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
32 changes: 15 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,26 @@ 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
- run:
name: Install dev dependencies
command: make install
- run:
name: Test
command: |
. ~/venv/bin/activate
make test
command: make test
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: Lint
command: |
. ~/venv/bin/activate
make lint
command: make ruff
when: always
- run:
name: Mypy
command: |
. ~/venv/bin/activate
make mypy
command: make mypy
when: always
- run:
name: Black
command: |
. ~/venv/bin/activate
make black_check
name: Format
command: make format_check
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
16 changes: 0 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,3 @@ FROM base as pytest
# in.
ENTRYPOINT ["py.test"]
CMD [""]

# ---

# Create a isort image from the base
FROM base as isort

ENTRYPOINT ["isort"]
CMD ["-rc"]

# ---

# Create a black image from the base
FROM base as black

ENTRYPOINT ["black"]
CMD ["."]
13 changes: 0 additions & 13 deletions docs/requirements.txt

This file was deleted.

28 changes: 15 additions & 13 deletions docs/xocto/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ Use these make commands:

```sh
make lint
make black
make isort
make format
make mypy
```

Expand All @@ -35,35 +34,37 @@ Docker images for these jobs can be built with:
make docker_images
```

This creates separate images for pytest, isort and black. Each can be run like
so:
This creates an image for pytest. Each can be run like so:

```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:
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
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 seperated 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:
Before you begin, determine the release number. This follows the instructions
specifiwed on [semver.org](https://semver.org/). Releases therefore use this
pattern:

```
MAJOR.MINOR.PATCH
```

Where:
Where:

- MAJOR version when you make incompatible API changes
- MINOR version when you add functionality in a backward compatible manner
Expand All @@ -75,9 +76,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
15 changes: 7 additions & 8 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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
Expand All @@ -10,10 +10,10 @@ clean:
# Static analysis

lint:
make black_check ruff mypy
make format_check ruff mypy

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

ruff:
ruff check .
Expand All @@ -26,16 +26,15 @@ test:

format:
ruff check --fix .
black .
ruff format .

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

# Releases

VERSION=v$(shell python setup.py --version)
VERSION=v$(shell grep -m 1 version pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3)

tag:
@echo Tagging as $(VERSION)
Expand Down
80 changes: 77 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,79 @@
[tool.black]
line-length = 99
[build-system]
requires = ["setuptools>=68.2.2"]
build-backend = "setuptools.build_meta"

[project]
name = "xocto"
version = "4.9.0"
requires-python = ">=3.9"
description = "Kraken Technologies Python service utilities"
readme = "README.md"
authors = [
{name = "Kraken Technologies", email = "[email protected]"},
]
maintainers = [
{name = "Kraken Technologies", email = "[email protected]"},
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Topic :: Software Development :: Build Tools",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add support for Python 3.12 at some point too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, created #121.

]
license = {text = "MIT"}
dependencies = [
"ddtrace>=1.9.0",
"duckdb>=0.9.0",
"django>=4.0",
"openpyxl>=3.1.0",
"pact-python>=1.6.0",
"pandas>=1.5.3",
"pyarrow>=11.0.0",
"python-dateutil>=2.8.2",
"python-magic>=0.4.27",
"pytz",
"structlog>=20.2.0",
"xlrd>=2.0.1",
]

[project.optional-dependencies]
dev = [
"boto3==1.26.53",
"botocore==1.29.53",
"hypothesis==6.62.1",
"moto[s3,sqs]==4.1",
"mypy-boto3-s3==1.26.0.post1",
"mypy==0.991",
"numpy==1.22.2",
"pre-commit>=3.2.0",
"pyarrow-stubs==10.0.1.6",
"pytest-django==4.5.2",
"pytest-mock==3.10.0",
"pytest==7.2.1",
"ruff==0.1.3",
"time-machine==2.9.0",
"twine==4.0.2",
"types-openpyxl==3.0.4.5",
"types-python-dateutil==2.8.19.6",
"types-pytz==2022.7.1.0",
"types-requests==2.28.11.8",
"wheel==0.38.4",
]
docs = [
"Sphinx==4.5.0",
"myst-parser==0.18.1",
]

[project.urls]
changelog = "https://github.com/octoenergy/xocto/blob/main/CHANGELOG.md"
documentation = "https://xocto.readthedocs.io"
issues = "https://github.com/octoenergy/xocto/issues"

[tool.setuptools]
packages = ["xocto", "xocto.events", "xocto.storage"]

[tool.mypy]
# Specify which files to check.
Expand Down Expand Up @@ -78,7 +152,7 @@ select = [
"I", # isort
]
ignore = [
"E501", # line too long - black takes care of this for us
"E501", # line too long
]

[tool.ruff.per-file-ignores]
Expand Down
26 changes: 0 additions & 26 deletions setup.cfg

This file was deleted.

Loading