Skip to content

Commit d8b18aa

Browse files
committed
Refactor entry points and move meson, ninja to dev-dependencies, improve build time
1 parent af26c8c commit d8b18aa

File tree

9 files changed

+146
-127
lines changed

9 files changed

+146
-127
lines changed

.github/funding.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/release.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,23 @@ jobs:
1919
uses: astral-sh/setup-uv@v3
2020

2121
- name: Get options
22-
run: uv run nvibrant-actions >> $GITHUB_ENV
22+
run: uv run nvibrant/version.py >> $GITHUB_ENV
2323
shell: bash
2424

2525
- name: Compile
26-
run: uv run nvibrant-build
26+
run: uv run nvibrant/build.py
2727

2828
- name: Build wheel
2929
run: uv build --wheel -o dist
3030

31-
- name: Publish to PyPI
32-
run: uv publish dist/*.whl
31+
# - name: Publish to PyPI
32+
# run: uv publish dist/*.whl
3333

3434
- name: Compress binaries
35-
run: tar --transform='s|^nvibrant/resources/|nvibrant/|' -czf dist/binaries.tar.gz nvibrant/resources/*.bin
35+
run: |
36+
tar --transform='s|^nvibrant/resources/|nvibrant/|' \
37+
-czf dist/nvibrant-${{env.GHA_VERSION}}-bin.tar.gz \
38+
nvibrant/resources/*.bin
3639
3740
- name: Upload artifacts
3841
uses: actions/upload-artifact@v4

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
build
2-
release
3-
nvibrant/resources
41
*.pyc
2+
3+
# Prebuilt binaries
4+
nvibrant/resources
5+
build

meson.build

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
project('nvibrant', 'cpp',
2-
version: run_command('nvibrant/version.py', check: true).stdout().strip()
3-
)
1+
project('nvibrant', 'cpp', version: '1.0.0')
42

53
# Paths to nvidia sources and headers
64
nvidia_src = 'open-gpu/src'

nvibrant/__init__.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,66 @@
1+
import os
2+
import shutil
3+
import subprocess
4+
import sys
5+
from pathlib import Path
6+
17
from nvibrant.version import __version__
8+
9+
# Common paths
10+
PACKAGE = Path(__file__).parent
11+
NVIBRANT = (PACKAGE.parent)
12+
RESOURCES = (PACKAGE/"resources")
13+
OPEN_GPU = (NVIBRANT/"open-gpu")
14+
RELEASE = (NVIBRANT/"release")
15+
BUILD = (NVIBRANT/"build")
16+
17+
# Common tools
18+
PYTHON = (sys.executable,)
19+
MESON = (*PYTHON, "-m", "mesonbuild.mesonmain")
20+
NINJA = (*PYTHON, "-m", "ninja")
21+
22+
# # Subprocess
23+
24+
def shell(*command: str, echo: bool=True, **kwargs) -> subprocess.CompletedProcess:
25+
command = tuple(map(str, command))
26+
if echo: print(f"• Call {command}")
27+
return subprocess.run(command, **kwargs)
28+
29+
# # Repositories
30+
31+
def get_tags(repo: Path) -> list[str]:
32+
return list(filter(None,
33+
subprocess.check_output(("git", "tag"), cwd=repo)
34+
.decode("utf-8").splitlines()))
35+
36+
def checkout_tag(repo: Path, tag: str) -> subprocess.CompletedProcess:
37+
return shell("git", "checkout", "-f", tag, cwd=repo)
38+
39+
# # Directories
40+
41+
def mkdir(path: Path) -> Path:
42+
Path(path).mkdir(parents=True, exist_ok=True)
43+
return Path(path)
44+
45+
def rmdir(path: Path) -> Path:
46+
shutil.rmtree(path, ignore_errors=True)
47+
return Path(path)
48+
49+
def rsdir(path: Path) -> Path:
50+
return mkdir(rmdir(path))
51+
52+
# # Drivers
53+
54+
def current_driver() -> str:
55+
56+
# Safety fallback or override with environment variable
57+
if (force := os.getenv("NVIDIA_DRIVER_VERSION")):
58+
return force
59+
60+
# Seems to be a common and stable path to get the information
61+
elif (file := Path("/sys/module/nvidia/version")).exists():
62+
return file.read_text("utf8").strip()
63+
64+
print("Could not find the current driver version at /sys/module/nvidia/version")
65+
print("• Run with 'NVIDIA_DRIVER_VERSION=x.y.z nvibrant' to set or force it")
66+
sys.exit(1)

nvibrant/__main__.py

Lines changed: 8 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,12 @@
1-
import os
2-
import shutil
3-
import subprocess
41
import sys
5-
from pathlib import Path
62

7-
from nvibrant import __version__
3+
from nvibrant import (
4+
RESOURCES,
5+
__version__,
6+
current_driver,
7+
shell,
8+
)
89

9-
# Common paths
10-
PACKAGE = Path(__file__).parent
11-
NVIBRANT = (PACKAGE.parent)
12-
RESOURCES = (PACKAGE/"resources")
13-
OPEN_GPU = (NVIBRANT/"open-gpu")
14-
RELEASE = (NVIBRANT/"release")
15-
BUILD = (NVIBRANT/"build")
16-
17-
# Common tools
18-
PYTHON = (sys.executable,)
19-
MESON = (*PYTHON, "-m", "mesonbuild.mesonmain")
20-
NINJA = (*PYTHON, "-m", "ninja")
21-
22-
# #
23-
24-
def shell(*command: str, echo: bool=True, **kwargs) -> subprocess.CompletedProcess:
25-
command = tuple(map(str, command))
26-
if echo: print(f"• Call {command}")
27-
return subprocess.run(command, **kwargs)
28-
29-
# # Repositories
30-
31-
def get_tags(repo: Path) -> list[str]:
32-
return list(filter(None,
33-
subprocess.check_output(("git", "tag"), cwd=repo)
34-
.decode("utf-8").splitlines()))
35-
36-
def checkout_tag(repo: Path, tag: str) -> subprocess.CompletedProcess:
37-
return shell("git", "checkout", "-f", tag, cwd=repo)
38-
39-
# # Directories
40-
41-
def mkdir(path: Path) -> Path:
42-
Path(path).mkdir(parents=True, exist_ok=True)
43-
return Path(path)
44-
45-
def rmdir(path: Path) -> Path:
46-
shutil.rmtree(path, ignore_errors=True)
47-
return Path(path)
48-
49-
def reset_dir(path: Path) -> Path:
50-
return mkdir(rmdir(path))
51-
52-
# # Drivers
53-
54-
def current_driver() -> str:
55-
56-
# Safety fallback or override with environment variable
57-
if (force := os.getenv("NVIDIA_DRIVER_VERSION")):
58-
return force
59-
60-
# Seems to be a common and stable path to get the information
61-
elif (file := Path("/sys/module/nvidia/version")).exists():
62-
return file.read_text("utf8").strip()
63-
64-
print("Could not find the current driver version at /sys/module/nvidia/version")
65-
print("• Run with 'NVIDIA_DRIVER_VERSION=x.y.z nvibrant' to set or force it")
66-
sys.exit(1)
67-
68-
# ------------------------------------------------------------------------------------------------ #
69-
# Entry points
70-
71-
def actions() -> None:
72-
for (key, value) in dict(
73-
GHA_VERSION=__version__,
74-
).items():
75-
print(f"{key}={value}")
76-
77-
def build() -> None:
78-
mkdir(RESOURCES)
79-
80-
# Internal structs may differ between versions,
81-
# compile the project for all nvidia drivers
82-
for driver in reversed(get_tags(OPEN_GPU)):
83-
checkout_tag(OPEN_GPU, driver)
84-
85-
# Configure and compile cpp project
86-
shell(*MESON, "setup", BUILD,
87-
"--buildtype", "release",
88-
"--reconfigure")
89-
shell(*NINJA, "-C", BUILD)
90-
91-
# Name the binary release
92-
nvibrant = (BUILD/"nvibrant")
93-
nvibrant.rename(RESOURCES / (
94-
f"nvibrant"
95-
f"-linux"
96-
f"-amd64"
97-
f"-{driver}"
98-
f"-v{__version__}"
99-
f".bin"
100-
))
101-
102-
# Revert back to the main branch
103-
checkout_tag(OPEN_GPU, "main")
10410

10511
def main() -> None:
10612
driver = current_driver()
@@ -127,5 +33,6 @@ def main() -> None:
12733
shell("chmod", "+x", nvibrant, echo=False)
12834
shell(nvibrant, *sys.argv[1:], echo=False)
12935

130-
if __name__ == "__main__":
36+
37+
if (__name__ == "__main__"):
13138
main()

nvibrant/build.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python3
2+
from nvibrant import (
3+
BUILD,
4+
MESON,
5+
NINJA,
6+
OPEN_GPU,
7+
RESOURCES,
8+
__version__,
9+
checkout_tag,
10+
get_tags,
11+
rsdir,
12+
shell,
13+
)
14+
15+
16+
def build() -> None:
17+
rsdir(RESOURCES)
18+
19+
# Configure the project once
20+
shell(*MESON, "setup", BUILD,
21+
"--buildtype", "release",
22+
"--reconfigure")
23+
24+
# Internal structs may differ between versions,
25+
# compile the project for all nvidia drivers
26+
for driver in reversed(get_tags(OPEN_GPU)):
27+
checkout_tag(OPEN_GPU, driver)
28+
shell(*NINJA, "-C", BUILD)
29+
30+
# Name the binary release
31+
nvibrant = (BUILD/"nvibrant")
32+
nvibrant.rename(RESOURCES / (
33+
f"nvibrant"
34+
f"-linux"
35+
f"-amd64"
36+
f"-{driver}"
37+
f"-v{__version__}"
38+
f".bin"
39+
))
40+
41+
# Revert back to the main branch
42+
checkout_tag(OPEN_GPU, "main")
43+
44+
if (__name__ == "__main__"):
45+
build()

nvibrant/version.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python3
2-
3-
__version__ = "1.0.3"
2+
__version__ = "1.0.4"
43

54
if (__name__ == "__main__"):
6-
print(__version__)
5+
print(f"GHA_VERSION={__version__}")

pyproject.toml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[tool.hatch.version]
2+
path = "nvibrant/version.py"
3+
14
[project]
25
name = "nvibrant"
36
description = "🟢 Nvidia Digital Vibrance on Wayland"
@@ -6,29 +9,28 @@ dynamic = ["version"]
69
readme = "readme.md"
710
license = "GPL-3.0"
811
requires-python = ">=3.9"
9-
dependencies = [
10-
"meson~=1.7.0",
11-
"ninja~=1.11.1.4",
12-
]
12+
dependencies = []
1313

1414
[project.scripts]
15-
nvibrant-actions = "nvibrant.__main__:actions"
16-
nvibrant-build = "nvibrant.__main__:build"
17-
nvibrant = "nvibrant.__main__:main"
15+
nvibrant = "nvibrant.__main__:main"
16+
17+
[tool.uv]
18+
dev-dependencies = [
19+
"meson~=1.7.2",
20+
"ninja~=1.11.1.4",
21+
]
1822

1923
[build-system]
2024
requires = ["hatchling"]
2125
build-backend = "hatchling.build"
2226

23-
[tool.hatch.version]
24-
path = "nvibrant/version.py"
25-
2627
[tool.hatch.build.targets.wheel]
2728
packages = ["nvibrant"]
2829
ignore-vcs = true
2930

3031
[tool.hatch.build.targets.sdist]
31-
exclude = ["*"]
32+
exclude = ["open-gpu"]
33+
ignore-vcs = true
3234

3335
[tool.hatch.build]
3436
exclude = ["main.cpp"]

0 commit comments

Comments
 (0)