Skip to content

Commit d073ee3

Browse files
committed
Python packaging and wheel build
1 parent 7e3187f commit d073ee3

2 files changed

Lines changed: 130 additions & 0 deletions

File tree

.github/workflows/build-windows.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ jobs:
134134
- name: Build git-annex
135135
run: stack install --no-haddock --local-bin-path .
136136

137+
- name: Install uv
138+
uses: astral-sh/setup-uv@v5
139+
140+
- name: Build the Python wheel
141+
run: |
142+
uv build --wheel
143+
137144
- name: Build the installer
138145
run: |
139146
stack ghc --no-haddock --package nsis Build/NullSoftInstaller.hs
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
diff --git a/pyproject.toml b/pyproject.toml
2+
new file mode 100644
3+
index 0000000000..bc754a40a6
4+
--- /dev/null
5+
+++ b/pyproject.toml
6+
@@ -0,0 +1,74 @@
7+
+[project]
8+
+authors = [
9+
+ { name = "Joey Hess", email = "id@joeyh.name" },
10+
+]
11+
+classifiers = [
12+
+ "Development Status :: 6 - Mature",
13+
+ "Environment :: Console",
14+
+ "Intended Audience :: Developers",
15+
+ "Intended Audience :: End Users/Desktop",
16+
+ "Intended Audience :: Information Technology",
17+
+ "Intended Audience :: Science/Research",
18+
+ "License :: DFSG approved",
19+
+ "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
20+
+ "Natural Language :: English",
21+
+ "Operating System :: MacOS",
22+
+ "Operating System :: Microsoft :: Windows",
23+
+ "Operating System :: POSIX :: Linux",
24+
+ "Programming Language :: Haskell",
25+
+ "Topic :: Software Development :: Version Control",
26+
+ "Topic :: Software Development :: Version Control :: Git",
27+
+ "Topic :: System :: Archiving :: Backup",
28+
+ "Topic :: System :: Archiving :: Mirroring",
29+
+ "Topic :: System :: Archiving :: Packaging",
30+
+ "Topic :: Utilities",
31+
+]
32+
+description = "manage files with git, without checking their contents into git"
33+
+dynamic = ["version"]
34+
+keywords = [
35+
+ "git",
36+
+ "data logistics",
37+
+ "version control",
38+
+]
39+
+license = "AGPL-3.0-or-later"
40+
+maintainers = [
41+
+ { name = "Michael Hanke", email = "mih@ngln.eu" },
42+
+]
43+
+name = "git-annex"
44+
+readme = "python/README.md"
45+
+requires-python = ">=3.9"
46+
+
47+
+[project.urls]
48+
+Homepage = "https://git-annex.branchable.com/"
49+
+Documentation = "https://git-annex.branchable.com/git-annex"
50+
+Issues = "https://git-annex.branchable.com/bugs"
51+
+Source = "http://source.git-annex.branchable.com/?p=source.git"
52+
+Changelog = "http://source.git-annex.branchable.com/?p=source.git;a=blob;f=CHANGELOG;hb=HEAD"
53+
+
54+
+[build-system]
55+
+requires = [
56+
+ "hatchling",
57+
+ "hatch-vcs",
58+
+]
59+
+build-backend = "hatchling.build"
60+
+
61+
+[tool.hatch.version]
62+
+source = "vcs"
63+
+
64+
+[tool.hatch.build.targets.wheel.shared-data]
65+
+"git-annex" = "bin/git-annex"
66+
+
67+
+[tool.hatch.build.targets.wheel]
68+
+# we need to ship at least one file
69+
+only-include = ["python/py.typed"]
70+
+
71+
+[tool.hatch.build.targets.wheel.sources]
72+
+# give the 'only-include' files a base directory in the wheel
73+
+"python" = "git-annex"
74+
+
75+
+[tool.hatch.build.targets.wheel.hooks.custom]
76+
+# custom build hook to set some metadata
77+
+path = "python/build_hook_plugin.py"
78+
+# if set, actually perform a build. Otherwise assume that
79+
+# the built binary is in bin/
80+
+#build = "stack"
81+
diff --git a/python/README.md b/python/README.md
82+
new file mode 100644
83+
index 0000000000..e69de29bb2
84+
diff --git a/python/build_hook_plugin.py b/python/build_hook_plugin.py
85+
new file mode 100644
86+
index 0000000000..fb5107184d
87+
--- /dev/null
88+
+++ b/python/build_hook_plugin.py
89+
@@ -0,0 +1,31 @@
90+
+from pathlib import Path
91+
+from subprocess import run
92+
+from sysconfig import get_platform
93+
+from typing import Any
94+
+
95+
+from hatchling.builders.hooks.plugin.interface import BuildHookInterface
96+
+
97+
+
98+
+class SpecialBuildHook(BuildHookInterface):
99+
+
100+
+ def initialize(
101+
+ self,
102+
+ version: str, # noqa: ARG002
103+
+ build_data: dict[str, Any],
104+
+ ) -> None:
105+
+ # we have platform-specific builds
106+
+ build_data['pure_python'] = False
107+
+ # set a tag that says: any python3 for the build platform
108+
+ build_data['tag'] = \
109+
+ f'py3-none-{get_platform().replace("-", "_").replace(".", "_")}'
110+
+
111+
+ build_cmds = []
112+
+ if self.config.get('build') == 'stack':
113+
+ build_cmds = [
114+
+ ['stack', 'setup'],
115+
+ ['stack', 'build', '--no-haddock'],
116+
+ ['stack', 'install', '--no-haddock', '--local-bin-path', '.'],
117+
+ ]
118+
+
119+
+ for cmd in build_cmds:
120+
+ run(cmd, cwd=self.root, check=True)
121+
diff --git a/python/py.typed b/python/py.typed
122+
new file mode 100644
123+
index 0000000000..e69de29bb2

0 commit comments

Comments
 (0)