From 70aa6568c84a5f7c5f6249396d8ba3eebe3a79aa Mon Sep 17 00:00:00 2001 From: Korusuke Date: Thu, 27 Jun 2019 19:36:32 +0530 Subject: [PATCH] Template Cleanup --- upt_macports/templates/base.Portfile | 22 ++++++----- upt_macports/templates/perl.Portfile | 54 ++++++++++++++------------ upt_macports/templates/python.Portfile | 36 +++++++++-------- upt_macports/templates/ruby.Portfile | 37 +++++++++--------- upt_macports/upt_macports.py | 10 +++++ 5 files changed, 92 insertions(+), 67 deletions(-) diff --git a/upt_macports/templates/base.Portfile b/upt_macports/templates/base.Portfile index 4a881a3..86f7fb7 100644 --- a/upt_macports/templates/base.Portfile +++ b/upt_macports/templates/base.Portfile @@ -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 @@ -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 %} diff --git a/upt_macports/templates/perl.Portfile b/upt_macports/templates/perl.Portfile index 4dc3f3c..5a81dfa 100644 --- a/upt_macports/templates/perl.Portfile +++ b/upt_macports/templates/perl.Portfile @@ -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 -%} diff --git a/upt_macports/templates/python.Portfile b/upt_macports/templates/python.Portfile index 27fbfcd..dee3e27 100644 --- a/upt_macports/templates/python.Portfile +++ b/upt_macports/templates/python.Portfile @@ -16,11 +16,20 @@ 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 @@ -28,26 +37,21 @@ 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-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 -%} diff --git a/upt_macports/templates/ruby.Portfile b/upt_macports/templates/ruby.Portfile index 99a198e..37a9c5a 100644 --- a/upt_macports/templates/ruby.Portfile +++ b/upt_macports/templates/ruby.Portfile @@ -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 -%} diff --git a/upt_macports/upt_macports.py b/upt_macports/upt_macports.py index a605727..f15272c 100644 --- a/upt_macports/upt_macports.py +++ b/upt_macports/upt_macports.py @@ -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) @@ -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' @@ -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 @@ -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'