diff --git a/upt_macports/templates/hackage.Portfile b/upt_macports/templates/hackage.Portfile new file mode 100755 index 0000000..efe3a88 --- /dev/null +++ b/upt_macports/templates/hackage.Portfile @@ -0,0 +1,21 @@ +{% extends 'base.Portfile' %} + +{% block portgroup %} +PortGroup haskell 1.0 +{% endblock %} +{% block nameversion %} +haskell.setup {{ pkg._pkgname() }} {{ pkg.upt_pkg.version }} +revision 0 +{% endblock %} + +{% block dist_info %} +homepage {{ pkg.upt_pkg.homepage }} +{% endblock %} + +{% block versions %} +depends_lib-append \ + {% for i in pkg.upt_pkg.requirements.run|sort(attribute='name') %} + port:hs-{{i.name|lower}}{% if not loop.last %} \ + {% endif %} + {% endfor %} +{% endblock %} diff --git a/upt_macports/tests/test_hackage_package.py b/upt_macports/tests/test_hackage_package.py new file mode 100644 index 0000000..27e5ebb --- /dev/null +++ b/upt_macports/tests/test_hackage_package.py @@ -0,0 +1,29 @@ +import unittest + +import upt + +from upt_macports.upt_macports import MacPortsHackagePackage + + +class TestMacPortsHackagePackage(unittest.TestCase): + def setUp(self): + self.package = MacPortsHackagePackage() + self.package.upt_pkg = upt.Package('test-pkg', '13.37') + + def test_pkgname(self): + expected = ['Foo', 'foo', 'Foo-bar', 'foo-bar'] + names = ['Foo', 'foo', 'Foo-bar', 'foo-bar'] + for (name, expected_name) in zip(names, expected): + self.package.upt_pkg = upt.Package(name, '13.37') + self.assertEqual(self.package._pkgname(), expected_name) + + def test_folder_name(self): + expected = ['hs-foo', 'hs-foo', 'hs-foo-bar', 'hs-foo-bar'] + names = ['Foo', 'foo', 'Foo-bar', 'foo-bar'] + for (name, expected_name) in zip(names, expected): + self.assertEqual( + self.package._normalized_macports_folder(name), expected_name) + + +if __name__ == '__main__': + unittest.main() diff --git a/upt_macports/upt_macports.py b/upt_macports/upt_macports.py index a605727..b3e708e 100644 --- a/upt_macports/upt_macports.py +++ b/upt_macports/upt_macports.py @@ -28,6 +28,7 @@ def _create_output_directories(self, upt_pkg, output_dir): 'cpan': 'perl', 'pypi': 'python', 'rubygems': 'ruby', + 'hackage': 'devel', } try: port_category = upt2macports[self.upt_pkg.frontend] @@ -223,6 +224,24 @@ def _normalized_macports_folder(name): return f'rb-{name}' +class MacPortsHackagePackage(MacPortsPackage): + template = 'hackage.Portfile' + archive_format = upt.ArchiveType.SOURCE_TARGZ + + def _pkgname(self): + macports_name = self._normalized_macports_name(self.upt_pkg.name) + return macports_name + + @staticmethod + def _normalized_macports_name(name): + return name + + @staticmethod + def _normalized_macports_folder(name): + name = name.lower() + return f'hs-{name}' + + class MacPortsBackend(upt.Backend): name = 'macports' @@ -231,6 +250,7 @@ def create_package(self, upt_pkg, output=None): 'pypi': MacPortsPythonPackage, 'cpan': MacPortsPerlPackage, 'rubygems': MacPortsRubyPackage, + 'hackage': MacPortsHackagePackage, 'npm': MacPortsNpmPackage }