Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fnesveda committed Sep 6, 2023
0 parents commit d86350c
Show file tree
Hide file tree
Showing 25 changed files with 784 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf

[Makefile]
indent_style = tab

[{*.yaml, *.yml}]
indent_size = 2
29 changes: 29 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[flake8]
filename =
./scripts/*.py,
./src/*.py,
./tests/*.py
per-file-ignores =
scripts/*: D
tests/*: D

# Google docstring convention + D204 & D401
docstring-convention = all
ignore =
D100
D104
D203
D213
D215
D406
D407
D408
D409
D413
U101

max_line_length = 150
unused-arguments-ignore-overload-functions = True
unused-arguments-ignore-stub-functions = True
pytest-fixture-no-parentheses = True
pytest-mark-no-parentheses = True
15 changes: 15 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Code quality checks

on:
pull_request:

jobs:
lint_and_type_checks:
name: Run lint and type checks
uses: ./.github/workflows/lint_and_type_checks.yaml

unit_tests:
name: Run unit tests
needs: [lint_and_type_checks]
uses: ./.github/workflows/unit_tests.yaml

30 changes: 30 additions & 0 deletions .github/workflows/lint_and_type_checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Lint and type checks

on:
workflow_call:

jobs:
lint_and_type_checks:
name: Lint and type checks
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- name: Checkout repository
uses: actions/checkout@v4

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

- name: Install dependencies
run: make install-dev

- name: Run lint
run: make lint

- name: Run type checks
run: make type-check
108 changes: 108 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Check & Release

on:
# Push to master will publish a beta version
push:
branches:
- master
tags-ignore:
- "**"
# A release via GitHub releases will publish a stable version
release:
types: [published]
# Workflow dispatch will publish whatever you choose
workflow_dispatch:
inputs:
release_type:
description: Release type
required: true
type: choice
default: alpha
options:
- alpha
- beta
- final

jobs:
lint_and_type_checks:
name: Run lint and type checks
uses: ./.github/workflows/lint_and_type_checks.yaml

unit_tests:
name: Run unit tests
uses: ./.github/workflows/unit_tests.yaml

publish_to_pypi:
name: Publish to PyPI
needs: [lint_and_type_checks, unit_tests]
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
environment:
name: pypi
url: https://pypi.org/p/flake8-no-pytest-mark-only

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install dependencies
run: make install-dev

- # Determine if this is a prerelease or latest release
name: Determine release type
id: get-release-type
run: |
if [ ${{ github.event_name }} = release ]; then
release_type="final"
elif [ ${{ github.event_name }} = push ]; then
release_type="beta"
elif [ ${{ github.event_name }} = workflow_dispatch ]; then
release_type=${{ github.event.inputs.release_type }}
fi
echo "release_type=${release_type}" >> $GITHUB_OUTPUT
- # Check whether the released version is listed in CHANGELOG.md
name: Check whether the released version is listed in the changelog
if: steps.get-release-type.outputs.release_type != 'alpha'
run: make check-changelog-entry

- # Check version consistency and increment pre-release version number for prereleases (must be the last step before build)
name: Bump pre-release version
if: steps.get-release-type.outputs.release_type != 'final'
run: python ./scripts/update_version_for_prerelease.py ${{ steps.get-release-type.outputs.release_type }}

- # Build a source distribution and a python3-only wheel
name: Build distribution files
run: make build

- # Check whether the package description will render correctly on PyPI
name: Check package rendering on PyPI
run: make twine-check

- # Publish package to PyPI using their official GitHub action
name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

- # Tag the current commit with the version tag if this is not made from the release event (releases are tagged with the release process)
name: Tag Version
if: github.event_name != 'release'
run: |
git_tag=v`python ./scripts/print_current_package_version.py`
git tag $git_tag
git push origin $git_tag
- # Upload the build artifacts to the release
name: Upload the build artifacts to release
if: github.event_name == 'release'
run: gh release upload ${{ github.ref_name }} dist/*
env:
GH_TOKEN: ${{ github.token }}

28 changes: 28 additions & 0 deletions .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Unit tests

on:
workflow_call:

jobs:
unit_tests:
name: Run unit tests
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
runs-on: ${{ matrix.os }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

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

- name: Install dependencies
run: make install-dev

- name: Run unit tests
run: make unit-tests
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
__pycache__
.mypy_cache
.pytest_cache

.venv
.direnv
.envrc
.python-version

*.egg-info/
*.egg
dist/
build/

.vscode
.DS_Store
7 changes: 7 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[isort]
include_trailing_comma = True
line_length = 150
use_parentheses = True
multi_line_output = 3
sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
known_first_party = flake8_no_pytest_mark_only
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repos:
- repo: local
hooks:
- id: lint
name: Lint codebase
entry: make lint
language: system
pass_filenames: false

- id: type-check
name: Type-check codebase
entry: make type-check
language: system
pass_filenames: false

- id: unit-tests
name: Run unit tests
entry: make unit-tests
language: system
pass_filenames: false

- id: check-changelog
name: Check whether current version is mentioned in changelog
entry: make check-changelog-entry
language: system
pass_filenames: false
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Changelog
=========

[1.0.0](../../releases/tag/v1.0.0) - 2023-06-09
-----------------------------------------------

Initial release of the package.
46 changes: 46 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Development

## Environment

For local development, it is required to have Python 3.8 installed.

It is recommended to set up a virtual environment while developing this package to isolate your development environment,
however, due to the many varied ways Python can be installed and virtual environments can be set up,
this is left up to the developers to do themselves.

One recommended way is with the built-in `venv` module:

```bash
python3 -m venv .venv
source .venv/bin/activate
```

To improve on the experience, you can use [pyenv](https://github.com/pyenv/pyenv) to have an environment with a pinned Python version,
and [direnv](https://github.com/direnv/direnv) to automatically activate/deactivate the environment when you enter/exit the project folder.

## Dependencies

To install this package and its development dependencies, run `make install-dev`

## Formatting

We use `autopep8` and `isort` to automatically format the code to a common format. To run the formatting, just run `make format`.

## Linting, type-checking and unit testing

We use `flake8` for linting, `mypy` for type checking and `pytest` for unit testing. To run these tools, just run `make check-code`.

## Release process

Publishing new versions to [PyPI](https://pypi.org/project/flake8-no-pytest-mark-only) happens automatically through GitHub Actions.

On each commit to the `master` branch, a new beta release is published, taking the version number from `pyproject.toml`
and automatically incrementing the beta version suffix by 1 from the last beta release published to PyPI.

A stable version is published when a new release is created using GitHub Releases, again taking the version number from `pyproject.toml`.
The built package assets are automatically uploaded to the GitHub release.

If there is already a stable version with the same version number as in `pyproject.toml` published to PyPI, the publish process fails,
so don't forget to update the version number before releasing a new version.
The release process also fails when the released version is not described in `CHANGELOG.md`,
so don't forget to describe the changes in the new version there.
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2023 František Nesveda

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.PHONY: clean install-dev build publish twine-check lint unit-tests type-check check-code format check-changelog-entry

clean:
rm -rf build dist .mypy_cache .pytest_cache src/*.egg-info __pycache__

install-dev:
python -m pip install --upgrade pip setuptools
pip install --no-cache-dir -e ".[dev]"
pre-commit install

build:
python -m build

publish:
python -m twine upload dist/*

twine-check:
python -m twine check dist/*

lint:
python3 -m flake8

unit-tests:
python3 -m pytest -ra tests

type-check:
python3 -m mypy

check-code: lint type-check unit-tests

format:
python3 -m isort scripts src tests
python3 -m autopep8 --in-place --recursive scripts src tests

check-changelog-entry:
python3 scripts/check_version_in_changelog.py
Loading

0 comments on commit d86350c

Please sign in to comment.