From 0005b775990516125a2123c56749bbd6e96bd166 Mon Sep 17 00:00:00 2001 From: Preocts Date: Sun, 12 Jun 2022 22:56:55 -0400 Subject: [PATCH 1/6] Add toml check and args for flake8 --- .pre-commit-config.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2337510..0598859 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -18,7 +19,7 @@ repos: # Adds a standard feel to import segments - repo: https://github.com/asottile/reorder_python_imports - rev: v3.0.1 + rev: v3.1.0 hooks: - id: reorder-python-imports args: [--py3-plus] @@ -42,9 +43,12 @@ 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 - rev: v0.942 + rev: v0.960 hooks: - id: mypy From e025a0498fd4dff3d543cac5b16880fd70277b70 Mon Sep 17 00:00:00 2001 From: Preocts Date: Sun, 12 Jun 2022 22:57:21 -0400 Subject: [PATCH 2/6] Convert to pyproject.toml --- pyproject.toml | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ setup.cfg | 65 ------------------------------- setup.py | 3 -- tox.ini | 17 --------- 4 files changed, 102 insertions(+), 85 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py delete mode 100644 tox.ini diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..89efdc6 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,102 @@ +[build-system] +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" + +[project] +name = "pd_ip_gatherer" +version = "1.0.6" +requires-python = ">=3.8" +description = "Gather PagerDuty webhook IP safelist from their help documents repo" +readme = "README.md" +license = { file = "LICENSE" } +authors = [ + { email = "preocts@preocts.com", name = "Preocts" } +] +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] +pd-ip-gatherer = "pd_ip_gatherer:_console_output" + +[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 + 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 +""" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index efefb48..0000000 --- a/setup.cfg +++ /dev/null @@ -1,65 +0,0 @@ -[metadata] -name = pd_ip_gatherer -version = 1.0.5 -description = Gather PagerDuty webhook IP safelist from their help documents repo -long_description = file: README.md -long_description_content_type = text/markdown -url = https://github.com/Preocts/pagerduty-safelist-gatherer -author = Preocts -author_email = preocts@preocts.com -license = MIT -license_file = LICENSE -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 :: Implementation :: CPython - -[options] -py_modules = pd_ip_gatherer -python_requires = >=3.8 - -[options.entry_points] -console_scripts = - pd-ip-gatherer = pd_ip_gatherer:_console_output - -[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 - -[mypy-tests.*] -disallow_untyped_defs = false - -[coverage:run] -branch = True -source = tests -source_pkgs = . - -[coverage:report] -exclude_lines = - pragma: no cover - def __repr__ - if self\.debug - raise AssertionError - raise NotImplementedError - if 0: - if __name__ == .__main__.: -ignore_errors = True - -[coverage:html] -directory = coverage_html_report - -[coverage:xml] -output = coverage.xml - -[flake8] -ignore = W503,E203 -max-line-length = 88 diff --git a/setup.py b/setup.py deleted file mode 100644 index 6068493..0000000 --- a/setup.py +++ /dev/null @@ -1,3 +0,0 @@ -from setuptools import setup - -setup() diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 681b3a3..0000000 --- a/tox.ini +++ /dev/null @@ -1,17 +0,0 @@ -[tox] -envlist = py38,py39,py310,py311,pre-commit -skip_missing_interpreters = true -skipsdist = True - -[testenv] -commands = - python -m pip install --upgrade coverage pytest - 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 From 7c2d08ddcf3307e5240dece2bff150c22d8d7d4c Mon Sep 17 00:00:00 2001 From: Preocts Date: Sun, 12 Jun 2022 22:57:55 -0400 Subject: [PATCH 3/6] Update phony defs for flit use --- Makefile | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index fff597b..04ace80 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,22 @@ .PHONY: init init: - pip install --upgrade pip setuptools wheel pip-tools + pip install --upgrade pip flit + +.PHONY: install +install: + [ -f "requirements.txt" ] && pip install -r requirements.txt + flit install .PHONY: install-dev install-dev: - pip install --editable . - pip install -r requirements-dev.txt + [ -f "requirements.txt" ] && pip install -r requirements.txt || true + [ -f "requirements-dev.txt" ] && pip install -r requirements-dev.txt + flit install --symlink pre-commit install -.PHONY: install -install: - pip install --upgrade . - .PHONY: build-dist build-dist: - rm -rf ./dist - python setup.py sdist bdist_wheel + flit build .PHONY: clean-artifacts clean-artifacts: From 89b39aa4c3b92de43585b674925d6c7ad16b8071 Mon Sep 17 00:00:00 2001 From: Preocts Date: Sun, 12 Jun 2022 23:00:20 -0400 Subject: [PATCH 4/6] Updates for 1.0.6 --- README.md | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7ea3666..06c49c3 100644 --- a/README.md +++ b/README.md @@ -116,11 +116,17 @@ 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 package +flit install + +# Optional: install editable package (pip install -e) +flit install --symlink ``` Install pre-commit [(see below for details)](#pre-commit): @@ -142,7 +148,7 @@ pre-commit run --all-files Run tests: ```bash -tox +tox [-r] [-e py3x] ``` To deactivate (exit) the `venv`: @@ -153,6 +159,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. @@ -172,9 +189,9 @@ Makefile. | PHONY | Description | | ----------------- | ------------------------------------------------------------------ | -| `init` | Update pip, setuptools, and wheel to newest version | -| `install-dev` | install development requirements and project | -| `install` | install 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 | From fda01fd38b0dda9428fbb34edf816fa427f8d2ca Mon Sep 17 00:00:00 2001 From: Preocts Date: Sun, 12 Jun 2022 23:07:53 -0400 Subject: [PATCH 5/6] Handle Makefile conditions better --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 04ace80..7f4d49c 100644 --- a/Makefile +++ b/Makefile @@ -4,13 +4,13 @@ init: .PHONY: install install: - [ -f "requirements.txt" ] && pip install -r requirements.txt + [ -f "requirements.txt" ] && pip install -r requirements.txt || true flit install .PHONY: install-dev install-dev: [ -f "requirements.txt" ] && pip install -r requirements.txt || true - [ -f "requirements-dev.txt" ] && pip install -r requirements-dev.txt + [ -f "requirements-dev.txt" ] && pip install -r requirements-dev.txt || true flit install --symlink pre-commit install From 188c30bfdd8d745c49e909758e1c4dd6177d180d Mon Sep 17 00:00:00 2001 From: Preocts Date: Sun, 12 Jun 2022 23:13:55 -0400 Subject: [PATCH 6/6] Add project links --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 89efdc6..df91e52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ dependencies = [] example = [] [project.urls] -homepage = "https://github.com/[your repo]/[repo name]" +homepage = "https://github.com/Preocts/pagerduty-safelist-gatherer" # documentation = "" # repository = "" # changelog = ""