pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/url2pkg/files url2pkg: for Python packages, p...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/498e0a7de1e9
branches:  trunk
changeset: 373125:498e0a7de1e9
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sun Feb 06 20:08:49 2022 +0000

description:
url2pkg: for Python packages, prefix directory name with 'py-'

diffstat:

 pkgtools/url2pkg/files/url2pkg.py      |  33 +++++++++++++++++++++++++--------
 pkgtools/url2pkg/files/url2pkg_test.py |  28 +++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 9 deletions(-)

diffs (97 lines):

diff -r bae8ab9599eb -r 498e0a7de1e9 pkgtools/url2pkg/files/url2pkg.py
--- a/pkgtools/url2pkg/files/url2pkg.py Sun Feb 06 19:04:41 2022 +0000
+++ b/pkgtools/url2pkg/files/url2pkg.py Sun Feb 06 20:08:49 2022 +0000
@@ -1,5 +1,5 @@
 #! @PYTHONBIN@
-# $NetBSD: url2pkg.py,v 1.39 2022/02/06 18:42:26 rillig Exp $
+# $NetBSD: url2pkg.py,v 1.40 2022/02/06 20:08:49 rillig Exp $
 
 # Copyright (c) 2019 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -540,6 +540,21 @@
             os.getenv('PKGMAINTAINER') or os.getenv('REPLYTO') \
             or 'INSERT_YOUR_MAIL_ADDRESS_HERE # or use pkgsrc-users%NetBSD.org@localhost'
 
+    def package_dir(self) -> str:
+        """Generate the suggested directory name for the package."""
+
+        if self.github_project != '':
+            return self.github_project
+
+        m = re.fullmatch(r'(.*?)-v?[0-9].*', self.distname)
+        if not m:
+            return ''
+        if 'MASTER_SITE_PYPI' in self.master_sites:
+            return f'py-{m[1]}'
+        if 'MASTER_SITE_CPAN' in self.master_sites:
+            return f'p5-{m[1]}'
+        return m[1]
+
 
 class Generator:
     """ Generates the initial package Makefile. """
@@ -1228,13 +1243,15 @@
 
     if os.path.isfile('../mk/bsd.pkg.mk'):
         vars = PackageVars(url, Path('..'))
-        m = re.fullmatch(r'(.*?)-[0-9].*', vars.distname)
-        if not m:
-            sys.exit(f'url2pkg: cannot determine package directory from distname \'{vars.distname}\'')
-        if Path(m[1]).exists():
-            sys.exit(f'url2pkg: package directory \'{m[1]}\' already exists')
-        os.mkdir(m[1])
-        os.chdir(m[1])
+        dir = vars.package_dir()
+
+        if dir == '':
+            sys.exit(f'url2pkg: cannot determine package directory '
+                     f'from distname \'{vars.distname}\'')
+        if Path(dir).exists():
+            sys.exit(f'url2pkg: package directory \'{dir}\' already exists')
+        os.mkdir(dir)
+        os.chdir(dir)
 
     if not os.path.isfile('../../mk/bsd.pkg.mk'):
         sys.exit(f'{argv[0]}: must be run from a package or category directory '
diff -r bae8ab9599eb -r 498e0a7de1e9 pkgtools/url2pkg/files/url2pkg_test.py
--- a/pkgtools/url2pkg/files/url2pkg_test.py    Sun Feb 06 19:04:41 2022 +0000
+++ b/pkgtools/url2pkg/files/url2pkg_test.py    Sun Feb 06 20:08:49 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: url2pkg_test.py,v 1.38 2022/02/06 18:42:26 rillig Exp $
+# $NetBSD: url2pkg_test.py,v 1.39 2022/02/06 20:08:49 rillig Exp $
 
 import pytest
 from url2pkg import *
@@ -577,6 +577,32 @@
     ]
 
 
+def test_PackageVars_adjust_site_from_sites_mk__CPAN():
+    url = 'https://cpan.metacpan.org/authors/id/M/MA/MAMAWE/Algorithm-CheckDigits-v1.3.6.tar.gz'
+    generator = Generator(url)
+
+    lines = generator.generate_Makefile()
+
+    assert detab(lines) == [
+        mkcvsid,
+        '',
+        'DISTNAME=       Algorithm-CheckDigits-v1.3.6',
+        'PKGNAME=        ${DISTNAME:S,-v,-,}',
+        'CATEGORIES=     pkgtools',
+        # TODO: Use MASTER_SITE_CPAN instead.
+        'MASTER_SITES=   https://cpan.metacpan.org/authors/id/M/MA/MAMAWE/',
+        '',
+        'MAINTAINER=     INSERT_YOUR_MAIL_ADDRESS_HERE # or use pkgsrc-users%NetBSD.org@localhost',
+        # TODO: Use https://metacpan.org/dist/Algorithm-CheckDigits instead.
+        'HOMEPAGE=       https://cpan.metacpan.org/authors/id/M/MA/MAMAWE/',
+        'COMMENT=        TODO: Short description of the package',
+        '#LICENSE=       # TODO: (see mk/license.mk)',
+        '',
+        '# url2pkg-marker (please do not remove this line.)',
+        '.include "../../mk/bsd.pkg.mk"',
+    ]
+
+
 def test_PackageVars_adjust_site_from_sites_mk__GNU():
     url = 'https://ftp.gnu.org/pub/gnu/cflow/cflow-1.6.tar.gz'
     generator = Generator(url)



Home | Main Index | Thread Index | Old Index