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 Aug 15, 2019
1 parent f3c01cf commit 0e17c4c
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion upt_macports/templates/base.Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ PortSystem 1.0

# categories-append
platforms darwin
{% if pkg.upt_pkg.frontend != 'rubygems' -%}
{% if pkg.upt_pkg.frontend != 'rubygems' and pkg.upt_pkg.frontend != 'hackage' -%}
## uncomment the following line if no architecture-dependent files are installed, otherwise remove
# supported_archs noarch
{% endif %}
Expand Down
19 changes: 19 additions & 0 deletions upt_macports/templates/hackage.Portfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% 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', pkg.upt_pkg.requirements.run) }}
{% 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()
23 changes: 23 additions & 0 deletions upt_macports/upt_macports.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,28 @@ def jinja2_reqformat(self, req):
return f'rb${{ruby.suffix}}-{req.name.lower()}'


class MacPortsHackagePackage(MacPortsPackage):
template = 'hackage.Portfile'
archive_format = upt.ArchiveType.SOURCE_TARGZ
category = 'devel'

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}'

def jinja2_reqformat(self, req):
return f'hs-{req.name.lower()}'


class MacPortsBackend(upt.Backend):
def __init__(self):
self.logger = logging.getLogger('upt')
Expand All @@ -236,6 +258,7 @@ def __init__(self):
'pypi': MacPortsPythonPackage,
'cpan': MacPortsPerlPackage,
'rubygems': MacPortsRubyPackage,
'hackage': MacPortsHackagePackage,
'npm': MacPortsNpmPackage
}

Expand Down

0 comments on commit 0e17c4c

Please sign in to comment.