Skip to content

Commit 1653a82

Browse files
authored
Merge pull request #36 from psafont/dev/pau/package
Properly package the python script
2 parents 824aeee + bfc8483 commit 1653a82

20 files changed

+238
-138
lines changed

.github/workflows/main.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v2
14-
- name: Set up Python
15-
uses: actions/setup-python@v2
14+
- name: Install uv
15+
uses: astral-sh/setup-uv@v6
16+
with:
17+
version: "0.7.x"
18+
- name: Install dependencies
19+
run: uv sync --frozen
1620
- name: Test
21+
# use script to provide a tty (workaround of systematic "docker -t"?)
1722
shell: 'script -q -e -c "bash {0}"'
1823
run: |
19-
./test/test.sh
24+
uv run ./test/test.sh

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Distribution / packaging
2+
build/
3+
*.egg-info/
4+
__pycache__/

README.md

Lines changed: 60 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -22,90 +22,74 @@ If you have both installed, docker will be used by default. If you
2222
want to use a specific container runtime, set `XCPNG_OCI_RUNNER` to
2323
the docker-compatible command to use (typically `podman` or `docker`).
2424

25+
You'll need to install git-lfs to be able to download the source tarballs from
26+
git, otherwise when running xcp-ng-dev, it won't be able to extract the sources.
27+
28+
## Installation
29+
30+
This can be done with `uv`:
31+
```
32+
uv tool install --from git+https://github.com/xcp-ng/xcp-ng-build-env xcp-ng-dev
33+
```
34+
or `pipx:`
35+
```
36+
pipx install git+https://github.com/xcp-ng/xcp-ng-build-env
37+
```
38+
39+
After this, two new commands will be available: `xcp-ng-dev-env-create` and
40+
`xcp-ng-dev`.
41+
42+
If you want to develop the package and try the changes as you develop the
43+
package, clone the repository and install the `xcp-ng-dev` package:
44+
45+
```bash
46+
git clone github.com:xcp-ng/xcp-ng-build-env
47+
cd xcp-ng-build-env
48+
uv tool install --editable .
49+
```
50+
51+
If `uv` is not available you can use other tools to install python packages,
52+
like `pipx install --editable .`
53+
54+
If you do not want this behaviour, use: `uv tool install --from . xcp-ng-dev`
55+
or `pipx install .`
56+
57+
## Completion
58+
59+
### Bash
60+
61+
To install the completion, add `eval "$(register-python-argcomplete xcp-ng-dev)"` to `~/.bash_completion` and relaunch Bash.
62+
63+
### Zsh
64+
65+
To install the completion, add `eval "$(register-python-argcomplete xcp-ng-dev)"` to `~/.zshrc` and relaunch Zsh.
66+
67+
### Fish
68+
69+
To install the completion, run `register-python-argcomplete --shell fish xcp-ng-dev > ~/.config/fish/completions/xcp-ng-dev.fish` and relaunch fish.
70+
2571
## Building the container image(s)
2672

2773
You need one container image per target version of XCP-ng.
2874

29-
Clone this repository (outside any container), then use `build.sh` to
75+
Clone this repository (outside any container), then use `xcp-ng-dev-env-create` to
3076
generate the images for the wanted releases of XCP-ng.
3177
Note that Docker and Podman store container images separately.
3278

3379
```
34-
Usage: ./build.sh {version_of_XCP_ng}
80+
Usage: xcp-ng-dev-env-create {version_of_XCP_ng}
3581
... where {version_of_XCP_ng} is a 'x.y' version such as 8.0.
3682
```
3783

3884
## Using the container
3985

40-
Use the `run.py` script. It accepts a variety of parameters allowing for different uses:
86+
Use `xcp-ng-dev`. It accepts a variety of parameters allowing for different uses:
4187
* rebuild an existing source RPM (with automated installation of the build dependencies)
4288
* build a package from an already extracted source RPM (sources and spec file), or from a directory that follows the rpmbuild convention (a `SOURCES/` directory and a `SPECS/` directory). Most useful for building packages from XCP-ng's git repositories of RPM sources: https://github.com/xcp-ng-rpms.
4389
* or simply start a shell in the build environment, with the appropriate CentOS, EPEL and XCP-ng yum repositories enabled.
4490

45-
```sh
46-
usage: run.py [-h] [-b BRANCH] [-l BUILD_LOCAL] [--define DEFINE]
47-
[-r REBUILD_SRPM] [-o OUTPUT_DIR] [-n] [-p PACKAGE] [-s SRPM]
48-
[-d DIR] [-e ENV] [-v VOLUME] [--rm] [--syslog] [--name NAME]
49-
[-a ENABLEREPO] [--fail-on-error]
50-
...
51-
52-
positional arguments:
53-
command Command to run inside the prepared container
54-
55-
optional arguments:
56-
-h, --help show this help message and exit
57-
-b BRANCH, --branch BRANCH
58-
XCP-ng version: 7.6, 8.0, etc. If not set, will
59-
default to 8.0.
60-
-l BUILD_LOCAL, --build-local BUILD_LOCAL
61-
Install dependencies for the spec file(s) found in the
62-
SPECS/ subdirectory of the directory passed as
63-
parameter, then build the RPM(s). Built RPMs and SRPMs
64-
will be in RPMS/ and SRPMS/ subdirectories. Any
65-
preexisting BUILD, BUILDROOT, RPMS or SRPMS
66-
directories will be removed first. If --output-dir is
67-
set, the RPMS and SRPMS directories will be copied to
68-
it after the build.
69-
--define DEFINE Definitions to be passed to rpmbuild (if --build-local
70-
or --rebuild-srpm are passed too). Example: --define
71-
'xcp_ng_section extras', for building the 'extras'
72-
version of a package which exists in both 'base' and
73-
'extras' versions.
74-
-r REBUILD_SRPM, --rebuild-srpm REBUILD_SRPM
75-
Install dependencies for the SRPM passed as parameter,
76-
then build it. Requires the --output-dir parameter to
77-
be set.
78-
-o OUTPUT_DIR, --output-dir OUTPUT_DIR
79-
Output directory for --rebuild-srpm and --build-local.
80-
-n, --no-exit After executing either an automated build or a custom
81-
command passed as parameter, drop user into a shell
82-
-p PACKAGE, --package PACKAGE
83-
Packages for which dependencies will be installed
84-
-s SRPM, --srpm SRPM SRPMs for which dependencies will be installed
85-
-d DIR, --dir DIR Local dir to mount in the image. Will be mounted at
86-
/external/<dirname>
87-
-e ENV, --env ENV Environment variables passed directly to docker -e
88-
-v VOLUME, --volume VOLUME
89-
Volume mounts passed directly to docker -v
90-
--rm Destroy the container on exit
91-
--syslog Enable syslog to host by mounting in /dev/log
92-
--name NAME Assign a name to the container
93-
-a ENABLEREPO, --enablerepo ENABLEREPO
94-
additional repositories to enable before installing
95-
build dependencies. Same syntax as yum's --enablerepo
96-
parameter. Available additional repositories: xcp-ng-
97-
updates_testing, xcp-ng-extras, xcp-ng-extras_testing.
98-
--fail-on-error If container initialisation fails, exit rather than
99-
dropping the user into a command shell
100-
```
101-
10291
**Examples**
10392

104-
Rebuild an existing source RPM (with automated installation of the build dependencies)
105-
```sh
106-
./run.py -b 8.0 --rebuild-srpm /path/to/some-source-rpm.src.rpm --output-dir /path/to/output/directory --rm
107-
```
108-
10993
Build from git (and put the result into RPMS/ and SRPMS/ subdirectories)
11094
```sh
11195
# Find the relevant repository at https://github.com/xcp-ng-rpms/
@@ -116,7 +100,7 @@ git clone https://github.com/xcp-ng-rpms/xapi.git
116100
# ... Here add your patches ...
117101

118102
# Build.
119-
/path/to/run.py -b 8.0 --build-local xapi/ --rm
103+
xcp-ng-dev container build -b 8.2 --rm xapi/
120104
```
121105

122106
**Important switches**
@@ -135,15 +119,15 @@ fully automated.
135119
1. modify the specfile to add `-Squilt` to `%autosetup` or
136120
`%autopatch` in the `%prep` block; add `BuildRequires: quilt`
137121
2. let quilt apply them in a 8.3 buildenv (`quilt` in 8.3 is only in EPEL) and get you a shell:
138-
```
139-
xcpng/build-env/run.py --rm -b 8.3 -l . --rpmbuild-stage=p -n --enablerepo=epel
140-
```
122+
```sh
123+
xcp-ng-dev container build --rm -b 8.3 --rpmbuild-stage=p -n --enablerepo=epel .
124+
```
141125
3. ask `quilt` to refresh all your patches (alternatively just the one you want)
142-
```
143-
$ cd rpmbuild/BUILD/$dir
144-
$ quilt pop -a --refresh
145-
$ cp patches/* ../../SOURCES/
146-
```
126+
```sh
127+
cd rpmbuild/BUILD/$dir
128+
quilt pop -a --refresh
129+
cp patches/* ../../SOURCES/
130+
```
147131
4. carefully pick up the bits you need
148132

149133
Note: unfortunately `rpmbuild` (in 8.3 at least) does not add all
@@ -180,11 +164,11 @@ make
180164

181165
If you'd like to develop using the tools on your host and preserve the changes
182166
to source and revision control but still use the container for building, you
183-
can do using by mouning a volume in the container, using the `-v` option to mount
167+
can do so by mounting a volume in the container, using the `-v` option to mount
184168
a directory from your host to a suitable point inside the container. For
185169
example, if I clone some repos into a directory on my host, say `/work/code/`,
186170
then I can mount it inside the container as follows:
187171

188172
```sh
189-
./run.py -b 8.0 -v /work/code:/mnt/repos
173+
xcp-ng-dev container shell -b 8.2 -v /work/code:/mnt/repos
190174
```

pyproject.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[project]
2+
name = "xcp-ng-dev"
3+
description = "A tool to develop and build XCP-ng packages"
4+
readme = "README.md"
5+
requires-python = ">=3.11"
6+
license = "MIT"
7+
license-files = ["LICENSE"]
8+
dynamic = ["version"]
9+
dependencies = [
10+
"argcomplete",
11+
]
12+
13+
[project.scripts]
14+
xcp-ng-dev = "xcp_ng_dev.cli:main"
15+
xcp-ng-dev-env-create = "xcp_ng_dev.cli:build"
16+
17+
[project.urls]
18+
Homepage = "https://github.com/xcp-ng/xcp-ng-build-env/"
19+
20+
[build-system]
21+
requires = ["setuptools >= 77.0.3", "setuptools-scm>=8"]
22+
build-backend = "setuptools.build_meta"
23+
24+
[tool.setuptools_scm]

src/xcp_ng_dev/__init__.py

Whitespace-only changes.

build.sh renamed to src/xcp_ng_dev/build.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env bash
22
set -e
33

4+
SELF_NAME="xcp-ng-dev-env-create"
5+
46
die() {
57
echo >&2
68
echo >&2 "ERROR: $*"
@@ -15,7 +17,7 @@ die_usage() {
1517

1618
usage() {
1719
cat <<EOF
18-
Usage: $0 [--platform PF] <version>
20+
Usage: $SELF_NAME [--platform PF] <version>
1921
... where <version> is a 'x.y' version such as 8.0.
2022
2123
--platform override the default platform for the build container.
@@ -71,12 +73,12 @@ ALMA_VERSION=
7173
CENTOS_VERSION=
7274
case "$1" in
7375
9.*)
74-
DOCKERFILE=Dockerfile-9.x
76+
DOCKERFILE=files/Dockerfile-9.x
7577
ALMA_VERSION=10.0
7678
: ${PLATFORM:=linux/amd64/v2}
7779
;;
7880
8.*)
79-
DOCKERFILE=Dockerfile-8.x
81+
DOCKERFILE=files/Dockerfile-8.x
8082
: ${PLATFORM:=linux/amd64}
8183
;;
8284
7.*)

0 commit comments

Comments
 (0)