diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..2fbe1c78 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,22 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[Makefile] +indent_size = 4 +indent_style = tab + +[*.{py, pyi}] +indent_size = 4 + +[*.md] +trim_trailing_whitespace = false + +[*.{diff,patch}] +trim_trailing_whitespace = false diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..e0739439 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,48 @@ +default_language_version: + python: python3.7 + +default_stages: [commit, push] +fail_fast: true + +repos: + - repo: local + hooks: + - id: format-style + name: format-style + entry: make format-style + language: system + + - repo: local + hooks: + - id: clean + name: clean + entry: make clean + language: system + + - repo: local + hooks: + - id: check-syntax-errors + name: check-syntax-errors + entry: make check-syntax-errors + language: system + + - repo: local + hooks: + - id: check-safety + name: check-safety + entry: make check-safety + language: system + + - repo: local + hooks: + - id: check-style + name: check-style + entry: make check-style + language: system + + - repo: local + hooks: + - id: run-tests + name: run-tests + entry: make run-tests + language: system diff --git a/CHANGELOG.md b/CHANGELOG.md index 614abdbe..23b55f53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,34 @@ # Changelog +### 4.0.0 - [#111](https://github.com/openfisca/country-template/pull/111) + +#### Patch changes + +- Improve `pytest` support for `doctest` +- Use `pip check` for dependency conflicts +- Add `pyupgrade` for automatic code formatting +- Add `darglint` for improved docstring linting +- Add `.editorconfig` for shared editor configuration +- Add `pre-commit` for automatic style checks & formatting + - Git hooks are optional, as they may not suit everybody + - To enable them, run `pre-commit install` +- Add long description to package distribution +- Update distribution keywords + +#### Minor changes + +- Relax upper-bound support for OpenFisca-Core + - This package and OpenFisca-Core are mutually dependent, which breaks `pip` + - The least astonishing is to assume this package to always be compatible with core + - This is also easily enforceable thanks to regular dependabot checks that will run in CircleCI + - Finally, it is the responsibility of the OpenFisca-Core integrity checks workflow to ensure this package to always be compatible + - Every new version of core has to ensure all of the tests included in and distributed by this package pass + - Also, every breaking change to OpenFisca-Core has to be phased out to help adapting this package to those changes + +#### Major changes + +- Drop support for Python < 3.7 + ### 3.12.8 - [#105](https://github.com/openfisca/country-template/pull/105) * Minor change. diff --git a/Makefile b/Makefile index 659fdb55..645cf13f 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,9 @@ all: test +test: clean check-syntax-errors check-safety check-style run-tests uninstall: pip freeze | grep -v "^-e" | xargs pip uninstall -y -clean: - rm -rf build dist - find . -name '*.pyc' -exec rm \{\} \; - deps: pip install --upgrade pip twine wheel @@ -23,21 +20,29 @@ build: clean deps python setup.py bdist_wheel find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \; -check-syntax-errors: - python -m compileall -q . - format-style: @# Do not analyse .gitignored files. @# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764. + pyupgrade --py37-plus `git ls-files | grep "\.py$$"` autopep8 `git ls-files | grep "\.py$$"` +clean: + rm -rf build dist + find . -name '*.pyc' -exec rm \{\} \; + +check-syntax-errors: + python -m compileall -q . + +check-safety: + pip check + check-style: @# Do not analyse .gitignored files. @# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764. - flake8 `git ls-files | grep "\.py$$"` pylint `git ls-files | grep "\.py$$"` + flake8 `git ls-files | grep "\.py$$"` -test: clean check-syntax-errors check-style +run-tests: openfisca test --country-package openfisca_country_template openfisca_country_template/tests serve-local: build diff --git a/openfisca_country_template/situation_examples/__init__.py b/openfisca_country_template/situation_examples/__init__.py index 788e5b9c..eaf4417a 100644 --- a/openfisca_country_template/situation_examples/__init__.py +++ b/openfisca_country_template/situation_examples/__init__.py @@ -10,7 +10,7 @@ def parse(file_name): """Load json example situations.""" file_path = os.path.join(DIR_PATH, file_name) - with open(file_path, "r") as file: + with open(file_path) as file: return json.loads(file.read()) diff --git a/setup.cfg b/setup.cfg index 67e8d6e3..5ee8c5c9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,15 +7,17 @@ ; W503/4: We break lines before binary operators (Knuth's style) [flake8] +application-import-names = openfisca_country_template +application-package-names = openfisca_country_template,openfisca_extension_template +docstring_style = google hang-closing = true ignore = D101,D107,D401,E128,E251,E501,W503 +import-order-style = appnexus in-place = true inline-quotes = " multiline-quotes = """ -import-order-style = appnexus no-accept-encodings = true -application-import-names = openfisca_country_template -application-package-names = openfisca_country_template,openfisca_extension_template +strictness = long ; C0103: We (still) snake case variables and reforms ; C0115: Variables already provide label/description @@ -31,7 +33,8 @@ disable = C0103,C0115,C0301,E0213,E1101,E1102,W0621,W1203 score = no [tool:pytest] -addopts = --showlocals --exitfirst --doctest-modules -testpaths = openfisca_country_template/tests -python_files = **/*.py +addopts = --doctest-modules --exitfirst --showlocals --strict-markers +doctest_optionflags = NUMBER NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL filterwarnings = ignore::DeprecationWarning +python_files = **/*.py +testpaths = openfisca_country_template diff --git a/setup.py b/setup.py index 72c66aeb..37baff95 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,16 @@ """This file contains your country package's metadata and dependencies.""" -from setuptools import find_packages, setup +import setuptools -setup( +with open("README.md") as file: + readme = file.read() + +with open("CHANGELOG.md") as file: + changelog = file.read() + +setuptools.setup( name = "OpenFisca-Country-Template", - version = "3.12.8", + version = "4.0.0", author = "OpenFisca Team", author_email = "contact@openfisca.org", classifiers = [ @@ -12,13 +18,15 @@ "License :: OSI Approved :: GNU Affero General Public License v3", "Operating System :: POSIX", "Programming Language :: Python", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", "Topic :: Scientific/Engineering :: Information Analysis", ], description = "OpenFisca tax and benefit system for Country-Template", - keywords = "benefit microsimulation social tax", + long_description = "\n".join((readme, changelog)), + long_description_content_type="text/markdown", + keywords = "microsimulation tax and benefit system rules as code", license = "http://www.fsf.org/licensing/licenses/agpl-3.0.html", url = "https://github.com/openfisca/country-template", include_package_data = True, # Will read MANIFEST.in @@ -28,12 +36,14 @@ ["CHANGELOG.md", "LICENSE", "README.md"], ), ], + python_requires = ">= 3.7", install_requires = [ - "OpenFisca-Core[web-api] >= 35.0.0, < 36.0.0", + "OpenFisca-Core[web-api] >= 35.0.0", ], extras_require = { "dev": [ "autopep8 >= 1.5.4, < 2.0.0", + "darglint == 1.8.0", "flake8 >= 3.8.0, < 4.0.0", "flake8-bugbear >= 20.1.0, < 22.0.0", "flake8-builtins >= 1.5.0, < 2.0.0", @@ -46,9 +56,11 @@ "flake8-quotes >= 3.2.0, < 4.0.0", "flake8-simplify >= 0.9.0, < 1.0.0", "flake8-use-fstring >= 1.1.0, < 2.0.0", + "pre-commit == 2.12.1", "pylint >= 2.6.0, < 3.0.0", "pycodestyle >= 2.6.0, < 3.0.0", + "pyupgrade == 2.14.0", ], }, - packages = find_packages(), + packages = setuptools.find_packages(), )