Skip to content

Commit

Permalink
Hatch (#6)
Browse files Browse the repository at this point in the history
* Update build system to Hatch and use ruff. Add pre-commit.

* Add Ruff badge
  • Loading branch information
mcarans authored Mar 18, 2024
1 parent 81bbe96 commit 09fb2b7
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 162 deletions.
17 changes: 17 additions & 0 deletions .config/coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[run]
source = src

omit = */_version.py

[report]
exclude_also =
from ._version
def __repr__
if self.debug:
if settings.DEBUG
raise AssertionError
raise NotImplementedError
if 0:
if __name__ == .__main__.:
if TYPE_CHECKING:
@(abc\.)?abstractmethod
25 changes: 25 additions & 0 deletions .config/pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
default_language_version:
python: python3.11
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-ast
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.2
hooks:
# Run the linter.
- id: ruff
args: [--config, .config/ruff.toml, --fix]
# Run the formatter.
- id: ruff-format
args: [--config, .config/ruff.toml]
- repo: https://github.com/jazzband/pip-tools
rev: 7.4.1
hooks:
- id: pip-compile
name: pip-compile requirements.txt
files: pyproject.toml
args: [pyproject.toml, --resolver=backtracking, --all-extras, --upgrade, -q, -o, requirements.txt]
4 changes: 4 additions & 0 deletions .config/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
pythonpath = ../src
addopts = "--color=yes"
log_cli = 1
16 changes: 16 additions & 0 deletions .config/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
line-length = 79
exclude = ["_version.py"]

[lint]
# List of rules: https://docs.astral.sh/ruff/rules/
select = [
"E", # pycodestyle - default
"F", # pyflakes - default
"I" # isort
]
ignore = [
"E501" # Line too long
]

[lint.isort]
known-local-folder = ["pytest_loguru"]
19 changes: 11 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Get history and tags for SCM versioning to work
- uses: actions/checkout@v4
- name: Get history and tags for versioning to work
run: |
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade tox-gh-actions
- name: Publish with tox and twine
pip install --upgrade hatch
- name: Build with hatch
run: |
hatch build
- name: Publish with hatch
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
HATCH_INDEX_USER: ${{secrets.HATCH_INDEX_USER}}
HATCH_INDEX_AUTH: ${{secrets.HATCH_INDEX_AUTH}}
run: |
tox -e publish
hatch publish
31 changes: 20 additions & 11 deletions .github/workflows/run-python-tests.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# This workflow will install Python dependencies, lint and run tests
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: build
name: Run tests

on:
workflow_dispatch: # add run button in github
push:
branches-ignore:
- gh-pages
- 'dependabot/**'
pull_request:
branches-ignore:
- gh-pages
Expand All @@ -16,24 +18,31 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade tox-gh-actions
- name: Test with tox/pytest
pip install --upgrade hatch
- name: Test with hatch/pytest
run: |
tox
hatch run test:test
- name: Check styling
if: always()
run: |
hatch run lint:style
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
files: .tox/*.xml
- name: Upload Coverage Results
uses: codecov/codecov-action@v2
if: success()
junit_files: test-results.xml
- name: Publish in Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: tests
format: lcov
55 changes: 55 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Development

## Environment

Development is currently done using Python 3.11. We recommend using a virtual
environment such as ``venv``:

python3.11 -m venv venv
source venv/bin/activate

In your virtual environment, please install all packages for
development by running:

pip install -r requirements.txt

## Pre-Commit

Also be sure to install `pre-commit`, which is run every time
you make a git commit:

pre-commit install

The configuration file for this project is in a
non-standard location. Thus, you will need to edit your
`.git/hooks/pre-commit` file to reflect this. Change
the line that begins with `ARGS` to:

ARGS=(hook-impl --config=.config/pre-commit-config.yaml --hook-type=pre-commit)

With pre-commit, all code is formatted according to
[ruff](https://github.com/astral-sh/ruff) guidelines.

To check if your changes pass pre-commit without committing, run:

pre-commit run --all-files --config=.config/pre-commit-config.yaml

## Testing

To run the tests and view coverage, execute:

pytest -c .config/pytest.ini --cov hdx --cov-config .config/coveragerc

## Packages

[pip-tools](https://github.com/jazzband/pip-tools) is used for
package management. If you’ve introduced a new package to the
source code (i.e.anywhere in `src/`), please add it to the
`project.dependencies` section of
`pyproject.toml` with any known version constraints.

Any changes to the dependencies will be automatically reflected in
`requirements.txt` with `pre-commit`, but you can re-generate
the file without committing by executing:

pre-commit run pip-compile --all-files --config=.config/pre-commit-config.yaml
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
[![PyPI](https://img.shields.io/pypi/v/pytest-loguru.svg)](https://pypi.python.org/pypi/pytest-loguru)
[![Conda Version](https://img.shields.io/conda/vn/conda-forge/pytest-loguru.svg)](https://anaconda.org/conda-forge/pytest-loguru)
[![Coverage Status](https://codecov.io/gh/mcarans/pytest-loguru/branch/main/graph/badge.svg?token=JpWZc5js4y)](https://codecov.io/gh/mcarans/pytest-loguru)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

### pytest-loguru

Expand Down
167 changes: 87 additions & 80 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,87 +1,94 @@
[build-system]
requires = [ "setuptools>=45", "setuptools_scm[toml]>=6.2", "wheel"]
build-backend = "setuptools.build_meta"
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[tool.setuptools_scm]
write_to = "src/pytest_loguru/_version.py"
[project]
name = "pytest-loguru"
description = "Pytest Loguru"
authors = [{name = "Michael Rans"}]
license = "MIT"
keywords = ["loguru", "py.test", "pytest"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Topic :: Software Development :: Libraries :: Python Modules",
"Framework :: Pytest",
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: POSIX :: Linux",
"Operating System :: Unix",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
]

requires-python = ">=3.8"

dependencies = ["loguru"]

dynamic = ["version"]

readme = "README.md"

[project.urls]
Homepage = "https://github.com/mcarans/pytest-loguru"

[project.entry-points.pytest11]
loguru = "pytest_loguru.plugin"

[project.optional-dependencies]
test = ["pytest", "pytest-cov"]

#########
# Hatch #
#########

# Build

[tool.hatch.build.targets.wheel]
packages = ["src/pytest_loguru"]

[tool.hatch.build.hooks.vcs]
version-file = "src/pytest_loguru/_version.py"

# Versioning

[tool.hatch.version]
source = "vcs"

[tool.hatch.version.raw-options]
local_scheme = "no-local-version"
version_scheme = "python-simplified-semver"

[tool.black]
line-length = 79

[tool.isort]
profile = "black"
line_length = 79
multi_line_output = 3

[tool.flake8]
exclude = ["_version.py"]
ignore = ["E203", "E501", "W503"]
max-line-length = 79
count = true
show_source = true

[tool.pytest.ini_options]
pythonpath = "src"
addopts = "--color=yes"
log_cli = 1

[tool.coverage.paths]
source = ["src/pytest_loguru", "*/site-packages/pytest_loguru"]

[tool.coverage.report]
omit = [
"*/setup.py",
"*/python?.?/*",
"*/venv/*",
"*/site-packages/*",
"*/tests/*",
"*__init__*"
]
# Tests

exclude_lines = [
"pragma: no cover", # Have to re-enable the standard pragma
"def __repr__", # Don't complain about missing
"if self.debug", # debug-only code
"raise AssertionError", # Don't complain if tests don't hit
"raise NotImplementedError", # defensive assertion code
"if 0:", # Don't complain if non-runnable code
"if __name__ == .__main__.:" # isn't run
]
[tool.hatch.envs.test]
features = ["test"]

[tool.hatch.envs.test.scripts]
test = """
pytest -c .config/pytest.ini --rootdir=. --junitxml=test-results.xml \
--cov --cov-config=.config/coveragerc --no-cov-on-fail \
--cov-report=lcov --cov-report=term-missing
"""

[[tool.hatch.envs.test.matrix]]
python = ["3.12"]

[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py311, lint
[gh-actions]
python =
3: py311, lint
[testenv]
package = wheel
wheel_build_env = .pkg
deps =
-r test-requirements.txt
commands =
pytest --cov=hdx --no-cov-on-fail --junitxml=.tox/test-results.xml --cov-report=xml --cov-report=term-missing
[testenv:lint]
deps =
flake8
flake8-isort
flake8-black
flake8-pyproject
commands =
flake8 --color=always src tests
[testenv:publish]
package = sdist
pass_env = SSH_AUTH_SOCK, TWINE_USERNAME, TWINE_PASSWORD
deps =
twine
commands =
twine upload {work_dir}/{package_env}/dist/*
"""
[tool.hatch.envs.lint]
detached = true
dependencies = ["ruff"]

[tool.hatch.envs.lint.scripts]
style = [
"ruff check --config .config/ruff.toml --diff {args:.}",
"ruff format --config .config/ruff.toml --diff {args:.}",
]
Loading

0 comments on commit 09fb2b7

Please sign in to comment.