From 2344cf32eb0e6e8aeb90d6adb0551faabaa30ea6 Mon Sep 17 00:00:00 2001 From: Vaughn Kottler Date: Sun, 1 Oct 2023 21:45:24 -0500 Subject: [PATCH 1/3] 2.7.1 - Allow pinning dependency versions --- .github/workflows/python-package.yml | 2 +- README.md | 4 ++-- local/variables/package.yaml | 2 +- pyproject.toml | 2 +- tests/data/valid/scenarios/native/yambs.yaml | 6 ++++- tests/data/valid/scenarios/native2/yambs.yaml | 5 +++- tests/github/test_github.py | 10 +++----- yambs/__init__.py | 4 ++-- yambs/config/common.py | 6 ++--- yambs/data/schemas/Dependency.yaml | 4 ++++ yambs/dependency/config.py | 1 + yambs/dependency/github.py | 12 +++++++--- yambs/dependency/handlers/yambs/github.py | 1 + yambs/github/__init__.py | 24 +++++++++++++++---- 14 files changed, 56 insertions(+), 27 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 8ff86fd..c2786c5 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -75,7 +75,7 @@ jobs: - run: | mk python-release owner=vkottler \ - repo=yambs version=2.7.0 + repo=yambs version=2.7.1 if: | matrix.python-version == '3.11' && matrix.system == 'ubuntu-latest' diff --git a/README.md b/README.md index 85638eb..af04a5d 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ ===================================== generator=datazen version=3.1.3 - hash=7c5f56f5b4ab2cfc9391105a8b2dc902 + hash=3cc4a55c298edb7c7fb7bb34bae1e691 ===================================== --> -# yambs ([2.7.0](https://pypi.org/project/yambs/)) +# yambs ([2.7.1](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) diff --git a/local/variables/package.yaml b/local/variables/package.yaml index f130e27..372e712 100644 --- a/local/variables/package.yaml +++ b/local/variables/package.yaml @@ -1,5 +1,5 @@ --- major: 2 minor: 7 -patch: 0 +patch: 1 entry: mbs diff --git a/pyproject.toml b/pyproject.toml index 9aa4d69..38a2bcb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__" [project] name = "yambs" -version = "2.7.0" +version = "2.7.1" description = "Yet another meta build-system." readme = "README.md" requires-python = ">=3.11" diff --git a/tests/data/valid/scenarios/native/yambs.yaml b/tests/data/valid/scenarios/native/yambs.yaml index e2ef3d5..180967a 100644 --- a/tests/data/valid/scenarios/native/yambs.yaml +++ b/tests/data/valid/scenarios/native/yambs.yaml @@ -28,5 +28,9 @@ variants: cflag_groups: [opt] dependencies: - - github: {repo: yambs-sample, owner: *self} + # This is temporary. + # - github: {repo: yambs-sample, owner: *self} + - github: {repo: yambs-sample2, owner: *self} + version: 0.1.3 + - directory: ../native2 diff --git a/tests/data/valid/scenarios/native2/yambs.yaml b/tests/data/valid/scenarios/native2/yambs.yaml index 5547889..050336b 100644 --- a/tests/data/valid/scenarios/native2/yambs.yaml +++ b/tests/data/valid/scenarios/native2/yambs.yaml @@ -3,5 +3,8 @@ project: name: yambs2 dependencies: - - github: {repo: yambs-sample, owner: vkottler} - github: {repo: yambs-sample2, owner: vkottler} + # This is temporary. + version: 0.1.3 + + - github: {repo: yambs-sample, owner: vkottler} diff --git a/tests/github/test_github.py b/tests/github/test_github.py index 093563b..89789a1 100644 --- a/tests/github/test_github.py +++ b/tests/github/test_github.py @@ -6,11 +6,7 @@ from tests.resources import OWNER, REPO # module under test -from yambs.github import ( - github_url, - latest_release_data, - latest_repo_release_api_url, -) +from yambs.github import github_url, release_data, repo_release_api_url def test_github_url_basic(): @@ -19,7 +15,7 @@ def test_github_url_basic(): assert github_url().geturl() == "https://github.com" assert github_url(netloc_prefix="api").geturl() == "https://api.github.com" assert ( - latest_repo_release_api_url(OWNER, REPO) + repo_release_api_url(OWNER, REPO) == "https://api.github.com/repos/vkottler/yambs-sample/releases/latest" ) - assert latest_release_data(OWNER, REPO) + assert release_data(OWNER, REPO) diff --git a/yambs/__init__.py b/yambs/__init__.py index c858c88..09a0bcc 100644 --- a/yambs/__init__.py +++ b/yambs/__init__.py @@ -1,7 +1,7 @@ # ===================================== # generator=datazen # version=3.1.3 -# hash=63f46d83195b193de72a6bbd1bcc7c47 +# hash=c74bb436d801c0a9f73549b83e4cd34b # ===================================== """ @@ -10,4 +10,4 @@ DESCRIPTION = "Yet another meta build-system." PKG_NAME = "yambs" -VERSION = "2.7.0" +VERSION = "2.7.1" diff --git a/yambs/config/common.py b/yambs/config/common.py index 82d3209..6a9c92f 100644 --- a/yambs/config/common.py +++ b/yambs/config/common.py @@ -101,11 +101,11 @@ def init(self, data: _JsonObject) -> None: """Initialize this instance.""" self.data = data - self.data["entry"] = f"{executable} -m {PKG_NAME}" - self.data["config_file"] = str(DEFAULT_CONFIG) - self.root = Path(data["root"]) # type: ignore + self.data["config_file"] = str(DEFAULT_CONFIG) + self.data["entry"] = f"{Path(executable).name} -m {PKG_NAME}" + self.src_root = self.directory("src_root") self.build_root = self.directory("build_root") self.ninja_root = self.directory("ninja_out") diff --git a/yambs/data/schemas/Dependency.yaml b/yambs/data/schemas/Dependency.yaml index f46228b..587385c 100644 --- a/yambs/data/schemas/Dependency.yaml +++ b/yambs/data/schemas/Dependency.yaml @@ -16,6 +16,10 @@ properties: type: string default: opt + version: + type: string + default: latest + github: $ref: package://yambs/schemas/Github.yaml diff --git a/yambs/dependency/config.py b/yambs/dependency/config.py index 6b0872a..87c1d2a 100644 --- a/yambs/dependency/config.py +++ b/yambs/dependency/config.py @@ -67,3 +67,4 @@ def init(self, data: _JsonObject) -> None: {}, # type: ignore ) self.target: str = data["target"] # type: ignore + self.version: str = data["version"] # type: ignore diff --git a/yambs/dependency/github.py b/yambs/dependency/github.py index a5e9974..cf1641d 100644 --- a/yambs/dependency/github.py +++ b/yambs/dependency/github.py @@ -15,7 +15,7 @@ from vcorelib.math import nano_str # internal -from yambs.github import ReleaseData, latest_release_data +from yambs.github import DEFAULT_RELEASE, ReleaseData, release_data AssetFilter = Callable[[dict[str, Any]], Optional[Path]] @@ -82,14 +82,20 @@ class GithubDependency(LoggerMixin): """A class for managing GitHub dependencies.""" def __init__( - self, owner: str, repo: str, *args, data: ReleaseData = None, **kwargs + self, + owner: str, + repo: str, + *args, + version: str = DEFAULT_RELEASE, + data: ReleaseData = None, + **kwargs, ) -> None: """Initialize this instance.""" super().__init__(logger_name=f"{owner}.{repo}") if data is None: - data = latest_release_data(owner, repo, *args, **kwargs) + data = release_data(owner, repo, *args, version=version, **kwargs) self.data = data self.logger.info( diff --git a/yambs/dependency/handlers/yambs/github.py b/yambs/dependency/handlers/yambs/github.py index d66f46e..d120e31 100644 --- a/yambs/dependency/handlers/yambs/github.py +++ b/yambs/dependency/handlers/yambs/github.py @@ -28,6 +28,7 @@ def github_release(dep: Dependency, data: DependencyData) -> GithubDependency: github = GithubDependency( dep.github["owner"], dep.github["repo"], + version=dep.version, data=data.get("latest_release"), ) diff --git a/yambs/github/__init__.py b/yambs/github/__init__.py index 34316ca..d9e89f3 100644 --- a/yambs/github/__init__.py +++ b/yambs/github/__init__.py @@ -49,10 +49,19 @@ def github_url( ) -def latest_repo_release_api_url(owner: str, repo: str) -> str: +DEFAULT_RELEASE = "latest" + + +def repo_release_api_url( + owner: str, repo: str, version: str = DEFAULT_RELEASE +) -> str: """Get a URL string for a repository's latest release.""" + + version_str = version if version == DEFAULT_RELEASE else f"tags/{version}" + return github_url( - netloc_prefix="api", path=f"repos/{owner}/{repo}/releases/latest" + netloc_prefix="api", + path=f"repos/{owner}/{repo}/releases/{version_str}", ).geturl() @@ -66,8 +75,13 @@ def check_api_token() -> None: ] = f"Bearer {os.environ['GITHUB_API_TOKEN']}" -def latest_release_data( - owner: str, repo: str, *args, timeout: float = None, **kwargs +def release_data( + owner: str, + repo: str, + *args, + version: str = DEFAULT_RELEASE, + timeout: float = None, + **kwargs, ) -> ReleaseData: """Get latest-release data.""" @@ -80,7 +94,7 @@ def latest_release_data( while not validate_release(result) and tries: result = requests.get( - latest_repo_release_api_url(owner, repo), + repo_release_api_url(owner, repo, version=version), *args, timeout=timeout, headers=GIHTUB_HEADERS, From 03704f7738a82392e51b90b5d970231e3902b15c Mon Sep 17 00:00:00 2001 From: Vaughn Kottler Date: Sun, 1 Oct 2023 21:51:03 -0500 Subject: [PATCH 2/3] Add package editable install --- .github/workflows/python-package.yml | 1 + local/configs/package.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index c2786c5..28f486d 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -42,6 +42,7 @@ jobs: - uses: seanmiddleditch/gha-setup-ninja@master with: {version: 1.11.1} if: matrix.system == 'ubuntu-latest' + - run: pip${{matrix.python-version}} install -e . - run: mk python-editable if: matrix.system == 'ubuntu-latest' # End project-specific setup. diff --git a/local/configs/package.yaml b/local/configs/package.yaml index 98cd95c..331de44 100644 --- a/local/configs/package.yaml +++ b/local/configs/package.yaml @@ -10,6 +10,7 @@ ci_local: - " with: {version: 1.11.1}" - " if: matrix.system == 'ubuntu-latest'" + - "- run: pip${{'{{matrix.python-version}}'}} install -e ." - "- run: mk python-editable" - " if: matrix.system == 'ubuntu-latest'" From 5ad4b109588a0b580488fb436edca0ca1224de7c Mon Sep 17 00:00:00 2001 From: Vaughn Kottler Date: Sun, 1 Oct 2023 22:01:48 -0500 Subject: [PATCH 3/3] Add some logging to help troubleshoot --- yambs/commands/common.py | 10 +++++++++- yambs/commands/compile_config.py | 5 +++++ yambs/commands/native.py | 9 ++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/yambs/commands/common.py b/yambs/commands/common.py index 089a02a..d1c218a 100644 --- a/yambs/commands/common.py +++ b/yambs/commands/common.py @@ -5,6 +5,7 @@ # built-in from argparse import ArgumentParser as _ArgumentParser from argparse import Namespace as _Namespace +from logging import getLogger from pathlib import Path as _Path from shutil import which from subprocess import run @@ -15,9 +16,16 @@ from rcmpy.watch.params import WatchParams # internal -from yambs import PKG_NAME +from yambs import DESCRIPTION, PKG_NAME, VERSION from yambs.config.common import DEFAULT_CONFIG +LOG = getLogger(__name__) + + +def log_package() -> None: + """Log some basic package information.""" + LOG.info("%s-%s - %s.", PKG_NAME, VERSION, DESCRIPTION) + def add_config_arg(parser: _ArgumentParser) -> None: """Add an argument for specifying a configuration file.""" diff --git a/yambs/commands/compile_config.py b/yambs/commands/compile_config.py index 49ca95b..42380ca 100644 --- a/yambs/commands/compile_config.py +++ b/yambs/commands/compile_config.py @@ -12,6 +12,9 @@ from vcorelib.dict import MergeStrategy, merge_dicts from vcorelib.io import ARBITER, DEFAULT_INCLUDES_KEY +# internal +from yambs.commands.common import log_package + def compile_config_cmd(args: _Namespace) -> int: """Execute the compile_config command.""" @@ -20,6 +23,8 @@ def compile_config_cmd(args: _Namespace) -> int: if args.update: merge_strat = MergeStrategy.UPDATE + log_package() + return ( 0 if ARBITER.encode( diff --git a/yambs/commands/native.py b/yambs/commands/native.py index a7b7af3..11d06a0 100644 --- a/yambs/commands/native.py +++ b/yambs/commands/native.py @@ -10,7 +10,12 @@ from vcorelib.args import CommandFunction as _CommandFunction # internal -from yambs.commands.common import add_common_args, handle_build, run_watch +from yambs.commands.common import ( + add_common_args, + handle_build, + log_package, + run_watch, +) from yambs.config.native import load_native from yambs.environment.native import NativeBuildEnvironment @@ -18,6 +23,8 @@ def native_cmd(args: _Namespace) -> int: """Execute the native command.""" + log_package() + config = load_native(path=args.config, root=args.dir) NativeBuildEnvironment(config).generate(sources_only=args.sources)