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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jobs:
enable-cache: true
- name: Install the project
run: uv sync --locked --all-extras --dev
- name: Run Mypy
run: uv run mypy .
- name: Run Ty for typechecking
run: uv run ty check

format:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
- name: Install the project
run: uv sync --locked --all-extras --dev
- name: Run Unittests
run: uv run pytest tests/unit --cov=debmagic
run: uv run pytest --ignore tests/integration .

# TODO: integration tests currently don't work in the CI since they require running apt source on debian trixie -> CI runs on ubuntu
# integration-tests:
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ jobs:
enable-cache: true
- name: Build
run: uv build
- name: Publish
run: uv publish
- name: Publish debmagic-common
run: uv publish --package debmagic-common
- name: Publish debmagic (cli)
run: uv publish --package debmagic
9 changes: 8 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@ repos:
hooks:
- id: ruff-check
args: [ --fix ]
- id: ruff-format
- id: ruff-format
- repo: local
hooks:
- id: ty
name: ty check
entry: uv run ty check .
pass_filenames: false
language: python
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
},
"python.testing.pytestArgs": ["tests"],
"python.testing.pytestArgs": ["."],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
24 changes: 23 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,35 @@ Homepage: https://github.com/SFTtech/debmagic
Vcs-Git: https://github.com/SFTtech/debmagic.git
Vcs-Browser: https://github.com/SFTtech/debmagic

Package: debmagic
Package: python3-debmagic-common
Architecture: all
Depends:
python3-debian,
${misc:Depends},
${python3:Depends}
Multi-Arch: foreign
Description: Shared components for the debmagic debian buildtool suite
Collection of utilities and type definitions used in both the debmagic cli
buildtool as well as the debmagic python debian rules file library.

Package: debmagic-pkg
Architecture: all
Depends:
python3-debmagic-common,
python3-pydantic,
${misc:Depends},
${python3:Depends}
Multi-Arch: foreign
Description: Debian build instructions written in Python.
Explicit is better than implicit.

Package: debmagic
Architecture: all
Depends:
python3-debmagic-common,
python3-pydantic,
${misc:Depends},
${python3:Depends}
Multi-Arch: foreign
Description: Debian package building made easy.
Holistic cli for the whole debian package building workflow.
54 changes: 47 additions & 7 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,56 @@
import sys
from pathlib import Path

repo_root = Path(__file__).parent.parent / "src"
sys.path.append(str(repo_root))
packages_root = Path(__file__).parent.parent / "packages"
sys.path.extend(
[
str(packages_root / "debmagic-common" / "src"),
str(packages_root / "debmagic-pkg" / "src"),
]
)

from debmagic.v0 import package
from debmagic.v0 import dh as dh_mod
from debmagic.v0 import package, dh, Build

dh = dh_mod.Preset(dh_args=["--with", "python3", "--buildsystem=pybuild"])
dhp = dh.Preset(dh_args=["--with", "python3", "--buildsystem=pybuild"])

pkg = package(
preset=[dh],
preset=[dhp],
)

pkg.pack()
packages = {
"python3-debmagic-common": ("packages/debmagic-common", "debmagic-common"),
"debmagic": ("packages/debmagic", "debmagic"),
"debmagic-pkg": ("packages/debmagic-pkg", "debmagic-pkg"),
}

def dh_auto(build: Build, stage: str, use_destdir: bool = False):
for pkg_name, (path, python_pkg_name) in packages.items():
destdir = f" --destdir debian/{pkg_name} " if use_destdir else ""
build.cmd(f"{stage} -p {pkg_name} --sourcedirectory {path} --buildsystem=pybuild {destdir} -- --name {python_pkg_name}")

@dhp.override
def dh_auto_configure(build: Build):
dh_auto(build, "dh_auto_configure")


@dhp.override
def dh_auto_build(build: Build):
dh_auto(build, "dh_auto_build")


@dhp.override
def dh_auto_install(build: Build):
dh_auto(build, "dh_auto_install", use_destdir=True)


@dhp.override
def dh_auto_test(build: Build):
dh_auto(build, "dh_auto_test")


@dhp.override
def dh_auto_clean(build: Build):
dh_auto(build, "dh_auto_clean")


pkg.pack()
3 changes: 2 additions & 1 deletion docs/develop/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ This section covers documentation relevant to developing and maintaining the deb
codebase, and some guidelines for how you can contribute.

```{toctree}
```

```
16 changes: 16 additions & 0 deletions docs/develop/releasing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Making releases

First step is bumping the versions

```shell
uv version --package <package-name> --bump <major | minor | patch | beta | alpha> [--dry-run]
```

Currently we version all packages in tandem without separate release for our sub-packages

```shell
export BUMP=<bump-type>
uv version --package debmagic-common --bump $BUMP
uv version --package debmagic-pkg --bump $BUMP
uv version --package debmagic --bump $BUMP
```
3 changes: 2 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ usage/installation.md
:caption: Development

develop/index.md
develop/releasing.md
```

```{toctree}
:hidden:
:caption: 📖 Reference

develop/_changelog.md
```
```
20 changes: 20 additions & 0 deletions packages/debmagic-common/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[project]
name = "debmagic-common"
version = "0.0.1-alpha.1"
description = "utility library for common debmagic code"
license = "GPL-2.0-or-later"
# license-files = ["../../LICENSE"]
# readme = "../../README.md"
requires-python = ">=3.12"
classifiers = ["Programming Language :: Python :: 3"]
dependencies = ["python-debian>=1.0"]

[project.urls]
homepage = "https://github.com/SFTtech/debmagic"
source = "https://github.com/SFTtech/debmagic.git"
issues = "https://github.com/SFTtech/debmagic/issues"
releasenotes = "https://github.com/SFTtech/debmagic/-/blob/main/debian/changelog"

[build-system]
requires = ["setuptools>=77.0.0", "setuptools-scm"]
build-backend = "setuptools.build_meta"
File renamed without changes.
53 changes: 53 additions & 0 deletions packages/debmagic-common/src/debmagic/common/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from dataclasses import dataclass
from pathlib import Path
from typing import Self

from debian import deb822


@dataclass
class BinaryPackage:
name: str
ctrl: deb822.Packages
arch_dependent: bool


@dataclass
class SourcePackage:
name: str
binary_packages: list[BinaryPackage]

@classmethod
def from_control_file(cls, control_file_path: Path) -> Self:
src_pkg: Self | None = None
# which binary packages should be produced?
bin_pkgs: list[BinaryPackage] = []

for block in deb822.DebControl.iter_paragraphs(
control_file_path.open(),
use_apt_pkg=False, # don't depend on python3-apt for now.
):
if "Source" in block:
if src_pkg is not None:
raise RuntimeError("encountered multiple Source: blocks in control file")
src_name = block["Source"]
src_pkg = cls(
src_name,
bin_pkgs,
)

if "Package" in block:
bin_pkg = BinaryPackage(
name=block["Package"],
ctrl=block,
arch_dependent=block["Architecture"] != "all",
)
bin_pkgs.append(bin_pkg)

if src_pkg is None:
raise RuntimeError("no 'Source:' package defined in control file")

if not bin_pkgs:
raise RuntimeError("no binary 'Package:' defined in control file")

return src_pkg
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions packages/debmagic-common/tests/assets/pkg1_minimal_control_file
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Source: pkg1
Section: devel
Maintainer: Some Maintainers <[email protected]>
Uploaders:
Some Uploader <[email protected]>,
Build-Depends:
debhelper-compat (= 13),
Rules-Requires-Root: no
Standards-Version: 4.7.2

Package: pkg1
Architecture: all
Multi-Arch: foreign
Description: description-tldr
description-extended
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import subprocess
from unittest.mock import patch

from debmagic import _utils
from debmagic.common import utils


@patch("subprocess.run", autospec=True)
def test_util_exec_str(mock_run):
mock_run.return_value = subprocess.CompletedProcess(["some", "command"], returncode=0)
_utils.run_cmd("some command")
utils.run_cmd("some command")
mock_run.assert_called_once_with(["some", "command"], check=True)


@patch("subprocess.run", autospec=True)
def test_util_exec_list(mock_run):
mock_run.return_value = subprocess.CompletedProcess(["some", "command"], returncode=0)
_utils.run_cmd(["some", "command"])
utils.run_cmd(["some", "command"])
mock_run.assert_called_once_with(["some", "command"], check=True)


@patch("subprocess.run", autospec=True)
def test_util_exec_str_dryrun(mock_run):
_utils.run_cmd("some command", dry_run=True)
utils.run_cmd("some command", dry_run=True)
mock_run.assert_not_called()


@patch("subprocess.run", autospec=True)
def test_util_exec_str_shlex(mock_run):
mock_run.return_value = subprocess.CompletedProcess(["nothing"], returncode=0)
_utils.run_cmd("some command 'some arg'")
utils.run_cmd("some command 'some arg'")
mock_run.assert_called_once_with(["some", "command", "some arg"], check=True)


@patch("subprocess.run", autospec=True)
def test_util_exec_str_check(mock_run):
mock_run.return_value = subprocess.CompletedProcess(["something"], returncode=0)
_utils.run_cmd("something", check=True)
utils.run_cmd("something", check=True)
mock_run.assert_called_once_with(["something"], check=True)


@patch("subprocess.run", autospec=True)
def test_util_exec_str_nocheck(mock_run):
mock_run.return_value = subprocess.CompletedProcess(["something"], returncode=0)
_utils.run_cmd("something", check=False)
utils.run_cmd("something", check=False)
mock_run.assert_called_once_with(["something"], check=False)
18 changes: 18 additions & 0 deletions packages/debmagic-common/tests/test_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from pathlib import Path

import pytest
from debmagic.common.package import SourcePackage

asset_base = Path(__file__).parent / "assets"


@pytest.mark.parametrize(
"control_file_path, name",
[
(asset_base / "pkg1_minimal_control_file", "pkg1"),
],
)
def test_source_package_parsing(control_file_path: Path, name: str):
package = SourcePackage.from_control_file(control_file_path)

assert package.name == name
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest

from debmagic._package_version import PackageVersion
from debmagic.common.package_version import PackageVersion


@pytest.mark.parametrize(
Expand Down
20 changes: 20 additions & 0 deletions packages/debmagic-pkg/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[project]
name = "debmagic-pkg"
version = "0.0.1-alpha.1"
description = "packaging for debian using python"
license = "GPL-2.0-or-later"
# license-files = ["../../LICENSE"]
# readme = "../../README.md"
requires-python = ">=3.12"
classifiers = ["Programming Language :: Python :: 3"]
dependencies = ["debmagic-common"]

[project.urls]
homepage = "https://github.com/SFTtech/debmagic"
source = "https://github.com/SFTtech/debmagic.git"
issues = "https://github.com/SFTtech/debmagic/issues"
releasenotes = "https://github.com/SFTtech/debmagic/-/blob/main/debian/changelog"

[build-system]
requires = ["setuptools>=77.0.0", "setuptools-scm"]
build-backend = "setuptools.build_meta"
Loading