From 7c68bef96fcd2b4de873dc61a3cf56b050073d79 Mon Sep 17 00:00:00 2001 From: Vaughn Kottler Date: Sun, 19 May 2024 20:53:51 -0700 Subject: [PATCH] 3.0.3 - Fix 'download' command --- .github/workflows/python-package.yml | 2 +- README.md | 6 +++--- local/variables/package.yaml | 2 +- pyproject.toml | 2 +- tests/commands/test_download.py | 15 ++++++++++++++- yambs/__init__.py | 4 ++-- yambs/commands/download.py | 10 +++++++--- yambs/dependency/github.py | 12 ++++++++---- 8 files changed, 37 insertions(+), 16 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index da5bdee..9e7417b 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -90,7 +90,7 @@ jobs: - run: | mk python-release owner=vkottler \ - repo=yambs version=3.0.2 + repo=yambs version=3.0.3 if: | matrix.python-version == '3.11' && matrix.system == 'ubuntu-latest' diff --git a/README.md b/README.md index 24775a3..5859b58 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ ===================================== generator=datazen version=3.1.4 - hash=72271a00d30bf23159c35289b5ff7a00 + hash=934a1cb8be74864c521e3c3d3875e01d ===================================== --> -# yambs ([3.0.2](https://pypi.org/project/yambs/)) +# yambs ([3.0.3](https://pypi.org/project/yambs/)) [![python](https://img.shields.io/pypi/pyversions/yambs.svg)](https://pypi.org/project/yambs/) ![Build Status](https://github.com/vkottler/yambs/workflows/Python%20Package/badge.svg) @@ -216,7 +216,7 @@ options: repository owner (default: 'vkottler') -r REPO, --repo REPO repository name (default: 'toolchains') -O OUTPUT, --output OUTPUT - output directory (default: 'toolchains') + output directory (default: '.') -p PATTERN, --pattern PATTERN a pattern to use to select project specifications filtered by name diff --git a/local/variables/package.yaml b/local/variables/package.yaml index 9cb4b38..c59db6d 100644 --- a/local/variables/package.yaml +++ b/local/variables/package.yaml @@ -1,5 +1,5 @@ --- major: 3 minor: 0 -patch: 2 +patch: 3 entry: mbs diff --git a/pyproject.toml b/pyproject.toml index 71e5fb7..ad64427 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__" [project] name = "yambs" -version = "3.0.2" +version = "3.0.3" description = "Yet another meta build-system." readme = "README.md" requires-python = ">=3.11" diff --git a/tests/commands/test_download.py b/tests/commands/test_download.py index c587b82..d3bf7da 100644 --- a/tests/commands/test_download.py +++ b/tests/commands/test_download.py @@ -3,6 +3,7 @@ """ # built-in +import platform from tempfile import TemporaryDirectory # module under test @@ -14,4 +15,16 @@ def test_download_basic(): """Test the 'download' command.""" with TemporaryDirectory() as tmpdir: - assert yambs_main([PKG_NAME, "-C", str(tmpdir), "download"]) == 0 + assert ( + yambs_main( + [ + PKG_NAME, + "-C", + str(tmpdir), + "download", + "-p", + platform.machine(), + ] + ) + == 0 + ) diff --git a/yambs/__init__.py b/yambs/__init__.py index 4d9e272..d231b30 100644 --- a/yambs/__init__.py +++ b/yambs/__init__.py @@ -1,7 +1,7 @@ # ===================================== # generator=datazen # version=3.1.4 -# hash=d1fc72b413b5923198b146f188381f34 +# hash=1229207e5be7a4167912254256ebd6a2 # ===================================== """ @@ -10,4 +10,4 @@ DESCRIPTION = "Yet another meta build-system." PKG_NAME = "yambs" -VERSION = "3.0.2" +VERSION = "3.0.3" diff --git a/yambs/commands/download.py b/yambs/commands/download.py index be0d951..51f9c26 100644 --- a/yambs/commands/download.py +++ b/yambs/commands/download.py @@ -13,6 +13,8 @@ # internal from yambs.dependency.github import GithubDependency, default_filt +DEFAULT_PATTERN = ".*" + def download_cmd(args: _Namespace) -> int: """Execute the download command.""" @@ -20,8 +22,10 @@ def download_cmd(args: _Namespace) -> int: dep = GithubDependency(args.owner, args.repo) # Download and extract things. + args.output.mkdir(parents=True, exist_ok=True) dep.download_release_assets( - default_filt(args.output, pattern=args.pattern) + default_filt(args.output.joinpath(args.repo), pattern=args.pattern), + strict=args.pattern == DEFAULT_PATTERN, ) return 0 @@ -46,13 +50,13 @@ def add_download_cmd(parser: _ArgumentParser) -> _CommandFunction: "-O", "--output", type=Path, - default=Path("toolchains"), + default=Path(), help="output directory (default: '%(default)s')", ) parser.add_argument( "-p", "--pattern", - default=".*", + default=DEFAULT_PATTERN, help=( "a pattern to use to select project " "specifications filtered by name" diff --git a/yambs/dependency/github.py b/yambs/dependency/github.py index cf1641d..5c73c56 100644 --- a/yambs/dependency/github.py +++ b/yambs/dependency/github.py @@ -54,7 +54,9 @@ def filt(asset: dict[str, Any]) -> Optional[Path]: return filt -def ensure_extracted(path: Path, logger: LoggerType = None) -> None: +def ensure_extracted( + path: Path, strict: bool = True, logger: LoggerType = None +) -> None: """Ensure that all archive files in a directory are extracted.""" for item in path.iterdir(): @@ -75,7 +77,7 @@ def ensure_extracted(path: Path, logger: LoggerType = None) -> None: nano_str(result[1], is_time=True), ) - assert dest.is_dir(), dest + assert not strict or dest.is_dir(), dest class GithubDependency(LoggerMixin): @@ -111,7 +113,7 @@ def __init__( } def download_release_assets( - self, filt: AssetFilter, extract: bool = True + self, filt: AssetFilter, extract: bool = True, strict: bool = True ) -> None: """Ensure release assets are downloaded.""" @@ -121,4 +123,6 @@ def download_release_assets( download_file_if_missing(asset["browser_download_url"], dest) if extract: - ensure_extracted(dest.parent, logger=self.logger) + ensure_extracted( + dest.parent, strict=strict, logger=self.logger + )