-
Notifications
You must be signed in to change notification settings - Fork 69
Modern Python packaging #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
909e16c
58bad8c
c6e3143
af80340
7d34abe
231abcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,39 +2,48 @@ | |
| # vi: ts=2 sw=2 et: | ||
| # SPDX-License-Identifier: LGPL-2.1-or-later | ||
| # | ||
| name: Build test | ||
| name: Build | ||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
| - feature/meson-build | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-20.04 | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ matrix.python }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: ["ubuntu-22.04", "ubuntu-24.04"] | ||
| python: [ | ||
| "3.7", | ||
| "3.8", | ||
| "3.9", | ||
| "3.10", | ||
| "3.11.0-rc.1", | ||
| "3.11", | ||
| "3.12", | ||
| "3.13", | ||
| ] | ||
| name: Python ${{ matrix.python }} | ||
| exclude: | ||
| - os: "ubuntu-22.04" | ||
| python: "3.13" | ||
| - os: "ubuntu-24.04" | ||
| python: "3.7" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3.7 is very old at this point. I guess we could drop that. But OTOH, the code will work fine with those old versions, so it should be fine to keep testing and supporting those old versions until there's some particular reason to raise the minimum. |
||
| runs-on: ${{ matrix.os }} | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ matrix.python }}-${{ matrix.os }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
| name: Python ${{ matrix.python }} on ${{ matrix.os }} | ||
| steps: | ||
| - name: Repository checkout | ||
| uses: actions/checkout@v2 | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Configure Python ${{ matrix.python }} | ||
| uses: actions/setup-python@v2 | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python }} | ||
| architecture: x64 | ||
|
|
@@ -43,14 +52,11 @@ jobs: | |
| run: | | ||
| sudo apt -y update | ||
| sudo apt -y install gcc libsystemd-dev | ||
| python -m pip install pytest sphinx | ||
| python -m pip install --break-system-packages pytest sphinx build | ||
|
|
||
| - name: Build (Python ${{ matrix.python }}) | ||
| run: | | ||
| set -x | ||
| make -j | ||
| make doc SPHINXOPTS="-W -v" | ||
|
|
||
| - name: Test (Python ${{ matrix.python }}) | ||
| run: | | ||
| make check | ||
| python -m build -Cbuild-dir=_build | ||
| python -m pip install . | ||
| cd _build && python -m sphinx -b html -W -v ../docs html | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ on: | |
| push: | ||
| branches: | ||
| - main | ||
| - feature/meson-build | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?? |
||
| pull_request: | ||
| branches: | ||
| - main | ||
|
|
@@ -18,7 +19,7 @@ permissions: | |
| jobs: | ||
| analyze: | ||
| name: Analyze | ||
| runs-on: ubuntu-22.04 | ||
| runs-on: ubuntu-24.04 | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ matrix.language }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
@@ -33,10 +34,10 @@ jobs: | |
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v3 | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Initialize CodeQL | ||
| uses: github/codeql-action/init@v2 | ||
| uses: github/codeql-action/init@v3 | ||
| with: | ||
| languages: ${{ matrix.language }} | ||
| queries: +security-extended,security-and-quality | ||
|
|
@@ -47,7 +48,7 @@ jobs: | |
| sudo apt -y install gcc libsystemd-dev | ||
|
|
||
| - name: Autobuild | ||
| uses: github/codeql-action/autobuild@v2 | ||
| uses: github/codeql-action/autobuild@v3 | ||
|
|
||
| - name: Perform CodeQL Analysis | ||
| uses: github/codeql-action/analyze@v2 | ||
| uses: github/codeql-action/analyze@v3 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,13 @@ | |
| # vi: ts=2 sw=2 et: | ||
| # SPDX-License-Identifier: LGPL-2.1-or-later | ||
| # | ||
| name: Install test | ||
| name: Install then test | ||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
| - feature/meson-build | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?? |
||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
@@ -24,16 +25,16 @@ jobs: | |
| container: [ | ||
| "archlinux:latest", | ||
| "debian:testing", | ||
| "quay.io/centos/centos:stream8", | ||
| "quay.io/centos/centos:stream10", | ||
| "quay.io/fedora/fedora:rawhide", | ||
| "ubuntu:focal", | ||
| "ubuntu:noble", | ||
| ] | ||
| container: | ||
| image: ${{ matrix.container }} | ||
| name: ${{ matrix.container }} | ||
| steps: | ||
| - name: Repository checkout | ||
| uses: actions/checkout@v2 | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install dependencies | ||
| shell: bash | ||
|
|
@@ -51,8 +52,7 @@ jobs: | |
|
|
||
| case "$DIST_ID" in | ||
| arch) | ||
| pacman --noconfirm -Sy "${DEPS_COMMON[@]}" systemd-libs | ||
| python3 -m ensurepip | ||
| pacman --noconfirm -Sy "${DEPS_COMMON[@]}" systemd-libs python-pip | ||
| ;; | ||
| centos|fedora) | ||
| dnf -y install "${DEPS_COMMON[@]}" systemd-devel python3-devel python3-pip | ||
|
|
@@ -66,13 +66,13 @@ jobs: | |
| exit 1 | ||
| esac | ||
|
|
||
| python3 -m pip install pytest sphinx | ||
| python3 -m pip install --break-system-packages pytest sphinx | ||
|
|
||
| - name: Build & install | ||
| - name: Install & test | ||
| shell: bash | ||
| run: | | ||
| set -x | ||
| python3 -m pip install -I -v . | ||
| python3 -m pip install -I -v --break-system-packages . | ||
| # Avoid importing the systemd module from the git repository | ||
| cd / | ||
| python3 -c 'from systemd import journal; print(journal.__version__)' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ __pycache__/ | |
| *.egg | ||
| *.egg-info | ||
| dist | ||
| _build | ||
| build | ||
|
Comment on lines
+10
to
11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see both |
||
| eggs | ||
| parts | ||
|
|
@@ -30,3 +31,6 @@ pip-log.txt | |
|
|
||
| #Mr Developer | ||
| .mr.developer.cfg | ||
|
|
||
| # Zed | ||
| .zed | ||
hongquan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,15 +5,7 @@ INCLUDE_DIR := $(shell pkg-config --variable=includedir libsystemd) | |
| INCLUDE_FLAGS := $(shell pkg-config --cflags libsystemd) | ||
| VERSION := $(shell $(PYTHON) setup.py --version) | ||
| TESTFLAGS = -v | ||
|
|
||
| define buildscript | ||
| import sys, sysconfig, setuptools | ||
| sversion = int(setuptools.__version__.split(".")[0]) | ||
| end = sys.implementation.cache_tag if sversion >= 61 else "{}.{}".format(*sys.version_info[:2]) | ||
| print("build/lib.{}-{}".format(sysconfig.get_platform(), end)) | ||
| endef | ||
|
|
||
| builddir := $(shell $(PYTHON) -c '$(buildscript)') | ||
| BUILD_DIR = _build | ||
|
||
|
|
||
| all: build | ||
|
|
||
|
|
@@ -32,38 +24,36 @@ update-constants: update-constants.py $(INCLUDE_DIR)/systemd/sd-messages.h | |
| mv docs/id128.rst{.tmp,} | ||
|
|
||
| build: | ||
| $(PYTHON) setup.py build_ext $(INCLUDE_FLAGS) | ||
| $(PYTHON) setup.py build | ||
| $(PYTHON) -m build -Cbuild-dir=$(BUILD_DIR) | ||
|
|
||
| install: | ||
| $(PYTHON) setup.py install --skip-build $(if $(DESTDIR),--root $(DESTDIR)) | ||
| $(PYTHON) -m pip install . | ||
|
|
||
| dist: | ||
| $(PYTHON) setup.py sdist | ||
| $(PYTHON) -m build --sdist | ||
|
|
||
| sign: dist/systemd-python-$(VERSION).tar.gz | ||
| gpg --detach-sign -a dist/systemd-python-$(VERSION).tar.gz | ||
|
|
||
| clean: | ||
| rm -rf build systemd/*.so systemd/*.py[co] *.py[co] systemd/__pycache__ | ||
| rm -rf _build systemd/*.so systemd/*.py[co] *.py[co] systemd/__pycache__ | ||
|
|
||
| distclean: clean | ||
| rm -rf dist MANIFEST | ||
|
|
||
| SPHINXOPTS += -D version=$(VERSION) -D release=$(VERSION) | ||
| sphinx-%: build | ||
| cd build && \ | ||
| PYTHONPATH=../$(builddir) $(PYTHON) -m sphinx -b $* $(SPHINXOPTS) ../docs $* | ||
| @echo Output has been generated in build/$* | ||
| sphinx-%: install | ||
|
||
| cd $(BUILD_DIR) && $(PYTHON) -m sphinx -b $* $(SPHINXOPTS) ../docs $* | ||
| @echo Output has been generated in $(BUILD_DIR)/$* | ||
|
|
||
| doc: sphinx-html | ||
|
|
||
| check: build | ||
| (cd $(builddir) && $(PYTHON) -m pytest . ../../docs $(TESTFLAGS)) | ||
| (cd $(BUILD_DIR) && $(PYTHON) -m pytest ../systemd/test ../docs $(TESTFLAGS)) | ||
|
|
||
| www_target = www.freedesktop.org:/srv/www.freedesktop.org/www/software/systemd/python-systemd | ||
| doc-sync: | ||
| rsync -rlv --delete --omit-dir-times build/html/ $(www_target)/ | ||
| rsync -rlv --delete --omit-dir-times $(BUILD_DIR)/html/ $(www_target)/ | ||
|
|
||
| upload: dist/systemd-python-$(VERSION).tar.gz dist/systemd-python-$(VERSION).tar.gz.asc | ||
| twine-3 upload $+ | ||
|
|
@@ -73,6 +63,6 @@ TAGS: $(shell git ls-files systemd/*.[ch]) | |
|
|
||
| shell: | ||
| # we change the directory because python insists on adding $CWD to path | ||
| (cd $(builddir) && $(PYTHON)) | ||
| (cd $(BUILD_DIR) && $(PYTHON)) | ||
|
||
|
|
||
| .PHONY: build install dist sign upload clean distclean TAGS doc doc-sync shell | ||
hongquan marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| project( | ||
| 'python-systemd', | ||
| 'c', | ||
| version: '236', | ||
| license: 'LGPL-2.1-or-later', | ||
| default_options: ['warning_level=2', 'c_std=c99'], | ||
| ) | ||
|
|
||
| # Dependencies | ||
| python = import('python').find_installation('python3', pure: false) | ||
| python_dep = python.dependency() | ||
|
|
||
| # Try to find libsystemd | ||
| foreach name : [ | ||
| 'libsystemd', | ||
| 'libsystemd-journal', | ||
| 'libsystemd-daemon', | ||
| 'libsystemd-id128', | ||
| 'libsystemd-login', | ||
|
||
| ] | ||
| libsystemd_dep = dependency(name, required: false) | ||
| if libsystemd_dep.found() | ||
| break | ||
| endif | ||
| endforeach | ||
|
|
||
| # Common compile arguments matching setup.py | ||
| common_c_args = [ | ||
| '-std=c99', | ||
|
||
| '-Werror=implicit-function-declaration', | ||
|
||
| '-DPACKAGE_VERSION="' + meson.project_version() + '"', | ||
| '-DLIBSYSTEMD_VERSION=' + libsystemd_dep.version(), | ||
| ] | ||
|
|
||
| # Build _journal extension module | ||
| python.extension_module( | ||
| '_journal', | ||
| ['systemd/_journal.c', 'systemd/pyutil.c'], | ||
| dependencies: [libsystemd_dep], | ||
| c_args: common_c_args, | ||
| install: true, | ||
| subdir: 'systemd', | ||
| ) | ||
|
|
||
| # Build _reader extension module | ||
| python.extension_module( | ||
| '_reader', | ||
| ['systemd/_reader.c', 'systemd/pyutil.c', 'systemd/strv.c'], | ||
| dependencies: [libsystemd_dep], | ||
| c_args: common_c_args, | ||
| install: true, | ||
| subdir: 'systemd', | ||
| ) | ||
|
|
||
| # Build _daemon extension module | ||
| python.extension_module( | ||
| '_daemon', | ||
| ['systemd/_daemon.c', 'systemd/pyutil.c', 'systemd/util.c'], | ||
| dependencies: [libsystemd_dep], | ||
| c_args: common_c_args, | ||
| install: true, | ||
| subdir: 'systemd', | ||
| ) | ||
|
|
||
| # Build id128 extension module | ||
| python.extension_module( | ||
| 'id128', | ||
| ['systemd/id128.c', 'systemd/pyutil.c'], | ||
| dependencies: [libsystemd_dep], | ||
| c_args: common_c_args, | ||
| install: true, | ||
| subdir: 'systemd', | ||
| ) | ||
|
|
||
| # Build login extension module | ||
| python.extension_module( | ||
| 'login', | ||
| ['systemd/login.c', 'systemd/pyutil.c', 'systemd/strv.c'], | ||
| dependencies: [libsystemd_dep], | ||
| c_args: common_c_args, | ||
| install: true, | ||
| subdir: 'systemd', | ||
| ) | ||
|
|
||
| # Install Python modules (matching py_modules in setup.py) | ||
|
||
| python.install_sources( | ||
| 'systemd/__init__.py', | ||
| 'systemd/journal.py', | ||
| 'systemd/daemon.py', | ||
| subdir: 'systemd', | ||
| ) | ||
|
|
||
| # Install test modules | ||
| python.install_sources( | ||
| 'systemd/test/test_daemon.py', | ||
| 'systemd/test/test_journal.py', | ||
| 'systemd/test/test_login.py', | ||
| 'systemd/test/test_id128.py', | ||
| subdir: 'systemd/test', | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just to make GH Action run on my fork repo when I push the code.
The line will be deleted when the PR is approved.