summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2022-02-06 18:42:26 +0000
committerrillig <rillig@pkgsrc.org>2022-02-06 18:42:26 +0000
commitd9c9ab73ba673778631dbfe530f86ce117124c01 (patch)
tree4fdcb9bc836874021ab8d99e6520a4a64b8be3e1 /pkgtools
parentba64732d3c46a70ff903f563b7edc0c419a41c23 (diff)
downloadpkgsrc-d9c9ab73ba673778631dbfe530f86ce117124c01.tar.gz
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.
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/url2pkg/Makefile4
-rw-r--r--pkgtools/url2pkg/files/url2pkg.py36
-rw-r--r--pkgtools/url2pkg/files/url2pkg_test.py6
3 files changed, 28 insertions, 18 deletions
diff --git a/pkgtools/url2pkg/Makefile b/pkgtools/url2pkg/Makefile
index 099e7238f14..61647f94460 100644
--- a/pkgtools/url2pkg/Makefile
+++ b/pkgtools/url2pkg/Makefile
@@ -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
diff --git a/pkgtools/url2pkg/files/url2pkg.py b/pkgtools/url2pkg/files/url2pkg.py
index 64fa6fcc0ea..b04f7437760 100644
--- a/pkgtools/url2pkg/files/url2pkg.py
+++ b/pkgtools/url2pkg/files/url2pkg.py
@@ -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()
diff --git a/pkgtools/url2pkg/files/url2pkg_test.py b/pkgtools/url2pkg/files/url2pkg_test.py
index 4d5bc7aad2e..ecadb0e1861 100644
--- a/pkgtools/url2pkg/files/url2pkg_test.py
+++ b/pkgtools/url2pkg/files/url2pkg_test.py
@@ -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_module__edited():
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():