Skip to content
This repository was archived by the owner on Jun 26, 2022. It is now read-only.
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ build/
dist/
__pycache__/
.vscode/
vendors/
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ repos:
rev: "v4.2.0"
hooks:
- id: check-json
- id: check-toml
- id: check-yaml
- id: trailing-whitespace
- id: end-of-file-fixer
Expand Down Expand Up @@ -42,6 +43,9 @@ repos:
hooks:
- id: flake8
additional_dependencies: [flake8-builtins]
args:
- --ignore=W503,E203
- --max-line-length=88

# Type enforcement for Python
- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
.PHONY: init
init:
pip install --upgrade pip setuptools wheel pip-tools
pip install --upgrade pip flit

.PHONY: install
install:
pip install -r requirements.txt
[ -f "requirements.txt" ] && pip install -r requirements.txt || true
flit install

.PHONY: install-dev
install-dev:
pip install -r requirements-dev.txt
pip install -r requirements.txt
[ -f "requirements.txt" ] && pip install -r requirements.txt || true
[ -f "requirements-dev.txt" ] && pip install -r requirements-dev.txt || true
flit install --symlink
pre-commit install

.PHONY: build-dist
build-dist:
rm -rf ./dist
python setup.py sdist bdist_wheel
flit build

.PHONY: clean-artifacts
clean-artifacts:
Expand Down
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ Straight forward to use!
### Single module projects

- Rename `module_example.py` as desired
- Update `py_modules = module_example` in `setup.cfg` with name
- `[project]` `name` value must match file name
- Update requirements.txt as needed
- *Optional* Use `pyproject.toml` for dependencies and optional-dependencies instead

### Multi file module projects

- All the steps above
- `py_modules = module_example` becomes a multi-line config with each module name

- `[project]` `name` value must match module folder
- *Optional*: Set `[tool.flit.module]` if [project name and module folder differ](https://flit.pypa.io/en/latest/pyproject_toml.html#module-section)

### GitHub Actions

Expand Down Expand Up @@ -92,14 +93,20 @@ call the version of the interpreter used to create the `venv`
Install editable library and development requirements:

```bash
# Update pip and tools
python -m pip install --upgrade pip wheel setuptools
# Update pip and install flit
python -m pip install --upgrade pip flit

# Install development requirements
python -m pip install -r requirements-dev.txt

# Install requirements (if any defined)
python -m pip install -r requirements.txt

# Install package
flit install

# Optional: install editable package (pip install -e)
flit install --symlink
```

Install pre-commit [(see below for details)](#pre-commit):
Expand Down Expand Up @@ -132,6 +139,17 @@ deactivate

---

## Note on flake8:

`flake8` is included in the `requirements-dev.txt` of the project. However it disagrees with `black`, the formatter of choice, on max-line-length and two general linting errors. `.pre-commit-config.yaml` is already configured to ignore these. `flake8` doesn't support `pyproject.toml` so be sure to add the following to the editor of choice as needed.

```ini
--ignore=W503,E203
--max-line-length=88
```

---

## [pre-commit](https://pre-commit.com)

> A framework for managing and maintaining multi-language pre-commit hooks.
Expand All @@ -151,9 +169,9 @@ Makefile.

| PHONY | Description |
| ----------------- | ------------------------------------------------------------------ |
| `init` | Update pip, setuptools, and wheel to newest version |
| `install` | install requirements of project |
| `install-dev` | install development requirements and project |
| `init` | Install/Update pip and flit |
| `install` | install project and requirements |
| `install-dev` | install dev requirements, project as editable, and pre-commit |
| `build-dist` | Build source distribution and wheel distribution |
| `clean-artifacts` | Deletes python/mypy artifacts including eggs, cache, and pyc files |
| `clean-tests` | Deletes tox, coverage, and pytest artifacts |
Expand Down
103 changes: 103 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"

[project]
name = "module_example"
version = "0.0.0"
requires-python = ">=3.8"
description = "Module Description"
readme = "README.md"
license = { file = "LICENSE" }
authors = [
# { email = "[YOUR EMAIL]", name = "[YOUR NAME]" }
]
maintainers = []
keywords = []
classifiers = [
"License :: OSI Approved :: MIT License",
"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 :: Implementation :: CPython"
]
dependencies = []

[project.optional-dependencies]
example = []

[project.urls]
homepage = "https://github.com/[your repo]/[repo name]"
# documentation = ""
# repository = ""
# changelog = ""

[project.scripts]
python-module-example = "module_example:main"

[tool.mypy]
check_untyped_defs = true
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true

[[tool.mypy.overrides]]
module = "tests.*"
disallow_incomplete_defs = false
disallow_untyped_defs = false

[tool.coverage.run]
branch = true
source = [ "tests" ]
source_pkgs = [ "." ]

[tool.coverage.report]
exclude_lines =[
"pragma: no cover",
"def __repr__",
"if self\\.debug",
"raise AssertionError",
"raise NotImplementedError",
"if 0:",
"if __name__ == .__main__.:"
]
ignore_errors = true

[tool.coverage.html]
directory = "coverage_html_report"

[tool.coverage.xml]
output = "coverage.xml"

# This is ignored by flake8, here in case they decide to add it in the future
[tool.flake8]
ignore = "W503,E203"
max-line-length = 88

[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py38,py39,py310,py311,pre-commit
skip_missing_interpreters = true
skipsdist = True

[testenv]
commands =
python -m pip install --upgrade coverage pytest
python -m pip install -r requirements.txt
coverage erase
coverage run -m pytest {posargs:tests}
coverage xml
coverage report -m --fail-under 90 --skip-covered

[testenv:pre-commit]
skip_install = true
deps = pre-commit
commands = pre-commit run --all-files --show-diff-on-failure
"""
61 changes: 0 additions & 61 deletions setup.cfg

This file was deleted.

18 changes: 0 additions & 18 deletions tox.ini

This file was deleted.