Skip to content

Commit

Permalink
Add Hackage frontend support
Browse files Browse the repository at this point in the history
  • Loading branch information
Korusuke committed Jul 2, 2019
1 parent 9694e26 commit d55b4bf
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
21 changes: 21 additions & 0 deletions upt_macports/templates/hackage.Portfile
Original file line number Diff line number Diff line change
@@ -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 %}
29 changes: 29 additions & 0 deletions upt_macports/tests/test_hackage_package.py
Original file line number Diff line number Diff line change
@@ -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()
20 changes: 20 additions & 0 deletions upt_macports/upt_macports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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'

Expand All @@ -231,6 +250,7 @@ def create_package(self, upt_pkg, output=None):
'pypi': MacPortsPythonPackage,
'cpan': MacPortsPerlPackage,
'rubygems': MacPortsRubyPackage,
'hackage': MacPortsHackagePackage,
'npm': MacPortsNpmPackage
}

Expand Down

0 comments on commit d55b4bf

Please sign in to comment.