pkgsrc-Changes archive

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

CVS commit: pkgsrc/pkgtools/url2pkg



Module Name:    pkgsrc
Committed By:   rillig
Date:           Sun Feb  6 18:42:26 UTC 2022

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

Log Message:
url2pkg: allow url2pkg to be run from a category directory as well

Previously, it was necessary to create the package directory, change
into it and then run url2pkg from there.  Since the name of the package
directory usually corresponds to DISTNAME without the version number,
all necessary data is readily available, so automate this.

Update version to 21.4.2.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 pkgsrc/pkgtools/url2pkg/Makefile
cvs rdiff -u -r1.38 -r1.39 pkgsrc/pkgtools/url2pkg/files/url2pkg.py
cvs rdiff -u -r1.37 -r1.38 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/Makefile
diff -u pkgsrc/pkgtools/url2pkg/Makefile:1.123 pkgsrc/pkgtools/url2pkg/Makefile:1.124
--- pkgsrc/pkgtools/url2pkg/Makefile:1.123      Sat Jan  1 15:29:14 2022
+++ pkgsrc/pkgtools/url2pkg/Makefile    Sun Feb  6 18:42:26 2022
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.123 2022/01/01 15:29:14 rillig Exp $
+# $NetBSD: Makefile,v 1.124 2022/02/06 18:42:26 rillig Exp $
 
-PKGNAME=       url2pkg-21.4.1
+PKGNAME=       url2pkg-21.4.2
 CATEGORIES=    pkgtools
 
 MAINTAINER=    rillig%NetBSD.org@localhost

Index: pkgsrc/pkgtools/url2pkg/files/url2pkg.py
diff -u pkgsrc/pkgtools/url2pkg/files/url2pkg.py:1.38 pkgsrc/pkgtools/url2pkg/files/url2pkg.py:1.39
--- pkgsrc/pkgtools/url2pkg/files/url2pkg.py:1.38       Sun Feb  6 18:04:50 2022
+++ pkgsrc/pkgtools/url2pkg/files/url2pkg.py    Sun Feb  6 18:42:26 2022
@@ -1,5 +1,5 @@
 #! @PYTHONBIN@
-# $NetBSD: url2pkg.py,v 1.38 2022/02/06 18:04:50 rillig Exp $
+# $NetBSD: url2pkg.py,v 1.39 2022/02/06 18:42:26 rillig Exp $
 
 # Copyright (c) 2019 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -333,7 +333,7 @@ class PackageVars:
     distname: str
     pkgname: str
 
-    def __init__(self, url: str) -> None:
+    def __init__(self, url: str, pkgsrcdir: Path) -> None:
         self.url = url
         self.master_sites = ''
         self.distfile = ''
@@ -353,17 +353,17 @@ class PackageVars:
         self.adjust_site_SourceForge()
         self.adjust_site_GitHub_archive()
         self.adjust_site_GitHub_release()
-        self.foreach_site_from_sites_mk(self.adjust_site_from_sites_mk)
+        self.adjust_site_from_sites_mk(pkgsrcdir)
         self.adjust_site_PyPI()
         self.adjust_site_other()
         self.adjust_everything_else()
 
-    def foreach_site_from_sites_mk(self, action: Callable[[str, str], None]):
+    def adjust_site_from_sites_mk(self, pkgsrcdir: Path):
         if self.master_sites != '':
             return
 
         varname = ''
-        with open('../../mk/fetch/sites.mk') as sites_mk:
+        with open(pkgsrcdir / 'mk/fetch/sites.mk') as sites_mk:
             for line in sites_mk:
                 m = re.search(r'^(MASTER_SITE_.*)\+=', line)
                 if m:
@@ -372,9 +372,9 @@ class PackageVars:
 
                 m = re.search(r'^\t(.*?)(?:\s+\\)?$', line)
                 if m:
-                    action(varname, m[1])
+                    self.adjust_site_from_site_var(varname, m[1])
 
-    def adjust_site_from_sites_mk(self, varname: str, site_url: str):
+    def adjust_site_from_site_var(self, varname: str, site_url: str):
 
         url_noproto = re.sub(r'^\w+://', '', self.url)
         site_url_noproto = re.sub(r'^\w+://', '', site_url)
@@ -545,8 +545,8 @@ class Generator:
     """ Generates the initial package Makefile. """
     vars: PackageVars
 
-    def __init__(self, url: str) -> None:
-        self.vars = PackageVars(url)
+    def __init__(self, url: str):
+        self.vars = PackageVars(url, Path('../..'))
 
     def generate_Makefile(self) -> Lines:
         vars = self.vars
@@ -1214,10 +1214,6 @@ def usage() -> NoReturn:
 
 
 def main(argv: List[str], g: Globals):
-    if not os.path.isfile('../../mk/bsd.pkg.mk'):
-        sys.exit(f'{argv[0]}: must be run from a package directory '
-                 f'(.../pkgsrc/category/package)')
-
     try:
         opts, args = getopt.getopt(argv[1:], 'v', ['verbose'])
         for (opt, _) in opts:
@@ -1230,6 +1226,20 @@ def main(argv: List[str], g: Globals):
     if not re.fullmatch(r'\w+://[!-~]+?/[!-~]+', url):
         sys.exit(f'url2pkg: invalid URL: {url}')
 
+    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])
+
+    if not os.path.isfile('../../mk/bsd.pkg.mk'):
+        sys.exit(f'{argv[0]}: must be run from a package or category directory '
+                 f'(.../pkgsrc/category[/package])')
+
     initial_lines = Generator(url).generate_package(g)
     Adjuster(g, url, initial_lines).adjust()
 

Index: pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py
diff -u pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py:1.37 pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py:1.38
--- pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py:1.37  Sun Feb  6 18:00:08 2022
+++ pkgsrc/pkgtools/url2pkg/files/url2pkg_test.py       Sun Feb  6 18:42:26 2022
@@ -1,4 +1,4 @@
-# $NetBSD: url2pkg_test.py,v 1.37 2022/02/06 18:00:08 rillig Exp $
+# $NetBSD: url2pkg_test.py,v 1.38 2022/02/06 18:42:26 rillig Exp $
 
 import pytest
 from url2pkg import *
@@ -1565,10 +1565,10 @@ def test_Adjuster_adjust_lines_python_mo
 
 def test_main__wrong_dir(tmp_path):
     os.chdir(tmp_path)
-    error = r'url2pkg: must be run from a package directory'
+    error = r'url2pkg: must be run from a package or category directory'
 
     with pytest.raises(SystemExit, match=error):
-        main(['url2pkg'], g)
+        main(['url2pkg', 'https://example.org/distfile-1.0.tar.gz'], g)
 
 
 def test_main__unknown_option():



Home | Main Index | Thread Index | Old Index