Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]: Add Hackage frontend support #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' -%}
Copy link
Contributor

@reneeotten reneeotten Aug 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this become: {% if pkg.upt_pkg.frontend not in ('rubygems', '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