Skip to content

Commit

Permalink
Template Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Korusuke committed Jul 11, 2019
1 parent 9694e26 commit 70aa656
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 67 deletions.
22 changes: 13 additions & 9 deletions upt_macports/templates/base.Portfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{% macro depends(kind, deps) %}
{% if deps %}
depends_{{ kind }}-append \
{% for dep in deps | unique(attribute='name') | 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
Expand Down Expand Up @@ -28,17 +37,12 @@ description {{ pkg.upt_pkg.summary|trim|replace('\n',' \\\n')|indent(20,
long_description ${description}

{% block dist_info %}
{% 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' %}
{{ "use_%-15s yes"|format(pkg.archive_type) }}
{% endif %}

{% endblock %}
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 -%}

{% block dependencies %}
{% endblock %}
54 changes: 30 additions & 24 deletions upt_macports/templates/perl.Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,42 @@ perl5.setup {{ pkg._pkgname() }} {{ pkg.upt_pkg.version }}{{ pkg._cpandi
revision 0
{% endblock %}

{% block versions %}
{% block dist_info %}
{% if pkg.archive_type not in ['gz', 'unknown'] -%} {{ "use_%-15s yes"|format(pkg.archive_type) }}

{% endif -%}
{% endblock %}

{% block dependencies %}
{%- 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 %}

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 %}
if {${perl5.major} != ""} {
{% if pkg.upt_pkg.requirements.config and pkg.upt_pkg.requirements.build %}
{{ depends('build', pkg.upt_pkg.requirements.build + pkg.upt_pkg.requirements.config) -}}
{% elif pkg.upt_pkg.requirements.config %}
{{ depends('build', pkg.upt_pkg.requirements.config) -}}
{% elif pkg.upt_pkg.requirements.build %}
{{ depends('build', pkg.upt_pkg.requirements.build) -}}
{% endif %}

{% if pkg.upt_pkg.requirements.run %}
{%- if pkg.upt_pkg.requirements.run %}
{%- if pkg.upt_pkg.requirements.build or pkg.upt_pkg.requirements.config %}

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('lib', pkg.upt_pkg.requirements.run) -}}
{%- else %}
{{ depends('lib', pkg.upt_pkg.requirements.run) -}}
{%- endif -%}
{%- 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 %}

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

{% raw %}
}
{% endif %}
{% endblock %}
{%- endraw -%}
{%- endif -%}
{%- endblock -%}
36 changes: 20 additions & 16 deletions upt_macports/templates/python.Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,42 @@ revision 0
homepage {{ pkg.upt_pkg.homepage }}
master_sites pypi:[string index ${python.rootname} 0]/${python.rootname}
distname ${python.rootname}-${version}
{% if pkg.archive_type not in ['gz', 'unknown'] -%} {{ "use_%-15s yes"|format(pkg.archive_type) }}

{% else %}

{% endif %}
{% endblock %}

{% block versions %}

python.versions 37

{% endblock %}

{% block dependencies %}
if {${name} ne ${subport}} {
## setuptools is added by default as a build-dependency since this is often the case.
## However, if the package installs a "console_script" or uses "entry_points", setuptools
## should be added as a lib-dependency instead. Please verify from the setup.{py/cfg}
## 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-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('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:py${python.version}-{{i.name}}{% if not loop.last %} \
{% endif %}
{% endfor %}
{% endif %}

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

livecheck.type none
{{'

livecheck.type none'}}
}
{% endblock %}
{%- endblock -%}
37 changes: 19 additions & 18 deletions upt_macports/templates/ruby.Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@ ruby.setup {{ pkg._pkgname() }} {{ pkg.upt_pkg.version }} gem {} rubyge
revision 0
{% endblock %}

{% block versions %}
{% if pkg.upt_pkg.requirements.run or pkg.upt_pkg.requirements.test %}
{% block dependencies %}

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 %}
{{ depends('lib', pkg.upt_pkg.requirements.run) -}}

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

{% 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 %}

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

{%- if (pkg.upt_pkg.requirements.run or pkg.upt_pkg.requirements.test) %}


livecheck.type none
{% else -%}
livecheck.type none
{% endif %}
}
{% endif %}
{% endblock %}
{%- endblock -%}
10 changes: 10 additions & 0 deletions upt_macports/upt_macports.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def _render_makefile_template(self):
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 +150,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.lower()}'


class MacPortsNpmPackage(MacPortsPackage):
template = 'npm.Portfile'
Expand Down Expand Up @@ -180,6 +184,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 +229,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.lower()}'


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

0 comments on commit 70aa656

Please sign in to comment.