Skip to content

Commit

Permalink
Template Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Korusuke committed Jul 4, 2019
1 parent 9694e26 commit c5387e3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 77 deletions.
28 changes: 15 additions & 13 deletions upt_macports/templates/base.Portfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
{%- macro depends(kind, deps) -%}
{%- if deps %}
depends_{{ kind }}-append \
{%- for dep in deps|sort(attribute='name') %}
port:{{ dep|reqformat }} {%- if not loop.last %} \ {%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endmacro -%}
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem 1.0
{% block portgroup %}
{%- block portgroup %}
{% endblock %}

## Portfile generated/maintained using the Universal Packaging Tool (upt)
## Please check out the commented statements and refer to the guide for more information:
## https://guide.macports.org/#reference.keywords
{% block nameversion %}
{%- block nameversion %}
{% endblock %}

# categories-append
platforms darwin
{% if pkg.upt_pkg.frontend != 'rubygems' -%}
## uncomment the following line if no architecture-dependent files are installed, otherwise remove
# supported_archs noarch
{% endif %}
{% endif -%}
license {{ pkg.licenses }}
## If you would like to keep maintaining this port in the future as described in
## https://guide.macports.org/chunked/project.contributing.html then
Expand All @@ -26,19 +32,15 @@ maintainers nomaintainer

description {{ pkg.upt_pkg.summary|trim|replace('\n',' \\\n')|indent(20, false) }}
long_description ${description}

{% block dist_info %}
{% endblock -%}

{% if pkg.archive_type == 'unknown' and pkg.upt_pkg.frontend != 'rubygems' -%}
{% endblock %}
{%- if pkg.archive_type == 'unknown' and pkg.upt_pkg.frontend != 'rubygems' %}
# Detection of archive type failed
{% elif pkg.archive_type != 'gz' and pkg.upt_pkg.frontend != 'rubygems' %}
{%- elif pkg.archive_type != 'gz' and pkg.upt_pkg.frontend != 'rubygems' %}
{{ "use_%-15s yes"|format(pkg.archive_type) }}
{% endif %}

{%- endif -%}
checksums sha256 {{ pkg.upt_pkg.archives[0].sha256 }} \
rmd160 {{ pkg.upt_pkg.archives[0].rmd160 }} \
size {{ pkg.upt_pkg.archives[0].size }}

{% block versions %}
{% endblock %}
37 changes: 11 additions & 26 deletions upt_macports/templates/perl.Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,18 @@ revision 0
{% block versions %}
{%- if pkg.upt_pkg.requirements.run or pkg.upt_pkg.requirements.test or pkg.upt_pkg.requirements.build or pkg.upt_pkg.requirements.config %}
if {${perl5.major} != ""} {
{%- if pkg.upt_pkg.requirements.config or pkg.upt_pkg.requirements.build %}
{%- if pkg.upt_pkg.requirements.build or pkg.upt_pkg.requirements.config %}
{{ depends('build', pkg.upt_pkg.requirements.build + pkg.upt_pkg.requirements.config) }}
{%- endif -%}

depends_build-append \
{% for i in (pkg.upt_pkg.requirements.build + pkg.upt_pkg.requirements.config)|sort(attribute='name')|unique(attribute='name') %}
port:p${perl5.major}-{{i.name|replace('::','-')|lower}}{% if not loop.last %} \
{% endif %}
{% endfor %}
{% endif %}
{%- if pkg.upt_pkg.requirements.run %}
{{ depends('lib', pkg.upt_pkg.requirements.run) }}
{%- endif -%}

{% if pkg.upt_pkg.requirements.run %}

depends_lib-append \
{% for i in pkg.upt_pkg.requirements.run|sort(attribute='name') %}
port:p${perl5.major}-{{i.name|replace('::','-')|lower}}{% if not loop.last %} \
{% endif %}
{% endfor %}
{% endif %}

{% if pkg.upt_pkg.requirements.test %}

depends_test-append \
{% for i in pkg.upt_pkg.requirements.test|sort(attribute='name') %}
port:p${perl5.major}-{{i.name|replace('::','-')|lower}}{% if not loop.last %} \
{% endif %}
{% endfor %}
{% endif %}
{%- if pkg.upt_pkg.requirements.test %}
{{ depends('test', pkg.upt_pkg.requirements.test) }}
{%- endif %}

}
{% endif %}
{% endblock %}
{%- endif -%}
{% endblock %}
27 changes: 8 additions & 19 deletions upt_macports/templates/python.Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PortGroup python 1.0
{% endblock %}
{% block nameversion %}
name {{ pkg._pkgname() }}
{% if pkg._python_root_name() %}
{%- if pkg._python_root_name() %}
python.rootname {{ pkg._python_root_name() }}
{% endif %}
version {{ pkg.upt_pkg.version }}
Expand All @@ -28,26 +28,15 @@ if {${name} ne ${subport}} {
## file that setuptools is indeed used and that the dependency-type is correct.
depends_build-append \
port:py${python.version}-setuptools
{%- if pkg.upt_pkg.requirements.run|length > 0 %}

{%- if pkg.upt_pkg.requirements.run %}
{{ depends('lib', pkg.upt_pkg.requirements.run) }}
{%- endif -%}

depends_lib-append \
{% for i in pkg.upt_pkg.requirements.run|sort(attribute='name') %}
port:py${python.version}-{{i.name}}{% if not loop.last %} \
{% endif %}
{% endfor %}
{% endif %}
{%- if pkg.upt_pkg.requirements.test|length > 0 %}


depends_test-append \
{% for i in pkg.upt_pkg.requirements.test|sort(attribute='name') %}
port:py${python.version}-{{i.name}}{% if not loop.last %} \
{% endif %}
{% endfor %}
{% endif %}

{%- if pkg.upt_pkg.requirements.test %}
{{ depends('test', pkg.upt_pkg.requirements.test) }}
{%- endif %}

livecheck.type none
}
{% endblock %}
{%- endblock %}
24 changes: 8 additions & 16 deletions upt_macports/templates/ruby.Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,17 @@ revision 0
{% endblock %}

{% block versions %}
{% if pkg.upt_pkg.requirements.run or pkg.upt_pkg.requirements.test %}
{%- if pkg.upt_pkg.requirements.run or pkg.upt_pkg.requirements.test %}
if {${subport} ne ${name}} {
{% if pkg.upt_pkg.requirements.run %}
depends_lib-append \
{% for i in pkg.upt_pkg.requirements.run|sort(attribute='name') %}
port:rb${ruby.suffix}-{{i.name}}{% if not loop.last %} \
{% endif %}
{% endfor %}
{% endif %}
{%- if pkg.upt_pkg.requirements.run %}
{{ depends('lib', pkg.upt_pkg.requirements.run) }}
{%- endif -%}


{% if pkg.upt_pkg.requirements.test %}
depends_test-append \
{% for i in pkg.upt_pkg.requirements.test|sort(attribute='name') %}
port:rb${ruby.suffix}-{{i.name}}{% if not loop.last %} \
{% endif %}
{% endfor %}
{% endif %}
{%- if pkg.upt_pkg.requirements.test %}
{{ depends('test', pkg.upt_pkg.requirements.test) }}
{%- endif %}

}
{% endif %}
{%- endif -%}
{% endblock %}
13 changes: 10 additions & 3 deletions upt_macports/upt_macports.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ def _create_portfile(self):
def _render_makefile_template(self):
env = jinja2.Environment(
loader=jinja2.PackageLoader('upt_macports', 'templates'),
trim_blocks=True,
lstrip_blocks=True,
keep_trailing_newline=True,
)
env.filters['reqformat'] = self.jinja2_reqformat
template = env.get_template(self.template)
return template.render(pkg=self)

Expand Down Expand Up @@ -149,6 +147,9 @@ def _normalized_macports_folder(name):
name = name.lower()
return f'py-{name}'

def jinja2_reqformat(self, req):
return f'py${{python.version}}-{req.name}'


class MacPortsNpmPackage(MacPortsPackage):
template = 'npm.Portfile'
Expand Down Expand Up @@ -180,6 +181,9 @@ def _normalized_macports_folder(name):
name = name.lower().replace('::', '-')
return f'p5-{name}'

def jinja2_reqformat(self, req):
return f'p${{perl5.major}}-{self._normalized_macports_name(req.name).lower()}' # noqa

def _cpandir(self):
pkg = self.upt_pkg
# If no archives detected then we cannot locate dist file
Expand Down Expand Up @@ -222,6 +226,9 @@ def _normalized_macports_folder(name):
name = name.lower()
return f'rb-{name}'

def jinja2_reqformat(self, req):
return f'rb${{ruby.suffix}}-{req.name}'


class MacPortsBackend(upt.Backend):
name = 'macports'
Expand Down

0 comments on commit c5387e3

Please sign in to comment.