Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve packaging #111

Closed
wants to merge 11 commits into from
Closed
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
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 14 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion openfisca_country_template/situation_examples/__init__.py
Original file line number Diff line number Diff line change
@@ -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())


15 changes: 9 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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
26 changes: 19 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
"""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 = [
"Development Status :: 5 - Production/Stable",
"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(),
)