Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -49,6 +52,7 @@ jobs:

publish:
needs: build
if: ${{ !startsWith(github.event.release.tag_name, 'nuget-packages-') }}
runs-on: ubuntu-latest
environment: pypi
permissions:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
35 changes: 26 additions & 9 deletions buildUtil/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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")
]

Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion buildUtil/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<packages source="nuget.org">
<package id="DHI.DFS" version="23.0.3" />
<package id="DHI.PFS" version="23.0.3" />
<package id="DHI.EUM" version="23.0.3" />
Expand Down
Loading