Skip to content
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

Use pyproject toml and enable workflow for publishing on PyPI #480

Merged
merged 4 commits into from
Feb 7, 2025
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
118 changes: 118 additions & 0 deletions .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI

on: push

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/podman
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/podman

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export PODMAN_VERSION ?= "5.3.0"
.PHONY: podman
podman:
rm dist/* || :
$(PYTHON) -m pip install --user -r requirements.txt
$(PYTHON) -m pip install -q build
PODMAN_VERSION=$(PODMAN_VERSION) \
$(PYTHON) setup.py sdist bdist bdist_wheel
$(PYTHON) -m build

.PHONY: lint
lint: tox
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ pip install podman

## Dependencies

* For runtime dependencies, see [requirements.txt](https://github.com/containers/podman-py/blob/main/requirements.txt).
* For testing and development dependencies, see [test-requirements.txt](https://github.com/containers/podman-py/blob/main/test-requirements.txt).
* For runtime dependencies, see \[dependencies\] in [pyproject.toml](https://github.com/containers/podman-py/blob/main/pyproject.toml)
* For testing and development dependencies, see \[project.optional.dependencies\] in [pyproject.toml](https://github.com/containers/podman-py/blob/main/pyproject.toml)
* The package is split in \[progress\_bar\], \[docs\], and \[test\]

## Example usage

Expand Down
2 changes: 1 addition & 1 deletion plans/main.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ prepare:
- name: pip dependencies
how: shell
script:
- pip3 install -r test-requirements.txt
- pip3 install .[test]

- name: ssh configuration
how: shell
Expand Down
2 changes: 1 addition & 1 deletion podman/domain/containers_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ def create(
read_only (bool): Mount the container's root filesystem as read only.
read_write_tmpfs (bool): Mount temporary file systems as read write,
in case of read_only options set to True. Default: False
restart_policy (dict[str, Union[str, int]]): Restart the container when it exits.
remove (bool): Remove the container when it has finished running. Default: False.
restart_policy (dict[str, Union[str, int]]): Restart the container when it exits.
Configured as a dictionary with keys:

- Name: One of on-failure, or always.
Expand Down
146 changes: 121 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,32 +1,128 @@
[tool.black]
line-length = 100
skip-string-normalization = true
preview = true
target-version = ["py39"]
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.tox
| \.venv
| \.history
| build
| dist
| docs
| hack
)/
'''
[tool.isort]
profile = "black"
line_length = 100
[build-system]
# Any changes should be copied into requirements.txt, setup.cfg, and/or test-requirements.txt
requires = [
"setuptools>=46.4",
]
requires = ["setuptools>=46.4"]
build-backend = "setuptools.build_meta"

[project]
name = "podman"
dynamic = ["version"]
description = "Bindings for Podman RESTful API"
readme = "README.md"
license = {file = "LICENSE"}
requires-python = ">=3.9"
authors = [
{ name = "Brent Baude" },
{ name = "Jhon Honce", email = "[email protected]" },
{ name = "Urvashi Mohnani" },
{ name = "Nicola Sella", email = "[email protected]" },
]
keywords = [
"libpod",
"podman",
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries :: Python Modules",
]
# compatible releases
# ~= with version numbers
dependencies = [
"requests >=2.24",
"tomli>=1.2.3; python_version<'3.11'",
"urllib3",
]

[project.optional-dependencies]
progress_bar = [
"rich >= 12.5.1",
]
docs = [
"sphinx"
]
test = [
"coverage",
"fixtures",
"pytest",
"requests-mock",
]

[project.urls]
"Bug Tracker" = "https://github.com/containers/podman-py/issues"
Homepage = "https://github.com/containers/podman-py"
"Libpod API" = "https://docs.podman.io/en/latest/_static/api.html"

[tool.pytest.ini_options]
log_cli = true
log_cli_level = "DEBUG"
log_cli_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)"
log_cli_date_format = "%Y-%m-%d %H:%M:%S"

[tool.setuptools]
packages = ["podman"]

[tool.setuptools.dynamic]
version = {attr = "podman.version.__version__"}

[tool.ruff]
line-length = 100
src = ["podman"]

# This is the section where Black is mostly replaced with Ruff
[tool.ruff.format]
exclude = [
".git",
".history",
".tox",
".venv",
"build",
"dist",
"docs",
"hack",
]
quote-style = "preserve"

[tool.ruff.lint]
select = [
# More stuff here https://docs.astral.sh/ruff/rules/
"F", # Pyflakes
"E", # Pycodestyle Error
"W", # Pycodestyle Warning
"N", # PEP8 Naming
# TODO "UP", # Pyupgrade
# TODO "ANN",
# TODO "S", # Bandit
# "B", # Bugbear
"A", # flake-8-builtins
"YTT", # flake-8-2020
"PLC", # Pylint Convention
"PLE", # Pylint Error
"PLW", # Pylint Warning
]
# Some checks should be enabled for code sanity disabled now
# to avoid changing too many lines
ignore = [
"F821", # TODO Undefined name
"F541", # TODO f-string is missing placeholders
"F401", # TODO Module imported but unused
"F841", # TODO Local variable is assigned to but never used
"E402", # TODO Module level import not at top of file
"E741", # TODO ambiguous variable name
"E722", # TODO do not use bare 'except'
"E501", # TODO line too long
"N818", # TODO Error Suffix in exception name
"N80", # TODO Invalid Name
"ANN10", # Missing type annotation
"PLW2901", # TODO Redefined Loop Name
]
[tool.ruff.lint.flake8-builtins]
builtins-ignorelist = ["copyright", "all"]
[tool.ruff.lint.per-file-ignores]
"podman/tests/*.py" = ["S"]
7 changes: 0 additions & 7 deletions requirements.txt

This file was deleted.

49 changes: 0 additions & 49 deletions ruff.toml

This file was deleted.

8 changes: 0 additions & 8 deletions test-requirements.txt

This file was deleted.

3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ ignore_basepython_conflict = true
[testenv]
basepython = python3
usedevelop = True
install_command = pip install {opts} {packages}
deps = -r{toxinidir}/test-requirements.txt
deps = .[test]
commands = pytest {posargs}
setenv =
PODMAN_LOG_LEVEL = {env:PODMAN_LOG_LEVEL:INFO}
Expand Down