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

Modernize setup to use pyproject.toml #116

Merged
merged 13 commits into from
Nov 13, 2023
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
47 changes: 27 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,35 @@ jobs:
steps:
Copy link
Contributor Author

@pydanny pydanny Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment: Looking at this I like the bold changes. I think I get too timid with these kinds of chores, trying to keep them tiny in scope.

- checkout
- run:
name: Install dev dependencies
name: Create virtualenv
command: |
python3 -m venv ~/venv
. ~/venv/bin/activate
make install
python -m venv /home/circleci/venv/
echo "source /home/circleci/venv/bin/activate" >> $BASH_ENV
- restore_cache:
keys:
- &cache-key python-3.9-packages-v1-{{ checksum "pyproject.toml" }}
- &cache-key-prefix python-3.9-packages-v1-
- run:
name: Test
command: |
. ~/venv/bin/activate
make test
name: Install dev dependencies
command: make install
- save_cache:
key: *cache-key
paths:
- "/home/circleci/venv/"
- "/home/circleci/.cache/pip"
- run:
name: Lint
command: |
. ~/venv/bin/activate
make lint
name: Check formatting
command: make format_check
when: always
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

- run:
name: Mypy
command: |
. ~/venv/bin/activate
make mypy
name: Check linting
command: make lint_check
when: always
- run:
name: Black
command: |
. ~/venv/bin/activate
make black_check
name: Run tests
command: make test
when: always
- run:
name: Check Python type annotations
command: make mypy
when: always
16 changes: 0 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ repos:
stages: [commit]
- id: trailing-whitespace # Trims trailing whitespace.


- repo: https://github.com/timothycrosley/isort
Copy link
Contributor Author

@pydanny pydanny Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment: Thanks for the catch on pre-commit. My VSCode doesn't search in this file. Need to fix that.

rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/ambv/black
rev: 23.1.0
hooks:
- id: black

- repo: https://github.com/pycqa/flake8.git
rev: 6.0.0
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.1.1'
hooks:
Expand Down
11 changes: 5 additions & 6 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
version: 2

# Set the version of Python
# and use modern dependency management
build:
os: ubuntu-22.04
apt_packages:
- libmagic1
tools:
python: "3.10"
jobs:
pre_build:
- "pip install '.[docs]'"

# Build documentation in the docs/ directory
sphinx:
configuration: docs/conf.py

# Declare the Python requirements required to build the docs
python:
install:
- requirements: docs/requirements.txt
configuration: docs/conf.py
47 changes: 0 additions & 47 deletions Dockerfile

This file was deleted.

13 changes: 0 additions & 13 deletions docs/requirements.txt

This file was deleted.

53 changes: 24 additions & 29 deletions docs/xocto/development.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Development

This page details how to develop `xocto`.

## Installation of development environment

Create and activate a Python 3.9 virtualenv then run:
Expand All @@ -8,7 +10,7 @@ Create and activate a Python 3.9 virtualenv then run:
make install
```

to install the package including development and testing dependencies
to install the package including development and testing dependencies.

## Running tests

Expand All @@ -23,49 +25,41 @@ make test
Use these make commands:

```sh
make lint
make black
make isort
make mypy
make format_check # Check formatting
make lint_check # Check linting
make mypy # Check Python type annotations
```

Docker images for these jobs can be built with:
## Coding conventions

```sh
make docker_images
```
### Don't mix code changes with version updates

This creates separate images for pytest, isort and black. Each can be run like
so:
Code changes mixed with version updates are problematic. The reason is because
of this workflow:

```sh
docker run -v `pwd`:/opt/app xocto/pytest
docker run -v `pwd`:/opt/app xocto/isort
docker run -v `pwd`:/opt/app xocto/black
```

## Don't mix code changes with version updates

Code changes mixed with version updates are problematic. The reason is because of this workflow:

1. I write a bugfix PR that also updates the version
1. I write a bug-fix PR that also updates the version
2. You add a feature PR that also updates the version
3. Everyone else mixes version changes with their code change PRs
4. My PR is accepted, now everyone else has to update the version specified in their PR
4. My PR is accepted, now everyone else has to update the version specified in
their PR

This is why typically in shared projects version releases are seperated into their own pull requests.
This is why typically in shared projects version releases are separated into
their own pull requests.

## Publishing

Before you begin, determine the release number. This follows the instructions specifiwed on [semver.org](https://semver.org/). Releases therefore use this pattern:
### Version number

First determine the version number. Follow the instructions specified on
[semver.org](https://semver.org/) which advocates this pattern:

```
MAJOR.MINOR.PATCH
```

Where:
where:

- MAJOR version when you make incompatible API changes
- MAJOR version when you make backwards-incompatible API changes
- MINOR version when you add functionality in a backward compatible manner
- PATCH version when you make backward compatible bug fixes

Expand All @@ -75,9 +69,10 @@ Create a pull request that:

1. Adds release notes to `CHANGELOG.md`.

2. Updates the `VERSION` constant in `setup.py`.
2. Updates the `VERSION` constant in `pyproject.toml`.

3. Updates the `__version__` constant in `xocto/__init__.py`, following the [semver.org](https://semver.org/) specification.
3. Updates the `__version__` constant in `xocto/__init__.py`, following the
[semver.org](https://semver.org/) specification.

Commit these changes in a single commit with subject matching
`Bump version to v...`.
Expand Down
40 changes: 19 additions & 21 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
install:
pip install pip==23.1.2
pip install -e .[dev,test]
pip install pip==23.3.1
pip install -e '.[dev,docs]'

clean:
@echo Cleaning workspace
-rm -rf dist/ *.egg-info/ build/
-find . -type d -name __pycache__ -delete

# Static analysis
# CI step wrappers

lint:
make black_check ruff mypy
ci: format_check lint_check test mypy

black_check:
black --check --diff .
format_check:
ruff format --check .

ruff:
lint_check:
ruff check .

test:
py.test

mypy:
mypy

test:
py.test
# Local helpers

clean:
@echo Cleaning workspace
-rm -rf dist/ *.egg-info/ build/
-find . -type d -name __pycache__ -delete

format:
ruff check --fix .
black .

docker_images:
docker build -t xocto/pytest --target=pytest .
docker build -t xocto/ruff --target=ruff .
docker build -t xocto/black --target=black .
ruff format .

# Releases

VERSION=v$(shell python setup.py --version)
# Extract version from pyproject.toml
VERSION=$(shell python -c "import importlib.metadata; print(importlib.metadata.version('xocto'))")

tag:
@echo Tagging as $(VERSION)
Expand Down
Loading