Skip to content

Commit

Permalink
Merge pull request #73 from vkottler/dev/2.7.1
Browse files Browse the repository at this point in the history
2.7.1 - Allow pinning dependency versions
  • Loading branch information
vkottler authored Oct 2, 2023
2 parents a0a29fb + 5ad4b10 commit d87bff4
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -75,7 +76,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'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions local/configs/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'"

Expand Down
2 changes: 1 addition & 1 deletion local/variables/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
major: 2
minor: 7
patch: 0
patch: 1
entry: mbs
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion tests/data/valid/scenarios/native/yambs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion tests/data/valid/scenarios/native2/yambs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
10 changes: 3 additions & 7 deletions tests/github/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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)
4 changes: 2 additions & 2 deletions yambs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.1.3
# hash=63f46d83195b193de72a6bbd1bcc7c47
# hash=c74bb436d801c0a9f73549b83e4cd34b
# =====================================

"""
Expand All @@ -10,4 +10,4 @@

DESCRIPTION = "Yet another meta build-system."
PKG_NAME = "yambs"
VERSION = "2.7.0"
VERSION = "2.7.1"
10 changes: 9 additions & 1 deletion yambs/commands/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""
Expand Down
5 changes: 5 additions & 0 deletions yambs/commands/compile_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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(
Expand Down
9 changes: 8 additions & 1 deletion yambs/commands/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@
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


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)
Expand Down
6 changes: 3 additions & 3 deletions yambs/config/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions yambs/data/schemas/Dependency.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ properties:
type: string
default: opt

version:
type: string
default: latest

github:
$ref: package://yambs/schemas/Github.yaml

Expand Down
1 change: 1 addition & 0 deletions yambs/dependency/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 9 additions & 3 deletions yambs/dependency/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions yambs/dependency/handlers/yambs/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)

Expand Down
24 changes: 19 additions & 5 deletions yambs/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand All @@ -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."""

Expand All @@ -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,
Expand Down

0 comments on commit d87bff4

Please sign in to comment.