pkgsrc-Changes archive

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

CVS commit: pkgsrc/pkgtools/url2pkg/files



Module Name:    pkgsrc
Committed By:   rillig
Date:           Sun Feb  6 20:08:49 UTC 2022

Modified Files:
        pkgsrc/pkgtools/url2pkg/files: url2pkg.py url2pkg_test.py

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


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 pkgsrc/pkgtools/url2pkg/files/url2pkg.py
cvs rdiff -u -r1.38 -r1.39 pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/pkgtools/url2pkg/files/url2pkg.py
diff -u pkgsrc/pkgtools/url2pkg/files/url2pkg.py:1.39 pkgsrc/pkgtools/url2pkg/files/url2pkg.py:1.40
--- pkgsrc/pkgtools/url2pkg/files/url2pkg.py:1.39       Sun Feb  6 18:42:26 2022
+++ pkgsrc/pkgtools/url2pkg/files/url2pkg.py    Sun Feb  6 20:08:49 2022
@@ -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 @@ class PackageVars:
             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 @@ def main(argv: List[str], g: Globals):
 
     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 '

Index: pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py
diff -u pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py:1.38 pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py:1.39
--- pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py:1.38  Sun Feb  6 18:42:26 2022
+++ pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py       Sun Feb  6 20:08:49 2022
@@ -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_si
     ]
 
 
+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