Skip to content

Commit

Permalink
Move to Hatch and hatchling as a build backend (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsoubelet authored Sep 22, 2022
1 parent 30f57a5 commit bfd0593
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 2,411 deletions.
15 changes: 5 additions & 10 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,18 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'

- name: Upgrade pip, setuptools and wheel
run: poetry run python -m pip install --upgrade pip setuptools wheel
cache: pip
cache-dependency-path: '**/pyproject.toml'

- name: Install dependencies
run: poetry install -v
- name: Install package with test dependencies
run: python -m pip install ".[test]"

- name: Run all tests
run: poetry run python -m pytest -n auto
run: make alltests

- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v1
Expand Down
34 changes: 13 additions & 21 deletions .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,28 @@ jobs:
os: [ubuntu-20.04, ubuntu-22.04, macos-latest, windows-latest]
python-version: [3.8, 3.9, "3.10", 3.x] # crons should always run latest python hence 3.x
exclude:
- os: windows-latest # scipy deps issues
python-version: "3.10"
- os: windows-latest
python-version: "3.x"
- os: macos-latest # scipy deps issues
python-version: "3.10"
- os: macos-latest
python-version: "3.x"
# - os: windows-latest # scipy deps issues
# python-version: "3.10"
# - os: windows-latest
# python-version: "3.x"
# - os: macos-latest # scipy deps issues
# python-version: "3.10"
# - os: macos-latest
# python-version: "3.x"
fail-fast: false

steps:
- uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'

- name: Upgrade pip, setuptools and wheel
run: poetry run python -m pip install --upgrade pip setuptools wheel

- name: Install dependencies
run: poetry install -v
cache: pip
cache-dependency-path: '**/pyproject.toml'

- name: Hack update scipy
run: poetry run python -m pip install --upgrade scipy
- name: Install package with test dependencies
run: python -m pip install ".[test]"

- name: Run Tests
run: poetry run python -m pytest
run: alltests
55 changes: 9 additions & 46 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,64 +29,27 @@ jobs:
- name: Install optipng, dvipng and cm-super
run: sudo apt-get install -y optipng dvipng cm-super

- name: Install poetry
run: pipx install poetry

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'

- name: Upgrade pip, setuptools and wheel
run: poetry run python -m pip install --upgrade pip setuptools wheel
cache: pip
cache-dependency-path: '**/pyproject.toml'

- name: Install dependencies
run: poetry install -v
- name: Install package with doc dependencies
run: python -m pip install ".[docs]"

# Sometimes the minrpc client will close while documentation builds and I don't know why
# Forcing several successive builds here and hoping it works out (sphinx-gallery
# checks for the existence of already built examples to avoid re-running them, so
# once the gallery is built successive builds will just re-generate the html, very quickly)
- name: Build documentation (1/10)
continue-on-error: true
run: poetry run python -m sphinx -v -b html docs doc_build -d doc_build

- name: Build documentation (2/10)
continue-on-error: true
run: poetry run python -m sphinx -v -b html docs doc_build -d doc_build

- name: Build documentation (3/10)
continue-on-error: true
run: poetry run python -m sphinx -v -b html docs doc_build -d doc_build

- name: Build documentation (4/10)
continue-on-error: true
run: poetry run python -m sphinx -v -b html docs doc_build -d doc_build

- name: Build documentation (5/10)
- name: Build documentation
continue-on-error: true
run: poetry run python -m sphinx -v -b html docs doc_build -d doc_build
run: make docs

- name: Build documentation (6/10)
continue-on-error: true
run: poetry run python -m sphinx -v -b html docs doc_build -d doc_build

- name: Build documentation (7/10)
continue-on-error: true
run: poetry run python -m sphinx -v -b html docs doc_build -d doc_build

- name: Build documentation (8/10)
continue-on-error: true
run: poetry run python -m sphinx -v -b html docs doc_build -d doc_build

- name: Build documentation (9/10)
continue-on-error: true
run: poetry run python -m sphinx -v -b html docs doc_build -d doc_build

- name: Build documentation (10/10)
continue-on-error: true
run: poetry run python -m sphinx -v -b html docs doc_build -d doc_build
# - name: Build documentation (2/n)
# continue-on-error: true
# run: make docs

# Upload artifacts if in PR so reviewers can have a quick look without building documentation from the branch locally
- name: Upload build artifacts
Expand Down
20 changes: 4 additions & 16 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,15 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'

- name: Upgrade pip, setuptools and wheel
run: poetry run python -m pip install --upgrade pip setuptools wheel

- name: Install dependencies
run: poetry install -v
- name: Install hatch
run: pipx install hatch

- name: Build wheels and sdist
run: poetry build
run: make build

- name: Publish package to PyPI
if: ${{ success() }}
env:
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: poetry publish -u "$PYPI_USERNAME" -p "$PYPI_PASSWORD"
run: hatch publish -u "$PYPI_USERNAME" -p "$PYPI_PASSWORD" --yes
42 changes: 12 additions & 30 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,24 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-22.04, macos-latest, windows-latest]
python-version: [3.8, 3.9]
python-version: [3.8, 3.9, "3.10"]
fail-fast: false

steps:
- uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'

- name: Upgrade pip, setuptools and wheel
run: poetry run python -m pip install --upgrade pip setuptools wheel

- name: Install dependencies
run: poetry install -v
cache: pip
cache-dependency-path: '**/pyproject.toml'

# Because scipy has dumb <3.12 constraint on Python which fucks the dependency resolution
- name: Hack update scipy
run: poetry run python -m pip install --upgrade scipy
- name: Install package with test dependencies
run: python -m pip install ".[test]"

- name: Run Tests
run: poetry run python -m pytest -k "not test_cpymadtools"
run: make quicktests

cpymad_tests:
needs: quick_tests
Expand All @@ -51,30 +42,21 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04, ubuntu-22.04, macos-latest, windows-latest]
python-version: [3.8, 3.9]
python-version: [3.8, 3.9, "3.10"]
fail-fast: false

steps:
- uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'

- name: Upgrade pip, setuptools and wheel
run: poetry run python -m pip install --upgrade pip setuptools wheel

- name: Install dependencies
run: poetry install -v
cache: pip
cache-dependency-path: '**/pyproject.toml'

# Because scipy has dumb <3.12 constraint on Python which fucks the dependency resolution
- name: Hack update scipy
run: poetry run python -m pip install --upgrade scipy
- name: Install package
run: python -m pip install ".[test]"

- name: Run Tests
run: poetry run python -m pytest -k "test_cpymadtools" -n auto -v
run: make slowtests
80 changes: 43 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,41 @@
# for the GNU make special targets: https://www.gnu.org/software/make/manual/html_node/Special-Targets.html
# for python packaging: https://docs.python.org/3/distutils/introduction.html

# ANSI escape sequences for bold, cyan, dark blue, end, pink and red.
B = \033[1m
C = \033[96m
D = \033[34m
E = \033[0m
P = \033[95m
R = \033[31m
# ANSI escape sequences for colors
B = \033[1m # bold
C = \033[96m # cyan
D = \033[34m # dark blue
E = \033[0m # end
P = \033[95m # pink
R = \033[31m # red
# Y = \033[33m # yellow

.PHONY : help checklist clean condaenv docker docs documentation format install interrogate lines lint tests type
.PHONY : help build clean docker docs format install lines lint typing alltests quicktests slowtests

all: install

help:
@echo "Please use 'make $(R)<target>$(E)' where $(R)<target>$(E) is one of:"
@echo " $(R) clean $(E) \t to recursively remove build, run, and bitecode files/dirs."
@echo " $(R) condaenv $(E) \t to $(D)conda create$(E) the specific 'PHD' environment I use. Personnal."
@echo " $(R) build $(E) \t to build wheel and source distribution with $(P)Hatch$(E)."
@echo " $(R) clean $(E) \t to recursively remove build, run and bitecode files/dirs."
@echo " $(R) docker $(E) \t to build a $(P)Docker$(E) container image replicating said environment (and other goodies)."
@echo " $(R) docs $(E) \t to build the documentation for the package."
@echo " $(R) docs $(E) \t to build the documentation for the package with $(P)Sphinx$(E)."
@echo " $(R) format $(E) \t to recursively apply PEP8 formatting through the $(P)Black$(E) and $(P)isort$(E) cli tools."
@echo " $(R) install $(E) \t to $(D)poetry install$(E) this package into the project's virtual environment."
@echo " $(R) install $(E) \t to $(C)pip install$(E) this package into the current environment."
@echo " $(R) lines $(E) \t to count lines of code with the $(P)tokei$(E) tool."
@echo " $(R) lint $(E) \t to lint the code though $(P)Pylint$(E)."
@echo " $(R) tests $(E) \t to run tests with the $(P)pytest$(E) package."
@echo " $(R) typing $(E) \t to run type checking with the $(P)mypy$(E) package."
@echo " $(R) typing $(E) \t to run type checking on the codebase with $(P)MyPy$(E)."
@echo " $(R) alltests $(E) \t to run the full test suite with $(P)pytest$(E)."
@echo " $(R) quicktests $(E) \t to run tests not involving $(D)pyhdtoolkit.cpymadtools$(E) with $(P)Pytest$(E)."
@echo " $(R) slowtests $(E) \t to run tests involving $(D)pyhdtoolkit.cpymadtools$(E) with $(P)Pytest$(E)."


# ----- Dev Tools Targets ----- #

build:
@echo "Re-building wheel and dist"
@rm -rf dist
@poetry build
@hatch build --clean
@echo "Created build is located in the $(C)dist$(E) folder."

clean:
Expand Down Expand Up @@ -61,50 +67,50 @@ clean:
@find . -type f -name '.coverage*' -exec rm -rf {} + -o -type f -name 'coverage.xml' -delete
@echo "All cleaned up!\n"

condaenv:
@echo "Creating $(D)PHD$(E) conda environment according to '$(C)environment.yml$(E)' file."
@conda env create -f docker/environment.yml
@echo "Adding $(D)PHD$(E) environment to base ipython kernel."
@source activate PHD
@ipython kernel install --user --name=PHD
@conda deactivate

docs:
@echo "Building static pages with $(D)Sphinx$(E)."
@poetry run python -m sphinx -b html docs doc_build -d doc_build

docker:
@echo "Building $(P)simenv$(E) Docker image with $(D)PHD$(E) conda environment, with tag $(P)latest$(E)."
@docker build -f ./docker/Dockerfile -t simenv .
@docker tag simenv simenv:latest
@echo "Done. You can run this with $(P)docker run --rm -p 8888:8888 -e JUPYTER_ENABLE_LAB=yes -v <host_dir_to_mount>:/home/jovyan/work simenv$(E)."

docs:
@echo "Building static pages with $(D)Sphinx$(E)."
@python -m sphinx -v -b html docs doc_build -d doc_build

format:
@echo "Formatting code to PEP8 with $(P)isort$(E) and $(P)Black$(E) for $(C)docs$(E), $(C)pyhdtoolkit$(E) and $(C)tests$(E) folders. Max line length is 120 characters."
@poetry run isort . && black .
@python -m isort . && black .
@echo "Formatting code to PEP8 with $(P)isort$(E) and $(P)Black$(E) for $(C)examples$(E) folder. Max line length is 95 characters."
@poetry run isort examples && black -l 95 examples
@python -m isort examples && black -l 95 examples

install: format clean
@echo "Installing through $(D)Poetry$(E), with dev dependencies but no extras."
@poetry install -v
@echo "Installing with $(D)pip$(E) in the current environment."
@python -m pip install . -v

lines: format
@tokei .

lint: format
@echo "Linting code with $(P)Pylint$(E)."
@poetry run pylint pyhdtoolkit/

tests: format clean
@poetry run pytest --no-flaky-report -n auto -p no:sugar
@make clean
@python -m pylint pyhdtoolkit/

typing: format
@echo "Checking code typing with $(P)mypy$(E)."
@poetry run mypy pyhdtoolkit
@python -m mypy pyhdtoolkit
@make clean


# ----- Tests Targets ----- #

quicktests: # all tests not involving pyhdtoolkit.cpymadtools
@python -m pytest -k "not test_cpymadtools" -n auto -v

slowtests: # all tests for pyhdtoolkit.cpymadtools
@python -m pytest -k "test_cpymadtools" -n auto -v

alltests:
@python -m pytest -n auto -v

# Catch-all unknow targets without returning an error. This is a POSIX-compliant syntax.
.DEFAULT:
@echo "Make caught an invalid target! See help output below for available targets."
Expand Down
Loading

0 comments on commit bfd0593

Please sign in to comment.