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

MNT: switch to pyproject.toml, PEP-518 build system and improve CI #498

Merged
merged 13 commits into from
Dec 31, 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
13 changes: 8 additions & 5 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@ jobs:
python-version: '3.9'

- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch the complete repo history (for setuptools-scm)

- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: pip-cache-${{ hashFiles('requirements/*/*.txt') }}
key: pip-cache-${{ hashFiles('requirements/*.txt') }}
restore-keys: |
pip-cache

- name: Install python requirements
run: |
python3 -m pip install --upgrade pip setuptools wheel
python3 -m pip install -r requirements-dev.txt
python -m pip install --upgrade pip
python -m pip install --upgrade build twine
python -m pip install -r requirements/dev.txt

- name: Create cache directory
run: |
Expand All @@ -51,7 +54,7 @@ jobs:

- name: Install Fast-F1 from sources
run: |
python3 -m pip install -e .
python -m pip install -e .

- name: Create doc build dir
run: |
Expand Down
20 changes: 14 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch the complete repo history (for setuptools-scm)
- uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
python -m pip install --upgrade build twine

# if this is a release, upload to PyPI
- name: Build and publish release
Expand All @@ -26,15 +28,21 @@ jobs:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
python setup.py sdist bdist_wheel
PACKAGE_VERSION=$(hatch version)
echo "Creating package with version $PACKAGE_VERSION"
python -m build
twine upload dist/*

# if this is a manual dispatch, upload to TestPyPI
# if this is a manual dispatch, upload to PyPI test index
- name: Build and publish test release
if: github.event_name == 'workflow_dispatch'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN}}
# override setuptools_scm config to remove local version, else PyPI will not accept the package
# this allows to push development releases to the test index from any repository state
run: |
python setup.py sdist bdist_wheel
PACKAGE_VERSION=$(hatch version)
echo "Creating package with version $PACKAGE_VERSION"
python -m build
twine upload --repository testpypi dist/*
2 changes: 1 addition & 1 deletion .github/workflows/selective_cache_persist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11']
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12']
name: Tests on ${{ matrix.python-version }}
steps:
- name: Create cache directory
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/semver_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Hatch SCM versioning test

on:
workflow_dispatch:

jobs:
versioning-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch the complete repo history (for setuptools-scm)
- uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade hatch

# if this is a manual dispatch, upload to TestPyPI
- name: Get SCM based version from build system
run: |
hatch version
94 changes: 38 additions & 56 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,40 @@ jobs:
run-code-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12']
name: Tests on ${{ matrix.python-version }}
include:
- name-suffix: "(Minimum Versions)"
python-version: "3.8"
extra-requirements: "-c requirements/minver.txt"
- python-version: "3.8"
- python-version: "3.9"
- python-version: "3.10"
- python-version: "3.11"
- python-version: "3.12"
name: Tests on ${{ matrix.python-version }} ${{ matrix.name-suffix }}
steps:
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: pip-cache-${{ hashFiles('requirements/*/*.txt') }}
key: pip-cache-${{ hashFiles('requirements/*.txt') }}
restore-keys: |
pip-cache

- name: Install python requirements
run: |
python3 -m pip install --upgrade pip setuptools wheel
python3 -m pip install -r requirements-dev.txt
python -m pip install --upgrade pip
python -m pip install --upgrade build twine
python -m pip install -r requirements/dev.txt ${{ matrix.extra-requirements }}

- name: Install Fast-F1 from sources
run: |
Expand All @@ -57,92 +67,64 @@ jobs:
run: |
pytest -ra


run-lint-checks:
runs-on: ubuntu-latest
name: Flake8 lint checks
name: Linting (Ruff)
steps:
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.12'

- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: pip-cache-${{ hashFiles('requirements/*/*.txt') }}
key: pip-cache-${{ hashFiles('requirements/*.txt') }}
restore-keys: |
pip-cache

- name: Install python requirements
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements-dev.txt
python -m pip install --upgrade pip
python -m pip install --upgrade build setuptools twine
python -m pip install -r requirements/dev.txt

- name: Install Fast-F1 from sources
- name: Install FastF1 from sources
run: |
python3 -m pip install -e .
python -m pip install -e .

- name: Run tests
if: ${{ github.ref != 'refs/heads/master' }}
run: |
mkdir test_cache # make sure cache dir exists
git fetch origin --quiet
# flake8 with default config
flake8 fastf1 examples scripts
# flake8 check new shorter line length only on diff
git diff origin/master -U0 --relative | flake8 --max-line-length 79 --diff --select E501 fastf1 examples scripts

- name: Run tests (master push)
if: ${{ github.ref == 'refs/heads/master' && env.GITHUB_EVENT_NAME == 'push'}}
env:
LAST_PUSH_SHA: ${{ github.event.before }}
run: |
mkdir test_cache # make sure cache dir exists
git fetch origin --quiet
# flake8 with default config
flake8 fastf1 examples scripts
# flake8 check new shorter line length only on diff
echo "Flake8 line length check on diff against $LAST_PUSH_SHA"
git diff $LAST_PUSH_SHA -U0 --relative | flake8 --max-line-length 79 --diff --select E501 fastf1 examples scripts
# ruff with default config
ruff check .


run-readme-render-test:
name: Test readme renders on PyPi
runs-on: ubuntu-latest
steps:
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Checkout repo
uses: actions/checkout@v3

- name: Cache pip
uses: actions/cache@v3
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
path: ~/.cache/pip
key: pip-cache-${{ hashFiles('requirements/*/*.txt') }}
restore-keys: |
pip-cache

- name: Install python requirements
python-version: '3.12'
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip setuptools wheel
python3 -m pip install -r requirements-dev.txt
python -m pip install --upgrade pip
python -m pip install --upgrade build twine

- name: Install Fast-F1 from sources
- name: Build release and check long form description
run: |
python3 -m pip install -e .
python -m build
twine check dist/*

- name: Run tests
run: |
mkdir test_cache # not really need but pytest setup relies on it
pytest -rf --prj-doc

run-sphinx-build-test:
name: Test Docs
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ dist/
build/
fastf1.egg-info/

# version info dynamically created by setuptools-scm
fastf1/_version.py

# temporary testrun directories
fastf1/tests/testenv/
fastf1/tests/mpl-results/
Expand All @@ -25,6 +28,7 @@ fastf1/tests/mpl-baseline-new/
# documentation build directories
docs/_build/
docs/examples_gallery/
**/sg_execution_times.rst

# all variations of cache directories
*_cache/
Expand Down
14 changes: 5 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.0.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.8
hooks:
- id: flake8
- repo: local
hooks:
- id: flake8-line-length
name: Flake8 line length
entry: python ./scripts/flake8_line_length.py
language: python
# Run the linter.
- id: ruff
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Philipp Schäfer
Copyright (c) 2024 Philipp Schäfer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ It is recommended to install FastF1 using `pip`:
pip install fastf1
```

Note that Python 3.8 or higher is required.

Alternatively, a wheel or a source distribution can be downloaded from Pypi.

You can also install using `conda`:
Expand All @@ -41,9 +39,9 @@ conda install -c conda-forge fastf1

- R package that wraps FastF1: https://github.com/SCasanova/f1dataR

These packages are not directly related to the FastF1 project. Questions and
suggestions regarding these packages need to be directed at their respective
maintainers.
Third-party packages are not directly related to the FastF1 project. Questions
and suggestions regarding these packages need to be directed at their
respective maintainers.

## Documentation

Expand Down
9 changes: 0 additions & 9 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ def pytest_addoption(parser):
"--ergast-api", action="store_true", default=False,
help="run tests which require connecting to ergast"
)
parser.addoption(
"--lint-only", action="store_true", default=False,
help="only run linter and skip all tests"
)
parser.addoption(
"--prj-doc", action="store_true", default=False,
help="run only tests for general project structure and documentation"
Expand Down Expand Up @@ -65,11 +61,6 @@ def pytest_collection_modifyitems(config, items):
if "ergastapi" in item.keywords:
item.add_marker(skip_ergast)

# lint only: skip all
if config.getoption('--lint-only'):
items[:] = [item for item in items
if item.get_closest_marker('flake8')]

# only test documentation and project structure
if config.getoption('--prj-doc'):
skip_non_prj = pytest.mark.skip(reason="--prj-doc given: run only "
Expand Down
3 changes: 3 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ help:

.PHONY: help Makefile

show:
@python -c "import webbrowser; webbrowser.open_new_tab('file://$(shell pwd)/_build/html/index.html')"

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
Expand Down
Loading