Skip to content

Commit 6ed57f8

Browse files
committed
Use pyproject.toml and hatch backend with hook to allow uv sync/build
1 parent bc674f8 commit 6ed57f8

File tree

4 files changed

+63
-29
lines changed

4 files changed

+63
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,4 @@ bin
9090
x64
9191
/tmp/
9292
/TestResults
93+
uv.lock

buildUtil/build.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import zipfile
2-
import urllib.request
1+
from __future__ import annotations
2+
33
import shutil
4-
from pathlib import Path
4+
import urllib.request
55
import xml.etree.ElementTree as ET
6+
import zipfile
7+
from pathlib import Path
8+
from typing import Any
9+
10+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
11+
612

713
def download_nuget_package(
814
package_id: str,
@@ -67,8 +73,21 @@ def read_packages_config(filepath: str | Path) -> list[tuple[str, str]]:
6773
for pkg in root.findall("package")
6874
]
6975

70-
if __name__ == "__main__":
76+
def setup():
77+
"""Setup function to download NuGet packages and copy native libraries into bin folder.
78+
"""
7179
packages = read_packages_config("buildUtil/packages.config")
7280
for name, version in packages:
7381
download_nuget_package(name, version, output_dir="packages")
74-
copy_native_libs_to_bin("packages", "mikecore/bin")
82+
copy_native_libs_to_bin("packages", "mikecore/bin")
83+
84+
85+
class BuildHook(BuildHookInterface):
86+
"""Custom build hook to run setup during the build process."""
87+
88+
def initialize(self, version: str, build_data: dict[str : Any]) -> None:
89+
"""Initialize the build hook."""
90+
setup()
91+
92+
if __name__ == "__main__":
93+
setup()

pyproject.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[tool.hatch.build.hooks.custom]
6+
path = "buildUtil/build.py"
7+
8+
[tool.hatch.build.targets.sdist.force-include]
9+
"mikecore/bin" = "mikecore/bin"
10+
11+
[tool.hatch.build.targets.wheel.force-include]
12+
"mikecore/bin" = "mikecore/bin"
13+
14+
[project]
15+
name = "mikecore"
16+
version = "0.3.0a0"
17+
description = "MIKE Core contains core libraries, like DFS (Data File System), EUM and more."
18+
readme = "README.md"
19+
license = { file = "LICENSE.txt" }
20+
authors = [
21+
{ name = "DHI", email = "mike@dhigroup.com" }
22+
]
23+
requires-python = ">=3.5"
24+
dependencies = [
25+
"numpy"
26+
]
27+
classifiers = [
28+
"License :: OSI Approved :: BSD License",
29+
"Programming Language :: Python :: 3"
30+
]
31+
32+
[project.urls]
33+
Homepage = "https://github.com/DHI/mikecore-python"
34+
35+
[dependency-groups]
36+
dev = [
37+
"pytest>=6.1.2",
38+
]

setup.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)