From 93b30aec92ff3e3760f23fa298b9c2139260b932 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 11 Nov 2026 15:18:48 +0100 Subject: [PATCH] Pick the NuGet feed with a source setting and skip mirror releases A required source attribute in buildUtil/packages.config chooses between nuget.org and a GitHub release mirror, so switching feeds is a one-word change. It stays nuget.org, so the wheel is unchanged. The Build package workflow skips releases tagged nuget-packages-*, which will only host the mirror. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/build_package.yml | 4 ++++ CHANGELOG.md | 4 ++++ buildUtil/build.py | 35 +++++++++++++++++++++-------- buildUtil/packages.config | 2 +- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build_package.yml b/.github/workflows/build_package.yml index 4edce87..d5f3956 100644 --- a/.github/workflows/build_package.yml +++ b/.github/workflows/build_package.yml @@ -12,6 +12,9 @@ jobs: build: # Builds a single py3-none-any wheel bundling both Windows and Linux binaries. # Must run on Linux: the build hook only patches the .so files there. + # nuget-packages-* releases only host the NuGet mirror. tag_name is null on + # workflow_dispatch, which startsWith treats as ''. + if: ${{ !startsWith(github.event.release.tag_name, 'nuget-packages-') }} runs-on: ubuntu-latest steps: @@ -49,6 +52,7 @@ jobs: publish: needs: build + if: ${{ !startsWith(github.event.release.tag_name, 'nuget-packages-') }} runs-on: ubuntu-latest environment: pypi permissions: diff --git a/CHANGELOG.md b/CHANGELOG.md index 130cd4e..c544370 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `MIKECORE_PYTHON_BIN`: set it to a MIKE installation's `bin` folder to have mikecore use that installation's native libraries instead of its bundled ones, at your own risk (see README). +- A required `source` attribute in `buildUtil/packages.config` picks where the + build downloads the native NuGet packages from: `nuget.org`, or + `github-mirror` for a mirror on this repository's releases. It's + `nuget.org` for now, so the wheel is unchanged. ### Changed diff --git a/buildUtil/build.py b/buildUtil/build.py index af19814..bca2665 100644 --- a/buildUtil/build.py +++ b/buildUtil/build.py @@ -13,15 +13,25 @@ from hatchling.builders.hooks.plugin.interface import BuildHookInterface +# Picked by the source attribute in packages.config. +FEEDS = { + "nuget.org": "https://api.nuget.org/v3-flatcontainer/{id_lower}/{version_lower}/{id_lower}.{version_lower}.nupkg", + "github-mirror": "https://github.com/DHI/mikecore-python/releases/download/nuget-packages-2026/{id}.{version}.nupkg", +} + + def download_nuget_package( - package_id: str, version: str, output_dir: str | Path + package_id: str, version: str, output_dir: str | Path, feed: str ) -> None: """ Download a NuGet package (.nupkg) to output_dir. """ - package_id_lower: str = package_id.lower() - version_lower: str = version.lower() - url: str = f"https://api.nuget.org/v3-flatcontainer/{package_id_lower}/{version_lower}/{package_id_lower}.{version_lower}.nupkg" + url: str = FEEDS[feed].format( + id=package_id, + version=version, + id_lower=package_id.lower(), + version_lower=version.lower(), + ) output_dir = Path(output_dir) nupkg_path: Path = output_dir / f"{package_id}.{version}.nupkg" extract_path: Path = output_dir / f"{package_id}" @@ -67,13 +77,19 @@ def copy_native_libs_to_bin(packages_dir: str | Path, bin_dir: str | Path) -> No shutil.copy2(lib, dest) -def read_packages_config(filepath: str | Path) -> list[tuple[str, str]]: +def read_packages_config(filepath: str | Path) -> tuple[str, list[tuple[str, str]]]: """ - Reads NuGet packages.config and returns a list of (id, version) tuples. + Reads NuGet packages.config and returns its feed and a list of + (id, version) tuples. """ tree = ET.parse(filepath) root = tree.getroot() - return [ + feed = root.get("source") + if feed not in FEEDS: + raise RuntimeError( + f"{filepath}: source must be one of {', '.join(FEEDS)}, got {feed!r}" + ) + return feed, [ (pkg.attrib["id"], pkg.attrib["version"]) for pkg in root.findall("package") ] @@ -154,9 +170,10 @@ def print_elf(lib: Path, flag: str) -> list[str]: def setup(): """Setup function to download NuGet packages and copy native libraries into bin folder.""" - packages = read_packages_config("buildUtil/packages.config") + feed, packages = read_packages_config("buildUtil/packages.config") + print(f"Downloading NuGet packages from {feed}") for name, version in packages: - download_nuget_package(name, version, output_dir="packages") + download_nuget_package(name, version, output_dir="packages", feed=feed) copy_native_libs_to_bin("packages", "mikecore/bin") check_signed("mikecore/bin/windows") diff --git a/buildUtil/packages.config b/buildUtil/packages.config index c2a57c0..7ed144d 100644 --- a/buildUtil/packages.config +++ b/buildUtil/packages.config @@ -1,5 +1,5 @@ - +