Skip to content

Commit

Permalink
Switch to Hatch (#403)
Browse files Browse the repository at this point in the history
* Use Hatch for build and environments
* Reinstate coveralls service
* Switch Read the Docs to Fural theme
  • Loading branch information
dyve committed Jun 2, 2023
1 parent 89a95bf commit 8f6e59c
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 316 deletions.
67 changes: 0 additions & 67 deletions .github/workflows/ci.yml

This file was deleted.

76 changes: 76 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: test

on: [ push ]

concurrency:
group: test-${{ github.head_ref }}
cancel-in-progress: true

env:
PYTHONUNBUFFERED: "1"
FORCE_COLOR: "1"

jobs:

static_tests:
name: Static Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install latest pip and Hatch
run: pip install --upgrade pip hatch
- name: Lint
run: hatch run lint:all
- name: Docs
run: hatch run docs:build
- name: Build
run: hatch build

tests_matrix:
name: Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v3

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

- name: Install latest pip, Hatch and coveralls
run: pip install --upgrade pip hatch coveralls

- name: Run tests
run: hatch run test-cov

- name: Coverage combine
run: coverage combine

- name: Upload coveralls (parallel)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
run: coveralls --service=github

tests:
if: always()
runs-on: ubuntu-latest
needs: [ static_tests, tests_matrix ]
steps:
- name: Check tests matrix status
if: needs.tests_matrix.result != 'success'
run: exit 1
- name: Finish parallel build
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
github-token: ${{ secrets.GITHUB_TOKEN }}
24 changes: 8 additions & 16 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

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

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.8
install:
- requirements: docs/requirements.txt
- method: pip
path: .
build:
os: ubuntu-22.04
tools:
python: "3.11"
commands:
- pip install -U pip hatch
- hatch run docs:build
- mv docs/_build $READTHEDOCS_OUTPUT
28 changes: 10 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,33 @@ Ready to contribute? Here\'s how to set up `django-icons` for local development.

You will need some knowledge of git, github, and Python/Django development. Using a Python virtual environment is advised.

This project uses [Hatch](https://github.com/pypa/hatch) for environments and builds.

### Local installation

This section assumes you know about local Python versions and virtual environments.

To clone the repository and install the requirements for local development:

```shell-script
```console
git clone git://github.com/zostera/django-icons.git
cd django-icons
pip install -U pip hatch
pip install -e .
pip install -U pip -r requirements-dev.txt
```

### Running the example app

You can run the example app:

```shell-script
cd example && python manage.py runserver
```

### Running the tests

The test suite requires tox to be installed.

To run the complete test suite:
To run the tests:

```shell-script
make tox
```console
make test
```

To run the tests in your current environment:
To run the tests on all supported Python/Django combinations:

```shell-script
make test
```console
make tests
```

## Pull Request Guidelines
Expand Down
39 changes: 12 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
VERSION := $(shell hatch version)

.PHONY: test
test:
coverage run manage.py test
coverage report
hatch run test

.PHONY: tox
tox:
rm -rf .tox
tox
.PHONY: tests
tests:
hatch run all:test

.PHONY: reformat
reformat:
ruff check . --fix
black .
hatch run lint:fmt

.PHONY: lint
lint:
ruff . --no-fix
black . --check
hatch run lint:style

.PHONY: docs
docs:
cd docs && sphinx-build -b html -d _build/doctrees . _build/html
hatch run docs:build

.PHONY: porcelain
porcelain:
Expand All @@ -42,24 +40,11 @@ endif

.PHONY: build
build: docs
rm -rf build dist *.egg-info
python -m build .
rm -rf build dist src/*.egg-info
hatch build

.PHONY: publish
publish: VERSION := $(shell python -c 'from setuptools.config.setupcfg import read_configuration as c; print(c("setup.cfg")["metadata"]["version"])')
publish: porcelain branch build
twine upload dist/*
rm -rf build dist *.egg-info
hatch publish
git tag -a v${VERSION} -m "Release ${VERSION}"
git push origin --tags

.PHONY: check-description
check-description:
rm -rf build-check-description
pip wheel -w build-check-description --no-deps .
twine check build-check-description/*
rm -rf build-check-description

.PHONY: check-manifest
check-manifest:
check-manifest --verbose
35 changes: 15 additions & 20 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import importlib
import os
from configparser import ConfigParser
from datetime import datetime

on_rtd = os.environ.get("READTHEDOCS", None) == "True"
import tomllib

config_parser = ConfigParser()
config_parser.read("../setup.cfg")
metadata = config_parser["metadata"]
with open("../pyproject.toml", "rb") as f:
pyproject = tomllib.load(f)

project = metadata["name"]
project_with_underscores = project.replace("-", "_")
project = pyproject["project"]["name"]
conf = {"module": project.replace("-", "_")}

module = importlib.import_module(f"{project_with_underscores}")
# The full version, including alpha/beta/rc tags, in x.y.z.misc format
try:
conf.update(pyproject["tool"]["sphinx"]["x-conf"])
except KeyError:
pass

module = importlib.import_module(conf["module"])
release = module.__version__
# The short X.Y version.
version = ".".join(release.split(".")[:2])

author = metadata["author"]
author = ", ".join(author["name"] for author in pyproject["project"]["authors"])
year = datetime.now().year
copyright = f"{year}, {author}"

Expand All @@ -27,11 +26,7 @@
"sphinx.ext.viewcode",
"sphinx_mdinclude",
]
pygments_style = "sphinx"
htmlhelp_basename = f"{project}-doc"

if not on_rtd: # only import and set the theme if we're building docs locally
import sphinx_rtd_theme

html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
htmlhelp_basename = f"{project}-doc"
html_theme = "furo"
pygments_style = "sphinx"

0 comments on commit 8f6e59c

Please sign in to comment.