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

[wip] Migrate the project to pyproject.toml #422

Closed
wants to merge 6 commits into from
Closed
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
1 change: 0 additions & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@

script:
- make
- make lint

test_task:

Check warning on line 50 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L50

task "Test on Fedora" depends on task "Gating test", but their only_if conditions are different

Check warning on line 50 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L50

task "Test on Fedora" depends on task "Gating test", but their only_if conditions are different
name: "Test on Fedora"
alias: test

Expand All @@ -61,7 +60,7 @@
- ${SCRIPT_BASE}/enable_podman.sh
- ${SCRIPT_BASE}/test.sh

latest_task:

Check warning on line 63 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L63

task "Test Podman main on Fedora" depends on task "Gating test", but their only_if conditions are different

Check warning on line 63 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L63

task "Test Podman main on Fedora" depends on task "Gating test", but their only_if conditions are different
name: "Test Podman main on Fedora"
alias: latest
allow_failures: true
Expand Down Expand Up @@ -104,7 +103,7 @@
# Status aggregator for all tests. This task simply ensures a defined
# set of tasks all passed, and allows confirming that based on the status
# of this task.
success_task:

Check warning on line 106 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L106

task "Total Success" depends on task "Gating test", but their only_if conditions are different

Check warning on line 106 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L106

task "Total Success" depends on task "Gating test", but their only_if conditions are different
name: "Total Success"
alias: success

Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
env:
SKIP: no-commit-to-branch
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: |
3.9
3.x
- uses: pre-commit/[email protected]
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ venv.bak/

# mypy
.mypy_cache/

# test containers
.containerfile.*
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.0
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
41 changes: 29 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ Please don't include any private/sensitive information in your issue!

## Tools we use

- Python 3.6
- [pylint](https://www.pylint.org/)
- [black](https://github.com/psf/black)
- [tox](https://tox.readthedocs.io/en/latest/)
- You may need to use [virtualenv](https://virtualenv.pypa.io/en/latest/) to
support Python 3.6
- Python >= 3.6
- [Hatch](https://hatch.pypa.io/)
- [pre-commit](https://pre-commit.com/)
- [ruff](https://docs.astral.sh/ruff/)

## Testing

Expand All @@ -41,10 +39,25 @@ Integration tests would be required for large changes (TBD).
Run unit tests and get coverage report:

```
pip install tox
tox -e coverage
hatch run test:cov
```

If you need to run individual tests you could use the hatch commands that wrap pytest:

```
hatch run test:run -vv podman/tests/integration/test_file.py -k "test_name"
```

It is worth mentioning that in this context test is not a command but it means the testing environment. The command is
specified after the colon and it could be one of the commands defined in pyproject.toml or any command that can be run
in the environment (like `test:pip` will run `pip` in the default `test` environment).

To use a separate environment replace `test` with `test.py3.10`, for example. See all the environments available with
`hatch env show`.

You might be used to create virtual envs and sourcing them via `source .venv/bin/activate`. Well, now you can do that
with hatch by running `hatch shell` or, for a specific environment `hatch shell test.py3.10`.

## Submitting changes

- Create a github pull request (PR)
Expand All @@ -65,10 +78,14 @@ tox -e coverage

## Coding conventions

- Use [black](https://github.com/psf/black) code formatter. If you have tox
installed, run `tox -e black` to see what changes will be made. You can use
`tox -e black-format` to update the code formatting prior to committing.
- Pass pylint
- Formatting and linting are incorporated using [ruff](https://docs.astral.sh/ruff/).
- If you use [pre-commit](https://pre-commit.com/) the checks will run automatically
when you commit some changes
- If you prefer to run the ckecks with pre-commit, use `pre-commit run -a` to run the
pre-commit checks for you.
- If you'd like to see what's happening with the checks you can run the [linter](https://docs.astral.sh/ruff/linter/)
and [formatter](https://docs.astral.sh/ruff/formatter/) separately with `ruff check --diff` and `ruff format --diff`
- Checks need to pass pylint
- exceptions are possible, but you will need to make a good argument
- Use spaces not tabs for indentation
- This is open source software. Consider the people who will read your code,
Expand Down
27 changes: 12 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,35 @@ export PODMAN_VERSION ?= "5.3.0"
.PHONY: podman
podman:
rm dist/* || :
$(PYTHON) -m pip install --user -r requirements.txt
$(PYTHON) -m pip install --user .
$(PYTHON) -m pip install --user hatch
PODMAN_VERSION=$(PODMAN_VERSION) \
$(PYTHON) setup.py sdist bdist bdist_wheel

.PHONY: lint
lint: tox
$(PYTHON) -m tox -e black,pylint
$(PYTHON) -m hatch build

.PHONY: tests
tests: tox
# see tox.ini for environment variable settings
$(PYTHON) -m tox -e coverage,py39,py310,py311,py312,py313
tests: hatch
# run tests on all the envs set in tool.hatch.envs.test.matrix
$(PYTHON) -m hatch run test:cov

.PHONY: unittest
unittest:
coverage run -m unittest discover -s podman/tests/unit
coverage report -m --skip-covered --fail-under=80 --omit=./podman/tests/* --omit=.tox/* --omit=/usr/lib/*
coverage report -m --skip-covered --fail-under=80 --omit=./podman/tests/* --omit=/usr/lib/*

.PHONY: integration
integration:
coverage run -m unittest discover -s podman/tests/integration
coverage report -m --skip-covered --fail-under=80 --omit=./podman/tests/* --omit=.tox/* --omit=/usr/lib/*
coverage report -m --skip-covered --fail-under=80 --omit=./podman/tests/* --omit=/usr/lib/*

.PHONY: tox
tox:
.PHONY: hatch
hatch:
ifeq (, $(shell which dnf))
brew install [email protected] [email protected] [email protected] [email protected] [email protected]
else
-dnf install -y python3 python3.9 python3.10 python3.11 python3.12 python3.13
endif
# ensure tox is available. It will take care of other testing requirements
$(PYTHON) -m pip install --user tox
# ensure hatch is available. It will take care of other testing requirements
$(PYTHON) -m pip install --user hatch

.PHONY: test-release
test-release: SOURCE = $(shell find dist -regex '.*/podman-[0-9][0-9\.]*.tar.gz' -print)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ 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).
* Runtime dependencies are specified in [pyproject.toml](https://github.com/containers/podman-py/blob/main/pyproject.toml).
* Testing dependencies can be installed via `pip install -e .[test]`

## Example usage

Expand Down
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

# -- Project information -----------------------------------------------------

project = u'Podman Python SDK'
copyright = u'2021, Red Hat Inc'
author = u'Red Hat Inc'
project = 'Podman Python SDK'
copyright = '2021, Red Hat Inc'
author = 'Red Hat Inc'

# The full version, including alpha/beta/rc tags
version = '3.2.1.0'
Expand Down
Loading
Loading