From e24d3fa42bfd7cc913e92992f2cff5d57ee841b5 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 27 Sep 2021 15:26:53 +0200 Subject: [PATCH 001/205] Reorganise make tasks --- Makefile | 128 ++++------------------------------- openfisca_tasks/install.mk | 17 +++++ openfisca_tasks/lint.mk | 22 ++++++ openfisca_tasks/publish.mk | 7 ++ openfisca_tasks/serve.mk | 6 ++ openfisca_tasks/test_code.mk | 21 ++++++ openfisca_tasks/test_doc.mk | 58 ++++++++++++++++ 7 files changed, 143 insertions(+), 116 deletions(-) create mode 100644 openfisca_tasks/install.mk create mode 100644 openfisca_tasks/lint.mk create mode 100644 openfisca_tasks/publish.mk create mode 100644 openfisca_tasks/serve.mk create mode 100644 openfisca_tasks/test_code.mk create mode 100644 openfisca_tasks/test_doc.mk diff --git a/Makefile b/Makefile index c139b6aac0..89d34c2056 100644 --- a/Makefile +++ b/Makefile @@ -1,120 +1,16 @@ -help = sed -n "/^$1/ { x ; p ; } ; s/\#\#/[⚙]/ ; s/\./.../ ; x" ${MAKEFILE_LIST} -repo = https://github.com/openfisca/openfisca-doc -branch = $(shell git branch --show-current) +include openfisca_tasks/install.mk +include openfisca_tasks/lint.mk +include openfisca_tasks/publish.mk +include openfisca_tasks/serve.mk +include openfisca_tasks/test_code.mk +include openfisca_tasks/test_doc.mk -## Same as `make test`. -all: test - -## Install project dependencies. -install: - @$(call help,$@:) - @pip install --upgrade pip twine wheel - @pip install --editable .[dev] --upgrade --use-deprecated=legacy-resolver - -## Install openfisca-core for deployment and publishing. -build: setup.py - @## This allows us to be sure tests are run against the packaged version - @## of openfisca-core, the same we put in the hands of users and reusers. - @$(call help,$@:) - @python $? bdist_wheel - @find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \; - -## Uninstall project dependencies. -uninstall: - @$(call help,$@:) - @pip freeze | grep -v "^-e" | sed "s/@.*//" | xargs pip uninstall -y - -## Delete builds and compiled python files. -clean: \ - $(shell ls -d * | grep "build\|dist") \ - $(shell find . -name "*.pyc") - @$(call help,$@:) - @rm -rf $? - -## Compile python files to check for syntax errors. -check-syntax-errors: . - @$(call help,$@:) - @python -m compileall -q $? - -## Run linters to check for syntax and style errors. -check-style: $(shell git ls-files "*.py") - @$(call help,$@:) - @flake8 $? +print_help = sed -n "/^$1/ { x ; p ; } ; s/\#\#/[⚙]/ ; s/\./.../ ; x" ${MAKEFILE_LIST} -## Run code formatters to correct style errors. -format-style: $(shell git ls-files "*.py") - @$(call help,$@:) - @autopep8 $? +.DEFAULT_GOAL := all -## Run static type checkers for type errors. -check-types: openfisca_core openfisca_web_api - @$(call help,$@:) - @mypy $? - -## Run openfisca-core tests. -test: clean check-syntax-errors check-style check-types - @$(call help,$@:) - @env PYTEST_ADDOPTS="${PYTEST_ADDOPTS} --cov=openfisca_core" pytest - -## Check that the current changes do not break the doc. -test-doc: - @## Usage: - @## - @## make test-doc [branch=BRANCH] - @## - @## Examples: - @## - @## # Will check the current branch in openfisca-doc. - @## make test-doc - @## - @## # Will check "test-doc" in openfisca-doc. - @## make test-doc branch=test-doc - @## - @## # Will check "master" if "asdf1234" does not exist. - @## make test-doc branch=asdf1234 - @## - @$(call help,$@:) - @${MAKE} test-doc-checkout - @${MAKE} test-doc-install - @${MAKE} test-doc-build - -## Update the local copy of the doc. -test-doc-checkout: - @$(call help,$@:) - @[ ! -d doc ] && git clone ${repo} doc || : - @cd doc && { \ - git reset --hard ; \ - git fetch --all ; \ - [ $$(git branch --show-current) != master ] && git checkout master || : ; \ - [ ${branch} != "master" ] \ - && { \ - { \ - git branch -D ${branch} 2> /dev/null ; \ - git checkout ${branch} ; \ - } \ - && git pull --ff-only origin ${branch} \ - || { \ - >&2 echo "[!] The branch '${branch}' doesn't exist, checking out 'master' instead..." ; \ - git pull --ff-only origin master ; \ - } \ - } \ - || git pull --ff-only origin master ; \ - } 1> /dev/null - -## Install doc dependencies. -test-doc-install: - @$(call help,$@:) - @pip install --requirement doc/requirements.txt 1> /dev/null - @pip install --editable .[dev] --upgrade 1> /dev/null - -## Dry-build the doc. -test-doc-build: - @$(call help,$@:) - @sphinx-build -M dummy doc/source doc/build -n -q -W +## Same as `make test`. +all: test -## Serve the openfisca Web API. -api: - @$(call help,$@:) - @openfisca serve \ - --country-package openfisca_country_template \ - --extensions openfisca_extension_template +## Run all lints and tests. +test: clean lint test-code diff --git a/openfisca_tasks/install.mk b/openfisca_tasks/install.mk new file mode 100644 index 0000000000..a51629899d --- /dev/null +++ b/openfisca_tasks/install.mk @@ -0,0 +1,17 @@ +## Install project dependencies. +install: + @$(call help,$@:) + @pip install --upgrade pip twine wheel + @pip install --editable .[dev] --upgrade --use-deprecated=legacy-resolver + +## Uninstall project dependencies. +uninstall: + @$(call help,$@:) + @pip freeze | grep -v "^-e" | sed "s/@.*//" | xargs pip uninstall -y + +## Delete builds and compiled python files. +clean: \ + $(shell ls -d * | grep "build\|dist") \ + $(shell find . -name "*.pyc") + @$(call help,$@:) + @rm -rf $? diff --git a/openfisca_tasks/lint.mk b/openfisca_tasks/lint.mk new file mode 100644 index 0000000000..403b4dc7a7 --- /dev/null +++ b/openfisca_tasks/lint.mk @@ -0,0 +1,22 @@ +## Lint the codebase. +lint: check-syntax-errors check-style check-types + +## Compile python files to check for syntax errors. +check-syntax-errors: . + @$(call help,$@:) + @python -m compileall -q $? + +## Run linters to check for syntax and style errors. +check-style: $(shell git ls-files "*.py") + @$(call help,$@:) + @flake8 $? + +## Run static type checkers for type errors. +check-types: openfisca_core openfisca_web_api + @$(call help,$@:) + @mypy $? + +## Run code formatters to correct style errors. +format-style: $(shell git ls-files "*.py") + @$(call help,$@:) + @autopep8 $? diff --git a/openfisca_tasks/publish.mk b/openfisca_tasks/publish.mk new file mode 100644 index 0000000000..b1b3cf57f6 --- /dev/null +++ b/openfisca_tasks/publish.mk @@ -0,0 +1,7 @@ +## Install openfisca-core for deployment and publishing. +build: setup.py + @## This allows us to be sure tests are run against the packaged version + @## of openfisca-core, the same we put in the hands of users and reusers. + @$(call help,$@:) + @python $? bdist_wheel + @find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \; diff --git a/openfisca_tasks/serve.mk b/openfisca_tasks/serve.mk new file mode 100644 index 0000000000..e115a75e6e --- /dev/null +++ b/openfisca_tasks/serve.mk @@ -0,0 +1,6 @@ +## Serve the openfisca Web API. +api: + @$(call help,$@:) + @openfisca serve \ + --country-package openfisca_country_template \ + --extensions openfisca_extension_template diff --git a/openfisca_tasks/test_code.mk b/openfisca_tasks/test_code.mk new file mode 100644 index 0000000000..c8018c7cd6 --- /dev/null +++ b/openfisca_tasks/test_code.mk @@ -0,0 +1,21 @@ +python_packages = $(shell python -c "import sysconfig; print(sysconfig.get_paths()[\"purelib\"])") + +## Run openfisca-core. +test-code: test-core + @## Usage: + @## + @## make test [pytest_args="--ARG"] [openfisca_args="--ARG"] + @## + @## Examples: + @## + @## make test + @## make test pytest_args="--exitfirst" + @## make test openfisca_args="--performance" + @## make test pytest_args="--exitfirst" openfisca_args="--performance" + +## Run openfisca-core tests. +test-core: $(shell git ls-files "tests/*.py") + @$(call help,$@:) + @PYTEST_ADDOPTS="${PYTEST_ADDOPTS} --cov=openfisca_core ${pytest_args}" \ + openfisca test $? \ + ${openfisca_args} diff --git a/openfisca_tasks/test_doc.mk b/openfisca_tasks/test_doc.mk new file mode 100644 index 0000000000..cfd2074f8c --- /dev/null +++ b/openfisca_tasks/test_doc.mk @@ -0,0 +1,58 @@ +repo = https://github.com/openfisca/openfisca-doc +branch = $(shell git branch --show-current) + +## Check that the current changes do not break the doc. +test-doc: + @## Usage: + @## + @## make test-doc [branch=BRANCH] + @## + @## Examples: + @## + @## # Will check the current branch in openfisca-doc. + @## make test-doc + @## + @## # Will check "test-doc" in openfisca-doc. + @## make test-doc branch=test-doc + @## + @## # Will check "master" if "asdf1234" does not exist. + @## make test-doc branch=asdf1234 + @## + @$(call help,$@:) + @${MAKE} test-doc-checkout + @${MAKE} test-doc-install + @${MAKE} test-doc-build + +## Update the local copy of the doc. +test-doc-checkout: + @$(call help,$@:) + @[ ! -d doc ] && git clone ${repo} doc || : + @cd doc && { \ + git reset --hard ; \ + git fetch --all ; \ + [ "$$(git branch --show-current)" != "master" ] && git checkout master || : ; \ + [ "${branch}" != "master" ] \ + && { \ + { \ + git branch -D ${branch} 2> /dev/null ; \ + git checkout ${branch} ; \ + } \ + && git pull --ff-only origin ${branch} \ + || { \ + >&2 echo "[!] The branch '${branch}' doesn't exist, checking out 'master' instead..." ; \ + git pull --ff-only origin master ; \ + } \ + } \ + || git pull --ff-only origin master ; \ + } 1> /dev/null + +## Install doc dependencies. +test-doc-install: + @$(call help,$@:) + @pip install --requirement doc/requirements.txt 1> /dev/null + @pip install --editable .[dev] --upgrade 1> /dev/null + +## Dry-build the doc. +test-doc-build: + @$(call help,$@:) + @sphinx-build -M dummy doc/source doc/build -n -q -W From f77d0210f6c52b8a7c3a1a29a7a9153bfeeccc89 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 27 Sep 2021 15:28:39 +0200 Subject: [PATCH 002/205] Fix failing tests --- openfisca_core/tools/test_runner.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openfisca_core/tools/test_runner.py b/openfisca_core/tools/test_runner.py index 1e01bc0fca..1c37ea1469 100644 --- a/openfisca_core/tools/test_runner.py +++ b/openfisca_core/tools/test_runner.py @@ -64,17 +64,17 @@ def run_tests(tax_benefit_system, paths, options = None): """ - argv = ["--capture", "no"] + argv = [] if options.get('pdb'): argv.append('--pdb') + if options.get('verbose'): + argv.append('--verbose') + if isinstance(paths, str): paths = [paths] - if options is None: - options = {} - return pytest.main([*argv, *paths] if True else paths, plugins = [OpenFiscaPlugin(tax_benefit_system, options)]) From a7b7a58e028009ef7b4cee51a027249ecb5b8aa8 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 27 Sep 2021 15:31:49 +0200 Subject: [PATCH 003/205] Adapt circleci --- .circleci/config.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c9f90c832b..9bab60db65 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,6 +21,7 @@ jobs: name: Install dependencies command: | make install + make clean # pip install --editable git+https://github.com/openfisca/country-template.git@BRANCH_NAME#egg=OpenFisca-Country-Template # use a specific branch of OpenFisca-Country-Template # pip install --editable git+https://github.com/openfisca/extension-template.git@BRANCH_NAME#egg=OpenFisca-Extension-Template # use a specific branch of OpenFisca-Extension-Template @@ -30,8 +31,12 @@ jobs: - /tmp/venv/openfisca_core - run: - name: Run Core tests - command: env PYTEST_ADDOPTS="--exitfirst" make test + name: Run linters + command: make lint + + - run: + name: Run openfisca-core tests + command: make test-core pytest_args="--exitfirst" - run: name: Check NumPy typing against latest 3 minor versions From 93c76dbb42fcf58da4e621b2a71801fd00e54f23 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 27 Sep 2021 15:41:02 +0200 Subject: [PATCH 004/205] Document print messages --- Makefile | 19 ++++++++++++++++++- openfisca_tasks/install.mk | 6 +++--- openfisca_tasks/lint.mk | 8 ++++---- openfisca_tasks/publish.mk | 2 +- openfisca_tasks/serve.mk | 2 +- openfisca_tasks/test_code.mk | 2 +- openfisca_tasks/test_doc.mk | 8 ++++---- 7 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 89d34c2056..3ed080823d 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,25 @@ include openfisca_tasks/serve.mk include openfisca_tasks/test_code.mk include openfisca_tasks/test_doc.mk -print_help = sed -n "/^$1/ { x ; p ; } ; s/\#\#/[⚙]/ ; s/\./.../ ; x" ${MAKEFILE_LIST} +## To share info with the user, but no action is needed. +print_info = $$(tput setaf 6)[i]$$(tput sgr0) +## To warn the user of something, but no action is needed. +print_warn = $$(tput setaf 3)[!]$$(tput sgr0) + +## To let the user know where we are in the task pipeline. +print_work = $$(tput setaf 5)[⚙]$$(tput sgr0) + +## To let the user know the task in progress succeded. +## The `$1` is a function argument, passed from a task (usually the task name). +print_pass = echo $$(tput setaf 2)[✓]$$(tput sgr0) $$(tput setaf 8)$1$$(tput sgr0)$$(tput setaf 2)passed$$(tput sgr0) $$(tput setaf 1)❤$$(tput sgr0) + +## Similar to `print_work`, but this will read the comments above a task, and +## print them to the user at the start of each task. The `$1` is a function +## argument. +print_help = sed -n "/^$1/ { x ; p ; } ; s/\#\#/[⚙]/ ; s/\./…/ ; x" ${MAKEFILE_LIST} + +## Same as `make`. .DEFAULT_GOAL := all ## Same as `make test`. diff --git a/openfisca_tasks/install.mk b/openfisca_tasks/install.mk index a51629899d..f37d17f26f 100644 --- a/openfisca_tasks/install.mk +++ b/openfisca_tasks/install.mk @@ -1,17 +1,17 @@ ## Install project dependencies. install: - @$(call help,$@:) + @$(call print_help,$@:) @pip install --upgrade pip twine wheel @pip install --editable .[dev] --upgrade --use-deprecated=legacy-resolver ## Uninstall project dependencies. uninstall: - @$(call help,$@:) + @$(call print_help,$@:) @pip freeze | grep -v "^-e" | sed "s/@.*//" | xargs pip uninstall -y ## Delete builds and compiled python files. clean: \ $(shell ls -d * | grep "build\|dist") \ $(shell find . -name "*.pyc") - @$(call help,$@:) + @$(call print_help,$@:) @rm -rf $? diff --git a/openfisca_tasks/lint.mk b/openfisca_tasks/lint.mk index 403b4dc7a7..3c466136b5 100644 --- a/openfisca_tasks/lint.mk +++ b/openfisca_tasks/lint.mk @@ -3,20 +3,20 @@ lint: check-syntax-errors check-style check-types ## Compile python files to check for syntax errors. check-syntax-errors: . - @$(call help,$@:) + @$(call print_help,$@:) @python -m compileall -q $? ## Run linters to check for syntax and style errors. check-style: $(shell git ls-files "*.py") - @$(call help,$@:) + @$(call print_help,$@:) @flake8 $? ## Run static type checkers for type errors. check-types: openfisca_core openfisca_web_api - @$(call help,$@:) + @$(call print_help,$@:) @mypy $? ## Run code formatters to correct style errors. format-style: $(shell git ls-files "*.py") - @$(call help,$@:) + @$(call print_help,$@:) @autopep8 $? diff --git a/openfisca_tasks/publish.mk b/openfisca_tasks/publish.mk index b1b3cf57f6..2f34599fd9 100644 --- a/openfisca_tasks/publish.mk +++ b/openfisca_tasks/publish.mk @@ -2,6 +2,6 @@ build: setup.py @## This allows us to be sure tests are run against the packaged version @## of openfisca-core, the same we put in the hands of users and reusers. - @$(call help,$@:) + @$(call print_help,$@:) @python $? bdist_wheel @find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \; diff --git a/openfisca_tasks/serve.mk b/openfisca_tasks/serve.mk index e115a75e6e..efad0be6cb 100644 --- a/openfisca_tasks/serve.mk +++ b/openfisca_tasks/serve.mk @@ -1,6 +1,6 @@ ## Serve the openfisca Web API. api: - @$(call help,$@:) + @$(call print_help,$@:) @openfisca serve \ --country-package openfisca_country_template \ --extensions openfisca_extension_template diff --git a/openfisca_tasks/test_code.mk b/openfisca_tasks/test_code.mk index c8018c7cd6..f83f7f6747 100644 --- a/openfisca_tasks/test_code.mk +++ b/openfisca_tasks/test_code.mk @@ -15,7 +15,7 @@ test-code: test-core ## Run openfisca-core tests. test-core: $(shell git ls-files "tests/*.py") - @$(call help,$@:) + @$(call print_help,$@:) @PYTEST_ADDOPTS="${PYTEST_ADDOPTS} --cov=openfisca_core ${pytest_args}" \ openfisca test $? \ ${openfisca_args} diff --git a/openfisca_tasks/test_doc.mk b/openfisca_tasks/test_doc.mk index cfd2074f8c..24c8ecec70 100644 --- a/openfisca_tasks/test_doc.mk +++ b/openfisca_tasks/test_doc.mk @@ -18,14 +18,14 @@ test-doc: @## # Will check "master" if "asdf1234" does not exist. @## make test-doc branch=asdf1234 @## - @$(call help,$@:) + @$(call print_help,$@:) @${MAKE} test-doc-checkout @${MAKE} test-doc-install @${MAKE} test-doc-build ## Update the local copy of the doc. test-doc-checkout: - @$(call help,$@:) + @$(call print_help,$@:) @[ ! -d doc ] && git clone ${repo} doc || : @cd doc && { \ git reset --hard ; \ @@ -48,11 +48,11 @@ test-doc-checkout: ## Install doc dependencies. test-doc-install: - @$(call help,$@:) + @$(call print_help,$@:) @pip install --requirement doc/requirements.txt 1> /dev/null @pip install --editable .[dev] --upgrade 1> /dev/null ## Dry-build the doc. test-doc-build: - @$(call help,$@:) + @$(call print_help,$@:) @sphinx-build -M dummy doc/source doc/build -n -q -W From 566ce7aa64a347c7f8b1f96838a1aff4408112db Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 27 Sep 2021 15:49:34 +0200 Subject: [PATCH 005/205] Add OK message to tests/lints --- Makefile | 2 ++ openfisca_tasks/lint.mk | 5 +++++ openfisca_tasks/test_code.mk | 4 ++-- openfisca_tasks/test_doc.mk | 4 ++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3ed080823d..87b0502815 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,8 @@ print_help = sed -n "/^$1/ { x ; p ; } ; s/\#\#/[⚙]/ ; s/\./…/ ; x" ${MAKEFI ## Same as `make test`. all: test + @$(call print_pass,$@:) ## Run all lints and tests. test: clean lint test-code + @$(call print_pass,$@:) diff --git a/openfisca_tasks/lint.mk b/openfisca_tasks/lint.mk index 3c466136b5..8be8dd71ce 100644 --- a/openfisca_tasks/lint.mk +++ b/openfisca_tasks/lint.mk @@ -1,22 +1,27 @@ ## Lint the codebase. lint: check-syntax-errors check-style check-types + @$(call print_pass,$@:) ## Compile python files to check for syntax errors. check-syntax-errors: . @$(call print_help,$@:) @python -m compileall -q $? + @$(call print_pass,$@:) ## Run linters to check for syntax and style errors. check-style: $(shell git ls-files "*.py") @$(call print_help,$@:) @flake8 $? + @$(call print_pass,$@:) ## Run static type checkers for type errors. check-types: openfisca_core openfisca_web_api @$(call print_help,$@:) @mypy $? + @$(call print_pass,$@:) ## Run code formatters to correct style errors. format-style: $(shell git ls-files "*.py") @$(call print_help,$@:) @autopep8 $? + @$(call print_pass,$@:) diff --git a/openfisca_tasks/test_code.mk b/openfisca_tasks/test_code.mk index f83f7f6747..878983049d 100644 --- a/openfisca_tasks/test_code.mk +++ b/openfisca_tasks/test_code.mk @@ -1,5 +1,3 @@ -python_packages = $(shell python -c "import sysconfig; print(sysconfig.get_paths()[\"purelib\"])") - ## Run openfisca-core. test-code: test-core @## Usage: @@ -12,6 +10,7 @@ test-code: test-core @## make test pytest_args="--exitfirst" @## make test openfisca_args="--performance" @## make test pytest_args="--exitfirst" openfisca_args="--performance" + @$(call print_pass,$@:) ## Run openfisca-core tests. test-core: $(shell git ls-files "tests/*.py") @@ -19,3 +18,4 @@ test-core: $(shell git ls-files "tests/*.py") @PYTEST_ADDOPTS="${PYTEST_ADDOPTS} --cov=openfisca_core ${pytest_args}" \ openfisca test $? \ ${openfisca_args} + @$(call print_pass,$@:) diff --git a/openfisca_tasks/test_doc.mk b/openfisca_tasks/test_doc.mk index 24c8ecec70..e7755c6f5b 100644 --- a/openfisca_tasks/test_doc.mk +++ b/openfisca_tasks/test_doc.mk @@ -1,4 +1,7 @@ +## The repository of the documentation. repo = https://github.com/openfisca/openfisca-doc + +## The current working branch. branch = $(shell git branch --show-current) ## Check that the current changes do not break the doc. @@ -22,6 +25,7 @@ test-doc: @${MAKE} test-doc-checkout @${MAKE} test-doc-install @${MAKE} test-doc-build + @$(call print_pass,$@:) ## Update the local copy of the doc. test-doc-checkout: From c9b03633137ad855286362597ea17f2abda3c810 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 27 Sep 2021 15:53:21 +0200 Subject: [PATCH 006/205] Add messages to test-doc --- openfisca_tasks/test_doc.mk | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/openfisca_tasks/test_doc.mk b/openfisca_tasks/test_doc.mk index e7755c6f5b..fb7249c99e 100644 --- a/openfisca_tasks/test_doc.mk +++ b/openfisca_tasks/test_doc.mk @@ -38,12 +38,25 @@ test-doc-checkout: [ "${branch}" != "master" ] \ && { \ { \ + >&2 echo "$(print_info) Trying to checkout the branch 'openfisca-doc/${branch}'..." ; \ git branch -D ${branch} 2> /dev/null ; \ - git checkout ${branch} ; \ + git checkout ${branch} 2> /dev/null ; \ } \ && git pull --ff-only origin ${branch} \ || { \ - >&2 echo "[!] The branch '${branch}' doesn't exist, checking out 'master' instead..." ; \ + >&2 echo "$(print_warn) The branch 'openfisca-doc/${branch}' was not found, falling back to 'openfisca-doc/master'..." ; \ + >&2 echo "" ; \ + >&2 echo "$(print_info) This is perfectly normal, one of two things can ensue:" ; \ + >&2 echo "$(print_info)" ; \ + >&2 echo "$(print_info) $$(tput setaf 2)[If tests pass]$$(tput sgr0)" ; \ + >&2 echo "$(print_info) * No further action required on your side..." ; \ + >&2 echo "$(print_info)" ; \ + >&2 echo "$(print_info) $$(tput setaf 1)[If tests fail]$$(tput sgr0)" ; \ + >&2 echo "$(print_info) * Create the branch '${branch}' in 'openfisca-doc'... " ; \ + >&2 echo "$(print_info) * Push your fixes..." ; \ + >&2 echo "$(print_info) * Run 'make test-doc' again..." ; \ + >&2 echo "" ; \ + >&2 echo "$(print_work) Checking out 'openfisca-doc/master'..." ; \ git pull --ff-only origin master ; \ } \ } \ From 7dc0a3be9f671a9eac79617a37c679f6701cf3fa Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 27 Sep 2021 15:55:31 +0200 Subject: [PATCH 007/205] Colorize print_help output --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 87b0502815..2691268681 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ print_pass = echo $$(tput setaf 2)[✓]$$(tput sgr0) $$(tput setaf 8)$1$$(tput s ## Similar to `print_work`, but this will read the comments above a task, and ## print them to the user at the start of each task. The `$1` is a function ## argument. -print_help = sed -n "/^$1/ { x ; p ; } ; s/\#\#/[⚙]/ ; s/\./…/ ; x" ${MAKEFILE_LIST} +print_help = sed -n "/^$1/ { x ; p ; } ; s/\#\#/$(print_work)/ ; s/\./…/ ; x" ${MAKEFILE_LIST} ## Same as `make`. .DEFAULT_GOAL := all From af8350b5baf68c9b4f290e21c90fcfa09ee5b7ef Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 27 Sep 2021 15:57:11 +0200 Subject: [PATCH 008/205] Add colorize config to circleci --- .circleci/config.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9bab60db65..ea7148b39b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,6 +3,8 @@ jobs: run_tests: docker: - image: python:3.7 + environment: + TERM: xterm-256color # To colorize output of make tasks. steps: - checkout @@ -56,6 +58,8 @@ jobs: test_docs: docker: - image: python:3.7 + environment: + TERM: xterm-256color # To colorize output of make tasks. steps: - checkout From 6c61469230e0314fdfce23b64f00464b421a8739 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 27 Sep 2021 16:04:50 +0200 Subject: [PATCH 009/205] Bump patch to 35.5.1 --- CHANGELOG.md | 7 +++++++ setup.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bed8ae1d5..ec66f40e3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### 35.5.1 [#1046](https://github.com/openfisca/openfisca-core/pull/1046) + +#### Non-technical changes + +- Reorganise `Makefile` into context files (install, test, publish…) +- Colorise `make` tasks and improve messages printed to the user + ## 35.5.0 [#1038](https://github.com/openfisca/openfisca-core/pull/1038) #### New Features diff --git a/setup.py b/setup.py index 88e2772a2c..396435263d 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ setup( name = 'OpenFisca-Core', - version = '35.5.0', + version = '35.5.1', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From 9219b06d24ec53aef3c7f5e1a4d48946d0c6a99b Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 20 Sep 2021 00:20:50 +0200 Subject: [PATCH 010/205] Fix yaml tests bug --- tests/core/test_yaml.py | 5 ++--- tests/fixtures/yaml_tests/__init__.py | 0 .../yaml_tests/directory/subdirectory/test_4.yaml | 0 tests/{core => fixtures}/yaml_tests/directory/test_1.yaml | 0 tests/{core => fixtures}/yaml_tests/directory/test_2.yaml | 0 .../yaml_tests/failing_test_absolute_error_margin.yaml | 0 .../yaml_tests/failing_test_relative_error_margin.yaml | 0 .../yaml_tests/test_absolute_error_margin.yaml | 0 tests/{core => fixtures}/yaml_tests/test_failure.yaml | 0 tests/{core => fixtures}/yaml_tests/test_name_filter.yaml | 0 .../yaml_tests/test_relative_error_margin.yaml | 0 tests/{core => fixtures}/yaml_tests/test_success.yml | 0 tests/{core => fixtures}/yaml_tests/test_with_anchors.yaml | 0 tests/{core => fixtures}/yaml_tests/test_with_extension.yaml | 0 tests/{core => fixtures}/yaml_tests/test_with_reform.yaml | 0 tests/{core => fixtures}/yaml_tests/test_with_reform_2.yaml | 0 16 files changed, 2 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/yaml_tests/__init__.py rename tests/{core => fixtures}/yaml_tests/directory/subdirectory/test_4.yaml (100%) rename tests/{core => fixtures}/yaml_tests/directory/test_1.yaml (100%) rename tests/{core => fixtures}/yaml_tests/directory/test_2.yaml (100%) rename tests/{core => fixtures}/yaml_tests/failing_test_absolute_error_margin.yaml (100%) rename tests/{core => fixtures}/yaml_tests/failing_test_relative_error_margin.yaml (100%) rename tests/{core => fixtures}/yaml_tests/test_absolute_error_margin.yaml (100%) rename tests/{core => fixtures}/yaml_tests/test_failure.yaml (100%) rename tests/{core => fixtures}/yaml_tests/test_name_filter.yaml (100%) rename tests/{core => fixtures}/yaml_tests/test_relative_error_margin.yaml (100%) rename tests/{core => fixtures}/yaml_tests/test_success.yml (100%) rename tests/{core => fixtures}/yaml_tests/test_with_anchors.yaml (100%) rename tests/{core => fixtures}/yaml_tests/test_with_extension.yaml (100%) rename tests/{core => fixtures}/yaml_tests/test_with_reform.yaml (100%) rename tests/{core => fixtures}/yaml_tests/test_with_reform_2.yaml (100%) diff --git a/tests/core/test_yaml.py b/tests/core/test_yaml.py index 15085dbbf3..f63e37ff39 100644 --- a/tests/core/test_yaml.py +++ b/tests/core/test_yaml.py @@ -1,4 +1,3 @@ -import pkg_resources import os import subprocess @@ -7,9 +6,9 @@ from openfisca_core.tools.test_runner import run_tests +from tests.fixtures import yaml_tests -openfisca_core_dir = pkg_resources.get_distribution('OpenFisca-Core').location -yaml_tests_dir = os.path.join(openfisca_core_dir, 'tests', 'core', 'yaml_tests') +yaml_tests_dir = os.path.dirname(yaml_tests.__file__) EXIT_OK = 0 EXIT_TESTSFAILED = 1 diff --git a/tests/fixtures/yaml_tests/__init__.py b/tests/fixtures/yaml_tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/core/yaml_tests/directory/subdirectory/test_4.yaml b/tests/fixtures/yaml_tests/directory/subdirectory/test_4.yaml similarity index 100% rename from tests/core/yaml_tests/directory/subdirectory/test_4.yaml rename to tests/fixtures/yaml_tests/directory/subdirectory/test_4.yaml diff --git a/tests/core/yaml_tests/directory/test_1.yaml b/tests/fixtures/yaml_tests/directory/test_1.yaml similarity index 100% rename from tests/core/yaml_tests/directory/test_1.yaml rename to tests/fixtures/yaml_tests/directory/test_1.yaml diff --git a/tests/core/yaml_tests/directory/test_2.yaml b/tests/fixtures/yaml_tests/directory/test_2.yaml similarity index 100% rename from tests/core/yaml_tests/directory/test_2.yaml rename to tests/fixtures/yaml_tests/directory/test_2.yaml diff --git a/tests/core/yaml_tests/failing_test_absolute_error_margin.yaml b/tests/fixtures/yaml_tests/failing_test_absolute_error_margin.yaml similarity index 100% rename from tests/core/yaml_tests/failing_test_absolute_error_margin.yaml rename to tests/fixtures/yaml_tests/failing_test_absolute_error_margin.yaml diff --git a/tests/core/yaml_tests/failing_test_relative_error_margin.yaml b/tests/fixtures/yaml_tests/failing_test_relative_error_margin.yaml similarity index 100% rename from tests/core/yaml_tests/failing_test_relative_error_margin.yaml rename to tests/fixtures/yaml_tests/failing_test_relative_error_margin.yaml diff --git a/tests/core/yaml_tests/test_absolute_error_margin.yaml b/tests/fixtures/yaml_tests/test_absolute_error_margin.yaml similarity index 100% rename from tests/core/yaml_tests/test_absolute_error_margin.yaml rename to tests/fixtures/yaml_tests/test_absolute_error_margin.yaml diff --git a/tests/core/yaml_tests/test_failure.yaml b/tests/fixtures/yaml_tests/test_failure.yaml similarity index 100% rename from tests/core/yaml_tests/test_failure.yaml rename to tests/fixtures/yaml_tests/test_failure.yaml diff --git a/tests/core/yaml_tests/test_name_filter.yaml b/tests/fixtures/yaml_tests/test_name_filter.yaml similarity index 100% rename from tests/core/yaml_tests/test_name_filter.yaml rename to tests/fixtures/yaml_tests/test_name_filter.yaml diff --git a/tests/core/yaml_tests/test_relative_error_margin.yaml b/tests/fixtures/yaml_tests/test_relative_error_margin.yaml similarity index 100% rename from tests/core/yaml_tests/test_relative_error_margin.yaml rename to tests/fixtures/yaml_tests/test_relative_error_margin.yaml diff --git a/tests/core/yaml_tests/test_success.yml b/tests/fixtures/yaml_tests/test_success.yml similarity index 100% rename from tests/core/yaml_tests/test_success.yml rename to tests/fixtures/yaml_tests/test_success.yml diff --git a/tests/core/yaml_tests/test_with_anchors.yaml b/tests/fixtures/yaml_tests/test_with_anchors.yaml similarity index 100% rename from tests/core/yaml_tests/test_with_anchors.yaml rename to tests/fixtures/yaml_tests/test_with_anchors.yaml diff --git a/tests/core/yaml_tests/test_with_extension.yaml b/tests/fixtures/yaml_tests/test_with_extension.yaml similarity index 100% rename from tests/core/yaml_tests/test_with_extension.yaml rename to tests/fixtures/yaml_tests/test_with_extension.yaml diff --git a/tests/core/yaml_tests/test_with_reform.yaml b/tests/fixtures/yaml_tests/test_with_reform.yaml similarity index 100% rename from tests/core/yaml_tests/test_with_reform.yaml rename to tests/fixtures/yaml_tests/test_with_reform.yaml diff --git a/tests/core/yaml_tests/test_with_reform_2.yaml b/tests/fixtures/yaml_tests/test_with_reform_2.yaml similarity index 100% rename from tests/core/yaml_tests/test_with_reform_2.yaml rename to tests/fixtures/yaml_tests/test_with_reform_2.yaml From b126443b1e34992f97e48119059c27f4f9bdc311 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Fri, 1 Oct 2021 13:30:15 +0200 Subject: [PATCH 011/205] Bump patch to 35.5.2 --- CHANGELOG.md | 7 +++++++ setup.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec66f40e3c..4fcb535f9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### 35.5.2 [#1048](https://github.com/openfisca/openfisca-core/pull/1048) + +#### Bug fix + +- In _test_yaml.py_: + - Fix yaml tests loading —required for testing against the built version. + ### 35.5.1 [#1046](https://github.com/openfisca/openfisca-core/pull/1046) #### Non-technical changes diff --git a/setup.py b/setup.py index 396435263d..01e036df50 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ setup( name = 'OpenFisca-Core', - version = '35.5.1', + version = '35.5.2', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From 2a4d0f806336029c377f739d3e2c80650eade0b2 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 7 Oct 2021 11:07:24 +0200 Subject: [PATCH 012/205] Extend ignore diff on --- .circleci/has-functional-changes.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/has-functional-changes.sh b/.circleci/has-functional-changes.sh index 049a94d6cd..b591716932 100755 --- a/.circleci/has-functional-changes.sh +++ b/.circleci/has-functional-changes.sh @@ -1,6 +1,6 @@ #! /usr/bin/env bash -IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore LICENSE* .circleci/* .github/* tests/*" +IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore LICENSE* .circleci/* .github/* openfisca_tasks/*.mk tasks/*.mk tests/*" last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in master through an unlikely intermediary merge commit From 6cc9caaa8046ca706c77a9ff28eb16b67dba8bb8 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 7 Oct 2021 11:07:55 +0200 Subject: [PATCH 013/205] Add missing carriage return --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2691268681..b5c73a5ff8 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ print_pass = echo $$(tput setaf 2)[✓]$$(tput sgr0) $$(tput setaf 8)$1$$(tput s ## Similar to `print_work`, but this will read the comments above a task, and ## print them to the user at the start of each task. The `$1` is a function ## argument. -print_help = sed -n "/^$1/ { x ; p ; } ; s/\#\#/$(print_work)/ ; s/\./…/ ; x" ${MAKEFILE_LIST} +print_help = sed -n "/^$1/ { x ; p ; } ; s/\#\#/\r$(print_work)/ ; s/\./…/ ; x" ${MAKEFILE_LIST} ## Same as `make`. .DEFAULT_GOAL := all From f24fe53f9244d468ae21068ba2234b8ade33bfab Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 7 Oct 2021 11:09:03 +0200 Subject: [PATCH 014/205] Fix make (build should be phony) --- openfisca_tasks/publish.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openfisca_tasks/publish.mk b/openfisca_tasks/publish.mk index 2f34599fd9..ac0ef2c053 100644 --- a/openfisca_tasks/publish.mk +++ b/openfisca_tasks/publish.mk @@ -1,7 +1,7 @@ ## Install openfisca-core for deployment and publishing. -build: setup.py +build: @## This allows us to be sure tests are run against the packaged version @## of openfisca-core, the same we put in the hands of users and reusers. @$(call print_help,$@:) - @python $? bdist_wheel + @python setup.py bdist_wheel @find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \; From 53e3d0af531f28efb1b9c8fb0ffe5bb631cc2bda Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 30 Sep 2021 18:30:03 +0200 Subject: [PATCH 015/205] Add task to run country/extension --- openfisca_tasks/test_code.mk | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/openfisca_tasks/test_code.mk b/openfisca_tasks/test_code.mk index 878983049d..e5bba15bd8 100644 --- a/openfisca_tasks/test_code.mk +++ b/openfisca_tasks/test_code.mk @@ -1,5 +1,7 @@ -## Run openfisca-core. -test-code: test-core +python_packages = $(shell python -c "import sysconfig; print(sysconfig.get_paths()[\"purelib\"])") + +## Run openfisca-core & country/extension template tests. +test-code: test-core test-country test-extension @## Usage: @## @## make test [pytest_args="--ARG"] [openfisca_args="--ARG"] @@ -10,6 +12,7 @@ test-code: test-core @## make test pytest_args="--exitfirst" @## make test openfisca_args="--performance" @## make test pytest_args="--exitfirst" openfisca_args="--performance" + @## @$(call print_pass,$@:) ## Run openfisca-core tests. @@ -19,3 +22,22 @@ test-core: $(shell git ls-files "tests/*.py") openfisca test $? \ ${openfisca_args} @$(call print_pass,$@:) + +## Run country-template tests. +test-country: + @$(call print_help,$@:) + @PYTEST_ADDOPTS="${PYTEST_ADDOPTS} ${pytest_args}" \ + openfisca test ${python_packages}/openfisca_country_template/tests \ + --country-package openfisca_country_template \ + ${openfisca_args} + @$(call print_pass,$@:) + +## Run extension-template tests. +test-extension: + @$(call print_help,$@:) + @PYTEST_ADDOPTS="${PYTEST_ADDOPTS} ${pytest_args}" \ + openfisca test ${python_packages}/openfisca_extension_template/tests \ + --country-package openfisca_country_template \ + --extensions openfisca_extension_template \ + ${openfisca_args} + @$(call print_pass,$@:) From 0946e6421822f74d3dc1ffc3681d7c6c068143c6 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 30 Sep 2021 18:33:19 +0200 Subject: [PATCH 016/205] Add to circleci --- .circleci/config.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ea7148b39b..67c45002e0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -40,6 +40,14 @@ jobs: name: Run openfisca-core tests command: make test-core pytest_args="--exitfirst" + - run: + name: Run country-template tests + command: make test-country pytest_args="--exitfirst" + + - run: + name: Run extension-template tests + command: make test-extension pytest_args="--exitfirst" + - run: name: Check NumPy typing against latest 3 minor versions command: for i in {1..3}; do VERSION=$(.circleci/get-numpy-version.py prev) && pip install numpy==$VERSION && make check-types; done @@ -49,12 +57,6 @@ jobs: paths: - .coverage - - run: - name: Run Country Template tests - command: | - COUNTRY_TEMPLATE_PATH=`python -c "import openfisca_country_template; print(openfisca_country_template.CountryTaxBenefitSystem().get_package_metadata()['location'])"` - openfisca test $COUNTRY_TEMPLATE_PATH/openfisca_country_template/tests/ - test_docs: docker: - image: python:3.7 From 94ac852041b89895d6219e88d70ec01e85dcdb35 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Fri, 1 Oct 2021 18:40:21 +0200 Subject: [PATCH 017/205] Add doc to python_packages --- openfisca_tasks/test_code.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/openfisca_tasks/test_code.mk b/openfisca_tasks/test_code.mk index e5bba15bd8..8a24ad69b1 100644 --- a/openfisca_tasks/test_code.mk +++ b/openfisca_tasks/test_code.mk @@ -1,3 +1,4 @@ +## The path to the installed packages. python_packages = $(shell python -c "import sysconfig; print(sysconfig.get_paths()[\"purelib\"])") ## Run openfisca-core & country/extension template tests. From e1aafc05c791fb630d46a89a1da7860e2ccf88a8 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 30 Sep 2021 18:33:39 +0200 Subject: [PATCH 018/205] Bump patch to 35.5.3 --- CHANGELOG.md | 6 ++++++ setup.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fcb535f9a..fed09d73c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +### 35.5.3 [#1020](https://github.com/openfisca/openfisca-core/pull/1020) + +#### Technical changes + +- Run openfisca-core & country/extension template tests systematically + ### 35.5.2 [#1048](https://github.com/openfisca/openfisca-core/pull/1048) #### Bug fix diff --git a/setup.py b/setup.py index 01e036df50..1935635464 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ setup( name = 'OpenFisca-Core', - version = '35.5.2', + version = '35.5.3', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From 307201ad83d6c38c67991188c8584f96d63c60a7 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 19 Sep 2021 22:28:46 +0200 Subject: [PATCH 019/205] Sort deps alphabetically --- setup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 1935635464..05da35a246 100644 --- a/setup.py +++ b/setup.py @@ -7,19 +7,19 @@ general_requirements = [ 'dpath >= 1.5.0, < 2.0.0', - 'pytest >= 4.4.1, < 6.0.0', # For openfisca test + 'numexpr >= 2.7.0, <= 3.0', 'numpy >= 1.11, < 1.21', 'psutil >= 5.4.7, < 6.0.0', + 'pytest >= 4.4.1, < 6.0.0', # For openfisca test 'PyYAML >= 3.10', 'sortedcontainers == 2.2.2', - 'numexpr >= 2.7.0, <= 3.0', ] api_requirements = [ - 'werkzeug >= 1.0.0, < 2.0.0', 'flask == 1.1.2', 'flask-cors == 3.0.10', 'gunicorn >= 20.0.0, < 21.0.0', + 'werkzeug >= 1.0.0, < 2.0.0', ] dev_requirements = [ @@ -28,10 +28,10 @@ 'flake8-bugbear >= 19.3.0, < 20.0.0', 'flake8-print >= 3.1.0, < 4.0.0', 'flake8-rst-docstrings < 1.0.0', - 'pytest-cov >= 2.6.1, < 3.0.0', 'mypy >= 0.701, < 0.800', 'openfisca-country-template >= 3.10.0, < 4.0.0', - 'openfisca-extension-template >= 1.2.0rc0, < 2.0.0' + 'openfisca-extension-template >= 1.2.0rc0, < 2.0.0', + 'pytest-cov >= 2.6.1, < 3.0.0', ] + api_requirements setup( From c14fd44c1db5f710849e7d8fb0dfcf43f87ea4b2 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 19 Sep 2021 22:34:23 +0200 Subject: [PATCH 020/205] Add nptying for numpy type-checks --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 05da35a246..4d10109413 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ general_requirements = [ 'dpath >= 1.5.0, < 2.0.0', + 'nptyping >= 1.4.3, < 2.0.0', 'numexpr >= 2.7.0, <= 3.0', 'numpy >= 1.11, < 1.21', 'psutil >= 5.4.7, < 6.0.0', From f4638afd5d2d68dfc0e2ceb2f0105cc4d1be324a Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 19 Sep 2021 22:38:51 +0200 Subject: [PATCH 021/205] Add the types subpackage --- openfisca_core/types/__init__.py | 46 +++++++++++++++++ openfisca_core/types/data_types/__init__.py | 1 + openfisca_core/types/data_types/arrays.py | 56 +++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 openfisca_core/types/__init__.py create mode 100644 openfisca_core/types/data_types/__init__.py create mode 100644 openfisca_core/types/data_types/arrays.py diff --git a/openfisca_core/types/__init__.py b/openfisca_core/types/__init__.py new file mode 100644 index 0000000000..36dabd1899 --- /dev/null +++ b/openfisca_core/types/__init__.py @@ -0,0 +1,46 @@ +"""Data types and protocols used by OpenFisca Core. + +The type definitions included in this sub-package are intented mostly for +contributors, to help them better document contracts and behaviours. + +Official Public API: + * ``ArrayLike`` + * :attr:`.ArrayType` + +Note: + How imports are being used today:: + + from openfisca_core.types import * # Bad + from openfisca_core.types.data_types.arrays import ArrayLike # Bad + + + The previous examples provoke cyclic dependency problems, that prevents us + from modularizing the different components of the library, so as to make + them easier to test and to maintain. + + How could them be used after the next major release:: + + from openfisca_core.types import ArrayLike + + ArrayLike # Good: import types as publicly exposed + + .. seealso:: `PEP8#Imports`_ and `OpenFisca's Styleguide`_. + + .. _PEP8#Imports: + https://www.python.org/dev/peps/pep-0008/#imports + + .. _OpenFisca's Styleguide: + https://github.com/openfisca/openfisca-core/blob/master/STYLEGUIDE.md + +""" + +# Official Public API + +from .data_types import ( # noqa: F401 + ArrayLike, + ArrayType, + ) + +#: Official Public API + +__all__ = ["ArrayLike", "ArrayType"] diff --git a/openfisca_core/types/data_types/__init__.py b/openfisca_core/types/data_types/__init__.py new file mode 100644 index 0000000000..6dd38194e3 --- /dev/null +++ b/openfisca_core/types/data_types/__init__.py @@ -0,0 +1 @@ +from .arrays import ArrayLike, ArrayType # noqa: F401 diff --git a/openfisca_core/types/data_types/arrays.py b/openfisca_core/types/data_types/arrays.py new file mode 100644 index 0000000000..3e941b4ab1 --- /dev/null +++ b/openfisca_core/types/data_types/arrays.py @@ -0,0 +1,56 @@ +from typing import Sequence, TypeVar, Union + +from nptyping import NDArray as ArrayType + +T = TypeVar("T", bool, bytes, float, int, object, str) + +A = Union[ + ArrayType[bool], + ArrayType[bytes], + ArrayType[float], + ArrayType[int], + ArrayType[object], + ArrayType[str], + ] + +ArrayLike = Union[A, Sequence[T]] +""":obj:`typing.Generic`: Type of any castable to :class:`numpy.ndarray`. + +These include any :obj:`numpy.ndarray` and sequences (like +:obj:`list`, :obj:`tuple`, and so on). + +Examples: + >>> ArrayLike[float] + typing.Union[numpy.ndarray, typing.Sequence[float]] + + >>> ArrayLike[str] + typing.Union[numpy.ndarray, typing.Sequence[str]] + +Note: + It is possible since numpy version 1.21 to specify the type of an + array, thanks to `numpy.typing.NDArray`_:: + + from numpy.typing import NDArray + NDArray[numpy.float64] + + `mypy`_ provides `duck type compatibility`_, so an :obj:`int` is + considered to be valid whenever a :obj:`float` is expected. + +Todo: + * Refactor once numpy version >= 1.21 is used. + +.. versionadded:: 35.5.0 + +.. versionchanged:: 35.6.0 + Moved to :mod:`.types` + +.. _mypy: + https://mypy.readthedocs.io/en/stable/ + +.. _duck type compatibility: + https://mypy.readthedocs.io/en/stable/duck_type_compatibility.html + +.. _numpy.typing.NDArray: + https://numpy.org/doc/stable/reference/typing.html#numpy.typing.NDArray + +""" From dcf0504f2141bda3a12454892e896f97b823a0e5 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 19 Sep 2021 22:46:21 +0200 Subject: [PATCH 022/205] Add darglint for docstring lints --- setup.cfg | 18 ++++++++++-------- setup.py | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/setup.cfg b/setup.cfg index 4f98591eeb..0307bfa59c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,16 +5,18 @@ ; W503/504: We break lines before binary operators (Knuth's style) [flake8] -hang-closing = true -ignore = E128,E251,F403,F405,E501,W503,W504 -in-place = true -rst-roles = any, class, exc, meth, obj -rst-directives = attribute +hang-closing = true +extend-ignore = D +ignore = E128,E251,F403,F405,E501,W503,W504 +in-place = true +rst-directives = attribute +rst-roles = any, class, exc, meth, obj +strictness = short [tool:pytest] -addopts = --showlocals --doctest-modules --disable-pytest-warnings -testpaths = tests -python_files = **/*.py +addopts = --showlocals --doctest-modules --disable-pytest-warnings +testpaths = tests +python_files = **/*.py [mypy] ignore_missing_imports = True diff --git a/setup.py b/setup.py index 4d10109413..077e733b14 100644 --- a/setup.py +++ b/setup.py @@ -25,6 +25,7 @@ dev_requirements = [ 'autopep8 >= 1.4.0, < 1.6.0', + 'darglint == 1.8.0', 'flake8 >= 3.9.0, < 4.0.0', 'flake8-bugbear >= 19.3.0, < 20.0.0', 'flake8-print >= 3.1.0, < 4.0.0', From 342fda850d024f9bbcc49aacdfb97c582a99d9fc Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 19 Sep 2021 22:49:22 +0200 Subject: [PATCH 023/205] Add flake8-docstrings for docstring lints --- setup.cfg | 4 ++-- setup.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 0307bfa59c..b7a1aa1c1d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,8 +9,8 @@ hang-closing = true extend-ignore = D ignore = E128,E251,F403,F405,E501,W503,W504 in-place = true -rst-directives = attribute -rst-roles = any, class, exc, meth, obj +rst-directives = attribute, deprecated, seealso, versionadded, versionchanged +rst-roles = any, attr, class, exc, func, meth, obj strictness = short [tool:pytest] diff --git a/setup.py b/setup.py index 077e733b14..5086afb0f1 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,7 @@ 'darglint == 1.8.0', 'flake8 >= 3.9.0, < 4.0.0', 'flake8-bugbear >= 19.3.0, < 20.0.0', + 'flake8-docstrings == 1.6.0', 'flake8-print >= 3.1.0, < 4.0.0', 'flake8-rst-docstrings < 1.0.0', 'mypy >= 0.701, < 0.800', From 596e05f51b4b18c889f1ee52fa3e2abef0e57388 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 19 Sep 2021 22:50:34 +0200 Subject: [PATCH 024/205] Set flake8 jobs to automatic --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index b7a1aa1c1d..13d9bdc05f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,6 +9,7 @@ hang-closing = true extend-ignore = D ignore = E128,E251,F403,F405,E501,W503,W504 in-place = true +jobs = 0 rst-directives = attribute, deprecated, seealso, versionadded, versionchanged rst-roles = any, attr, class, exc, func, meth, obj strictness = short From 28a2f49e0107afd14441b70573389619c6ac888a Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 19 Sep 2021 22:51:24 +0200 Subject: [PATCH 025/205] Add commons to flake8 doctest path --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 13d9bdc05f..2f29d2e405 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,6 +9,7 @@ hang-closing = true extend-ignore = D ignore = E128,E251,F403,F405,E501,W503,W504 in-place = true +include-in-doctest = openfisca_core/commons jobs = 0 rst-directives = attribute, deprecated, seealso, versionadded, versionchanged rst-roles = any, attr, class, exc, func, meth, obj From 4a33d573662edd1b118ca5fe115437c05414b769 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 19 Sep 2021 22:52:59 +0200 Subject: [PATCH 026/205] Add pylint for docstring lints --- setup.cfg | 5 +++++ setup.py | 1 + 2 files changed, 6 insertions(+) diff --git a/setup.cfg b/setup.cfg index 2f29d2e405..16ce15d85a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,6 +15,11 @@ rst-directives = attribute, deprecated, seealso, versionadded, versionchang rst-roles = any, attr, class, exc, func, meth, obj strictness = short +[pylint.message_control] +disable = all +jobs = 0 +score = no + [tool:pytest] addopts = --showlocals --doctest-modules --disable-pytest-warnings testpaths = tests diff --git a/setup.py b/setup.py index 5086afb0f1..dc55e3e783 100644 --- a/setup.py +++ b/setup.py @@ -32,6 +32,7 @@ 'flake8-print >= 3.1.0, < 4.0.0', 'flake8-rst-docstrings < 1.0.0', 'mypy >= 0.701, < 0.800', + 'pylint == 2.10.2', 'openfisca-country-template >= 3.10.0, < 4.0.0', 'openfisca-extension-template >= 1.2.0rc0, < 2.0.0', 'pytest-cov >= 2.6.1, < 3.0.0', From 12611134f2ef8f0becb0820e392886291b024c5a Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 19 Sep 2021 22:55:15 +0200 Subject: [PATCH 027/205] Add coverage threshold to pytest --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 16ce15d85a..e2c80252eb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,7 +21,7 @@ jobs = 0 score = no [tool:pytest] -addopts = --showlocals --doctest-modules --disable-pytest-warnings +addopts = --cov-report=term-missing:skip-covered --cov-fail-under=78.69 --doctest-modules --disable-pytest-warnings --showlocals testpaths = tests python_files = **/*.py From 23203ca75a0672e6111b60f8c0d1b3640f47c277 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 19 Sep 2021 22:58:12 +0200 Subject: [PATCH 028/205] Add doctests setup to pytest --- setup.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index e2c80252eb..7c8a105c68 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,8 +22,9 @@ score = no [tool:pytest] addopts = --cov-report=term-missing:skip-covered --cov-fail-under=78.69 --doctest-modules --disable-pytest-warnings --showlocals -testpaths = tests +doctest_optionflags = ELLIPSIS IGNORE_EXCEPTION_DETAIL NUMBER NORMALIZE_WHITESPACE python_files = **/*.py +testpaths = tests [mypy] ignore_missing_imports = True From 8f322163d5df191ed16d96e652cd632d7dee1a02 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 19 Sep 2021 23:00:15 +0200 Subject: [PATCH 029/205] Add types to tests path --- setup.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 7c8a105c68..8a5dac766e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,7 +9,7 @@ hang-closing = true extend-ignore = D ignore = E128,E251,F403,F405,E501,W503,W504 in-place = true -include-in-doctest = openfisca_core/commons +include-in-doctest = openfisca_core/commons openfisca_core/types jobs = 0 rst-directives = attribute, deprecated, seealso, versionadded, versionchanged rst-roles = any, attr, class, exc, func, meth, obj @@ -24,7 +24,7 @@ score = no addopts = --cov-report=term-missing:skip-covered --cov-fail-under=78.69 --doctest-modules --disable-pytest-warnings --showlocals doctest_optionflags = ELLIPSIS IGNORE_EXCEPTION_DETAIL NUMBER NORMALIZE_WHITESPACE python_files = **/*.py -testpaths = tests +testpaths = openfisca_core/commons openfisca_core/types tests [mypy] ignore_missing_imports = True From 727344d622a9ec53091ee536d4a8dd9865b1e1cf Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 19 Sep 2021 23:06:04 +0200 Subject: [PATCH 030/205] Update mypy to avoid false-positives --- setup.cfg | 3 +++ setup.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 8a5dac766e..880fc8d31c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,5 +29,8 @@ testpaths = openfisca_core/commons openfisca_core/types tests [mypy] ignore_missing_imports = True +[mypy-openfisca_core.commons.tests.*] +ignore_errors = True + [mypy-openfisca_core.scripts.*] ignore_errors = True diff --git a/setup.py b/setup.py index dc55e3e783..432205cfd9 100644 --- a/setup.py +++ b/setup.py @@ -14,6 +14,7 @@ 'pytest >= 4.4.1, < 6.0.0', # For openfisca test 'PyYAML >= 3.10', 'sortedcontainers == 2.2.2', + 'typing-extensions >= 3.0.0.0, < 4.0.0.0', ] api_requirements = [ @@ -31,11 +32,13 @@ 'flake8-docstrings == 1.6.0', 'flake8-print >= 3.1.0, < 4.0.0', 'flake8-rst-docstrings < 1.0.0', - 'mypy >= 0.701, < 0.800', + 'mypy == 0.910', 'pylint == 2.10.2', 'openfisca-country-template >= 3.10.0, < 4.0.0', 'openfisca-extension-template >= 1.2.0rc0, < 2.0.0', 'pytest-cov >= 2.6.1, < 3.0.0', + 'types-PyYAML == 5.4.10', + 'types-setuptools == 57.0.2', ] + api_requirements setup( From e9c07c9e6e242bc11e16e412a6618ec4bef2488a Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 20 Sep 2021 00:08:14 +0200 Subject: [PATCH 031/205] Fix bug in make test-doc --- openfisca_tasks/lint.mk | 30 +++++++++++++++++++++++++++--- openfisca_tasks/test_code.mk | 2 +- openfisca_tasks/test_doc.mk | 3 +++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/openfisca_tasks/lint.mk b/openfisca_tasks/lint.mk index 8be8dd71ce..2e52457926 100644 --- a/openfisca_tasks/lint.mk +++ b/openfisca_tasks/lint.mk @@ -1,5 +1,5 @@ ## Lint the codebase. -lint: check-syntax-errors check-style check-types +lint: check-syntax-errors check-style lint-styling-doc check-types @$(call print_pass,$@:) ## Compile python files to check for syntax errors. @@ -14,10 +14,34 @@ check-style: $(shell git ls-files "*.py") @flake8 $? @$(call print_pass,$@:) +## Run linters to check for syntax and style errors in the doc. +lint-styling-doc: \ + lint-styling-doc-commons \ + lint-styling-doc-types \ + ; + +## Run linters to check for syntax and style errors in the doc. +lint-styling-doc-%: + @## These checks are exclusively related to doc/strings/test. + @## + @## They can be integrated into setup.cfg once all checks pass. + @## The reason they're here is because otherwise we wouldn't be + @## able to integrate documentation improvements progresively. + @## + @## D101: Each class has to have at least one doctest. + @## D102: Each public method has to have at least one doctest. + @## D103: Each public function has to have at least one doctest. + @## DARXXX: https://github.com/terrencepreilly/darglint#error-codes. + @## + @$(call print_help,$(subst $*,%,$@:)) + @flake8 --select=D101,D102,D103,DAR openfisca_core/$* + @pylint openfisca_core/$* + @$(call print_pass,$@:) + ## Run static type checkers for type errors. -check-types: openfisca_core openfisca_web_api +check-types: @$(call print_help,$@:) - @mypy $? + @mypy --package openfisca_core --package openfisca_web_api @$(call print_pass,$@:) ## Run code formatters to correct style errors. diff --git a/openfisca_tasks/test_code.mk b/openfisca_tasks/test_code.mk index 8a24ad69b1..ffa87efbc4 100644 --- a/openfisca_tasks/test_code.mk +++ b/openfisca_tasks/test_code.mk @@ -19,7 +19,7 @@ test-code: test-core test-country test-extension ## Run openfisca-core tests. test-core: $(shell git ls-files "tests/*.py") @$(call print_help,$@:) - @PYTEST_ADDOPTS="${PYTEST_ADDOPTS} --cov=openfisca_core ${pytest_args}" \ + @PYTEST_ADDOPTS="${PYTEST_ADDOPTS} --cov=openfisca_core --cov=openfisca_web_api ${pytest_args}" \ openfisca test $? \ ${openfisca_args} @$(call print_pass,$@:) diff --git a/openfisca_tasks/test_doc.mk b/openfisca_tasks/test_doc.mk index fb7249c99e..bce952fe81 100644 --- a/openfisca_tasks/test_doc.mk +++ b/openfisca_tasks/test_doc.mk @@ -62,14 +62,17 @@ test-doc-checkout: } \ || git pull --ff-only origin master ; \ } 1> /dev/null + @$(call print_pass,$@:) ## Install doc dependencies. test-doc-install: @$(call print_help,$@:) @pip install --requirement doc/requirements.txt 1> /dev/null @pip install --editable .[dev] --upgrade 1> /dev/null + @$(call print_pass,$@:) ## Dry-build the doc. test-doc-build: @$(call print_help,$@:) @sphinx-build -M dummy doc/source doc/build -n -q -W + @$(call print_pass,$@:) From 39aa617803b7e06f436840c4a5513f5f2d17cbba Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 20 Sep 2021 00:25:21 +0200 Subject: [PATCH 032/205] Add commons/decorators --- openfisca_core/commons/__init__.py | 1 + openfisca_core/commons/decorators.py | 76 +++++++++++++++++++ openfisca_core/commons/tests/__init__.py | 0 .../commons/tests/test_decorators.py | 20 +++++ 4 files changed, 97 insertions(+) create mode 100644 openfisca_core/commons/decorators.py create mode 100644 openfisca_core/commons/tests/__init__.py create mode 100644 openfisca_core/commons/tests/test_decorators.py diff --git a/openfisca_core/commons/__init__.py b/openfisca_core/commons/__init__.py index db41ed1874..42c1ada223 100644 --- a/openfisca_core/commons/__init__.py +++ b/openfisca_core/commons/__init__.py @@ -23,6 +23,7 @@ from .dummy import Dummy # noqa: F401 +from .decorators import deprecated # noqa: F401 from .formulas import apply_thresholds, concat, switch # noqa: F401 from .misc import empty_clone, stringify_array # noqa: F401 from .rates import average_rate, marginal_rate # noqa: F401 diff --git a/openfisca_core/commons/decorators.py b/openfisca_core/commons/decorators.py new file mode 100644 index 0000000000..2041a7f4f7 --- /dev/null +++ b/openfisca_core/commons/decorators.py @@ -0,0 +1,76 @@ +import functools +import warnings +import typing +from typing import Any, Callable, TypeVar + +T = Callable[..., Any] +F = TypeVar("F", bound = T) + + +class deprecated: + """Allows (soft) deprecating a functionality of OpenFisca. + + Attributes: + since (:obj:`str`): Since when the functionality is deprecated. + expires (:obj:`str`): When will it be removed forever? + + Args: + since: Since when the functionality is deprecated. + expires: When will it be removed forever? + + Examples: + >>> @deprecated(since = "35.5.0", expires = "in the future") + ... def obsolete(): + ... return "I'm obsolete!" + + >>> repr(obsolete) + '' + + >>> str(obsolete) + '' + + .. versionadded:: 35.6.0 + + """ + + since: str + expires: str + + def __init__(self, since: str, expires: str) -> None: + self.since = since + self.expires = expires + + def __call__(self, function: F) -> F: + """Wraps a function to return another one, decorated. + + Args: + function: The function or method to decorate. + + Returns: + :obj:`callable`: The decorated function. + + Examples: + >>> def obsolete(): + ... return "I'm obsolete!" + + >>> decorator = deprecated( + ... since = "35.5.0", + ... expires = "in the future", + ... ) + + >>> decorator(obsolete) + + + """ + + def wrapper(*args: Any, **kwds: Any) -> Any: + message = [ + f"{function.__qualname__} has been deprecated since", + f"version {self.since}, and will be removed in", + f"{self.expires}.", + ] + warnings.warn(" ".join(message), DeprecationWarning) + return function(*args, **kwds) + + functools.update_wrapper(wrapper, function) + return typing.cast(F, wrapper) diff --git a/openfisca_core/commons/tests/__init__.py b/openfisca_core/commons/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/openfisca_core/commons/tests/test_decorators.py b/openfisca_core/commons/tests/test_decorators.py new file mode 100644 index 0000000000..04c5ce3d91 --- /dev/null +++ b/openfisca_core/commons/tests/test_decorators.py @@ -0,0 +1,20 @@ +import re + +import pytest + +from openfisca_core.commons import deprecated + + +def test_deprecated(): + """The decorated function throws a deprecation warning when used.""" + + since = "yesterday" + expires = "doomsday" + match = re.compile(f"^.*{since}.*{expires}.*$") + + @deprecated(since, expires) + def function(a: int, b: float) -> float: + return a + b + + with pytest.warns(DeprecationWarning, match = match): + assert function(1, 2.) == 3. From 757c0087b7c9272bf69e08bcd369e9d293809b7b Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 20 Sep 2021 00:27:40 +0200 Subject: [PATCH 033/205] Fix commons/dummy doctests --- openfisca_core/commons/dummy.py | 21 +++++++++++++-------- openfisca_core/commons/tests/test_dummy.py | 10 ++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 openfisca_core/commons/tests/test_dummy.py diff --git a/openfisca_core/commons/dummy.py b/openfisca_core/commons/dummy.py index 4136a0d429..732ed49a65 100644 --- a/openfisca_core/commons/dummy.py +++ b/openfisca_core/commons/dummy.py @@ -1,13 +1,18 @@ -import warnings +from .decorators import deprecated class Dummy: - """A class that does nothing.""" + """A class that did nothing. + Examples: + >>> Dummy() + None: - message = [ - "The 'Dummy' class has been deprecated since version 34.7.0,", - "and will be removed in the future.", - ] - warnings.warn(" ".join(message), DeprecationWarning) - pass + ... diff --git a/openfisca_core/commons/tests/test_dummy.py b/openfisca_core/commons/tests/test_dummy.py new file mode 100644 index 0000000000..d4ecec3842 --- /dev/null +++ b/openfisca_core/commons/tests/test_dummy.py @@ -0,0 +1,10 @@ +import pytest + +from openfisca_core.commons import Dummy + + +def test_dummy_deprecation(): + """Dummy throws a deprecation warning when instantiated.""" + + with pytest.warns(DeprecationWarning): + assert Dummy() From a75f83685bb67d595fc858610a6bd8ebd4ffd1f8 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 20 Sep 2021 00:28:42 +0200 Subject: [PATCH 034/205] Fix commons/formulas doctests --- openfisca_core/commons/formulas.py | 127 ++++++++++++++---- openfisca_core/commons/tests/test_formulas.py | 81 +++++++++++ 2 files changed, 181 insertions(+), 27 deletions(-) create mode 100644 openfisca_core/commons/tests/test_formulas.py diff --git a/openfisca_core/commons/formulas.py b/openfisca_core/commons/formulas.py index 4fadc1b518..a750717f1d 100644 --- a/openfisca_core/commons/formulas.py +++ b/openfisca_core/commons/formulas.py @@ -1,52 +1,125 @@ +from typing import Any, Dict, List + import numpy +from openfisca_core.types import ArrayLike, ArrayType + + +def apply_thresholds( + input: ArrayType[float], + thresholds: ArrayLike[float], + choices: ArrayLike[float], + ) -> ArrayType[float]: + """Makes a choice based on an input and thresholds. + + From list of ``choices``, it selects one of them based on a list of + inputs, depending on the position of each ``input`` whithin a list of + ``thresholds``. It does so for each ``input`` provided. + + Args: + input: A list of inputs to make a choice. + thresholds: A list of thresholds to choose. + choices: A list of the possible choices. + + Returns: + :obj:`numpy.ndarray` of :obj:`float`: + A list of the choices made. + + Raises: + :exc:`AssertionError`: When the number of ``thresholds`` (t) and the + number of choices (c) are not either t == c or t == c - 1. + + Examples: + >>> input = numpy.array([4, 5, 6, 7, 8]) + >>> thresholds = [5, 7] + >>> choices = [10, 15, 20] + >>> apply_thresholds(input, thresholds, choices) + array([10, 10, 15, 15, 20]) -def apply_thresholds(input, thresholds, choices): - """ - Return one of the choices depending on the input position compared to thresholds, for each input. - - >>> apply_thresholds(np.array([4]), [5, 7], [10, 15, 20]) - array([10]) - >>> apply_thresholds(np.array([5]), [5, 7], [10, 15, 20]) - array([10]) - >>> apply_thresholds(np.array([6]), [5, 7], [10, 15, 20]) - array([15]) - >>> apply_thresholds(np.array([8]), [5, 7], [10, 15, 20]) - array([20]) - >>> apply_thresholds(np.array([10]), [5, 7, 9], [10, 15, 20]) - array([0]) """ + + condlist: List[ArrayType[bool]] + condlist = [input <= threshold for threshold in thresholds] + if len(condlist) == len(choices) - 1: - # If a choice is provided for input > highest threshold, last condition must be true to return it. + # If a choice is provided for input > highest threshold, last condition + # must be true to return it. condlist += [True] + assert len(condlist) == len(choices), \ - "apply_thresholds must be called with the same number of thresholds than choices, or one more choice" + " ".join([ + "apply_thresholds must be called with the same number of", + "thresholds than choices, or one more choice", + ]) + return numpy.select(condlist, choices) -def concat(this, that): - if isinstance(this, numpy.ndarray) and not numpy.issubdtype(this.dtype, numpy.str): +def concat(this: ArrayLike[str], that: ArrayLike[str]) -> ArrayType[str]: + """Concatenates the values of two arrays. + + Args: + this: An array to concatenate. + that: Another array to concatenate. + + Returns: + :obj:`numpy.ndarray` of :obj:`float`: + An array with the concatenated values. + + Examples: + >>> this = ["this", "that"] + >>> that = numpy.array([1, 2.5]) + >>> concat(this, that) + array(['this1.0', 'that2.5']...) + + """ + + if isinstance(this, numpy.ndarray) and \ + not numpy.issubdtype(this.dtype, numpy.str_): this = this.astype('str') - if isinstance(that, numpy.ndarray) and not numpy.issubdtype(that.dtype, numpy.str): + + if isinstance(that, numpy.ndarray) and \ + not numpy.issubdtype(that.dtype, numpy.str_): that = that.astype('str') - return numpy.core.defchararray.add(this, that) + return numpy.char.add(this, that) + + +def switch( + conditions: ArrayType[float], + value_by_condition: Dict[float, Any], + ) -> ArrayType[float]: + """Reproduces a switch statement. + Given an array of conditions, returns an array of the same size, + replacing each condition item by the corresponding given value. -def switch(conditions, value_by_condition): - ''' - Reproduces a switch statement: given an array of conditions, return an array of the same size replacing each - condition item by the corresponding given value. + Args: + conditions: An array of conditions. + value_by_condition: Values to replace for each condition. - Example: - >>> switch(np.array([1, 1, 1, 2]), {1: 80, 2: 90}) + Returns: + :obj:`numpy.ndarray` of :obj:`float`: + An array with the replaced values. + + Raises: + :exc:`AssertionError`: When ``value_by_condition`` is empty. + + Examples: + >>> conditions = numpy.array([1, 1, 1, 2]) + >>> value_by_condition = {1: 80, 2: 90} + >>> switch(conditions, value_by_condition) array([80, 80, 80, 90]) - ''' + + """ + assert len(value_by_condition) > 0, \ "switch must be called with at least one value" + condlist = [ conditions == condition for condition in value_by_condition.keys() ] + return numpy.select(condlist, value_by_condition.values()) diff --git a/openfisca_core/commons/tests/test_formulas.py b/openfisca_core/commons/tests/test_formulas.py new file mode 100644 index 0000000000..f05725cb80 --- /dev/null +++ b/openfisca_core/commons/tests/test_formulas.py @@ -0,0 +1,81 @@ +import numpy +import pytest +from numpy.testing import assert_array_equal + +from openfisca_core import commons + + +def test_apply_thresholds_when_several_inputs(): + """Makes a choice for any given input.""" + + input_ = numpy.array([4, 5, 6, 7, 8, 9, 10]) + thresholds = [5, 7, 9] + choices = [10, 15, 20, 25] + + result = commons.apply_thresholds(input_, thresholds, choices) + + assert_array_equal(result, [10, 10, 15, 15, 20, 20, 25]) + + +def test_apply_thresholds_when_too_many_thresholds(): + """Raises an AssertionError when thresholds > choices.""" + + input_ = numpy.array([6]) + thresholds = [5, 7, 9, 11] + choices = [10, 15, 20] + + with pytest.raises(AssertionError): + assert commons.apply_thresholds(input_, thresholds, choices) + + +def test_apply_thresholds_when_too_many_choices(): + """Raises an AssertionError when thresholds < choices - 1.""" + + input_ = numpy.array([6]) + thresholds = [5, 7] + choices = [10, 15, 20, 25] + + with pytest.raises(AssertionError): + assert commons.apply_thresholds(input_, thresholds, choices) + + +def test_concat_when_this_is_array_not_str(): + """Casts ``this`` to ``str`` when it is a numpy array other than string.""" + + this = numpy.array([1, 2]) + that = numpy.array(["la", "o"]) + + result = commons.concat(this, that) + + assert_array_equal(result, ["1la", "2o"]) + + +def test_concat_when_that_is_array_not_str(): + """Casts ``that`` to ``str`` when it is a numpy array other than string.""" + + this = numpy.array(["ho", "cha"]) + that = numpy.array([1, 2]) + + result = commons.concat(this, that) + + assert_array_equal(result, ["ho1", "cha2"]) + + +def test_concat_when_args_not_str_array_like(): + """Raises a TypeError when args are not a string array-like object.""" + + this = (1, 2) + that = (3, 4) + + with pytest.raises(TypeError): + commons.concat(this, that) + + +def test_switch_when_values_are_empty(): + """Raises an AssertionError when the values are empty.""" + + conditions = [1, 1, 1, 2] + value_by_condition = {} + + with pytest.raises(AssertionError): + assert commons.switch(conditions, value_by_condition) From cc8b623e94d1960d2002d2df6879bd2d25282153 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 20 Sep 2021 00:29:32 +0200 Subject: [PATCH 035/205] Fix commons/rates doctests --- openfisca_core/commons/rates.py | 125 ++++++++++++++++++--- openfisca_core/commons/tests/test_rates.py | 26 +++++ 2 files changed, 137 insertions(+), 14 deletions(-) create mode 100644 openfisca_core/commons/tests/test_rates.py diff --git a/openfisca_core/commons/rates.py b/openfisca_core/commons/rates.py index 4bc8580193..487abd3aea 100644 --- a/openfisca_core/commons/rates.py +++ b/openfisca_core/commons/rates.py @@ -1,27 +1,124 @@ +from typing import Optional + import numpy +from openfisca_core.types import ArrayLike, ArrayType + + +def average_rate( + target: ArrayType[float], + varying: ArrayLike[float], + trim: Optional[ArrayLike[float]] = None, + ) -> ArrayType[float]: + """Computes the average rate of a target net income. + + Given a ``target`` net income, and according to the ``varying`` gross + income. Optionally, a ``trim`` can be applied consisting on the lower and + upper bounds of the average rate to be computed. + + Note: + Usually, ``target`` and ``varying`` are the same size. + + Args: + target: The targeted net income. + varying: The varying gross income. + trim: The lower and upper bounds of the average rate. + + Returns: + :obj:`numpy.ndarray` of :obj:`float`: -def average_rate(target = None, varying = None, trim = None): - ''' - Computes the average rate of a targeted net income, according to the varying gross income. + The average rate for each target. + + When ``trim`` is provided, values that are out of the provided bounds + are replaced by :obj:`numpy.nan`. + + Examples: + >>> target = numpy.array([1, 2, 3]) + >>> varying = [2, 2, 2] + >>> trim = [-1, .25] + >>> average_rate(target, varying, trim) + array([ nan, 0. , -0.5]) + + """ + + average_rate: ArrayType[float] - :param target: Targeted net income, numerator - :param varying: Varying gross income, denominator - :param trim: Lower and upper bound of average rate to return - ''' average_rate = 1 - target / varying + if trim is not None: - average_rate = numpy.where(average_rate <= max(trim), average_rate, numpy.nan) - average_rate = numpy.where(average_rate >= min(trim), average_rate, numpy.nan) + + average_rate = numpy.where( + average_rate <= max(trim), + average_rate, + numpy.nan, + ) + + average_rate = numpy.where( + average_rate >= min(trim), + average_rate, + numpy.nan, + ) return average_rate -def marginal_rate(target = None, varying = None, trim = None): - # target: numerator, varying: denominator - marginal_rate = 1 - (target[:-1] - target[1:]) / (varying[:-1] - varying[1:]) +def marginal_rate( + target: ArrayType[float], + varying: ArrayType[float], + trim: Optional[ArrayLike[float]] = None, + ) -> ArrayType[float]: + """Computes the marginal rate of a target net income. + + Given a ``target`` net income, and according to the ``varying`` gross + income. Optionally, a ``trim`` can be applied consisting of the lower and + upper bounds of the marginal rate to be computed. + + Note: + Usually, ``target`` and ``varying`` are the same size. + + Args: + target: The targeted net income. + varying: The varying gross income. + trim: The lower and upper bounds of the marginal rate. + + Returns: + :obj:`numpy.ndarray` of :obj:`float`: + + The marginal rate for each target. + + When ``trim`` is provided, values that are out of the provided bounds + are replaced by :obj:`numpy.nan`. + + Examples: + >>> target = numpy.array([1, 2, 3]) + >>> varying = numpy.array([1, 2, 4]) + >>> trim = [.25, .75] + >>> marginal_rate(target, varying, trim) + array([nan, 0.5]) + + """ + + marginal_rate: ArrayType[float] + + marginal_rate = ( + + 1 + - (target[:-1] + - target[1:]) / (varying[:-1] + - varying[1:]) + ) + if trim is not None: - marginal_rate = numpy.where(marginal_rate <= max(trim), marginal_rate, numpy.nan) - marginal_rate = numpy.where(marginal_rate >= min(trim), marginal_rate, numpy.nan) + + marginal_rate = numpy.where( + marginal_rate <= max(trim), + marginal_rate, + numpy.nan, + ) + + marginal_rate = numpy.where( + marginal_rate >= min(trim), + marginal_rate, + numpy.nan, + ) return marginal_rate diff --git a/openfisca_core/commons/tests/test_rates.py b/openfisca_core/commons/tests/test_rates.py new file mode 100644 index 0000000000..e603a05241 --- /dev/null +++ b/openfisca_core/commons/tests/test_rates.py @@ -0,0 +1,26 @@ +import numpy +from numpy.testing import assert_array_equal + +from openfisca_core import commons + + +def test_average_rate_when_varying_is_zero(): + """Yields infinity when the varying gross income crosses zero.""" + + target = numpy.array([1, 2, 3]) + varying = [0, 0, 0] + + result = commons.average_rate(target, varying) + + assert_array_equal(result, [- numpy.inf, - numpy.inf, - numpy.inf]) + + +def test_marginal_rate_when_varying_is_zero(): + """Yields infinity when the varying gross income crosses zero.""" + + target = numpy.array([1, 2, 3]) + varying = numpy.array([0, 0, 0]) + + result = commons.marginal_rate(target, varying) + + assert_array_equal(result, [numpy.inf, numpy.inf]) From 54a8706ee4dfc3af7d9b7ccf3d413d7f5faf5300 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 20 Sep 2021 00:30:27 +0200 Subject: [PATCH 036/205] Fix commons/misc doctests --- openfisca_core/commons/misc.py | 74 +++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/openfisca_core/commons/misc.py b/openfisca_core/commons/misc.py index eb2bc7372c..5056389c6e 100644 --- a/openfisca_core/commons/misc.py +++ b/openfisca_core/commons/misc.py @@ -1,20 +1,76 @@ -import numpy +from typing import TypeVar +from openfisca_core.types import ArrayType -def empty_clone(original): - """Create a new empty instance of the same class of the original object.""" - class Dummy(original.__class__): - def __init__(self) -> None: - pass +T = TypeVar("T") + + +def empty_clone(original: T) -> T: + """Creates an empty instance of the same class of the original object. + + Args: + original: An object to clone. + + Returns: + The cloned, empty, object. + + Examples: + >>> Foo = type("Foo", (list,), {}) + >>> foo = Foo([1, 2, 3]) + >>> foo + [1, 2, 3] + + >>> bar = empty_clone(foo) + >>> bar + [] + + >>> isinstance(bar, Foo) + True + + """ + + Dummy: object + new: T + + Dummy = type( + "Dummy", + (original.__class__,), + {"__init__": lambda self: None}, + ) new = Dummy() new.__class__ = original.__class__ return new -def stringify_array(array: numpy.ndarray) -> str: - """ - Generate a clean string representation of a NumPY array. +def stringify_array(array: ArrayType) -> str: + """Generates a clean string representation of a numpy array. + + Args: + array: An array. + + Returns: + :obj:`str`: + "None" if the ``array`` is None, the stringified ``array`` otherwise. + + Examples: + >>> import numpy + + >>> stringify_array(None) + 'None' + + >>> array = numpy.array([10, 20.]) + >>> stringify_array(array) + '[10.0, 20.0]' + + >>> array = numpy.array(["10", "Twenty"]) + >>> stringify_array(array) + '[10, Twenty]' + + >>> array = numpy.array([list, dict(), stringify_array]) + >>> stringify_array(array) + "[, {}, Date: Mon, 20 Sep 2021 00:32:51 +0200 Subject: [PATCH 037/205] Add doc to commons module --- openfisca_core/commons/__init__.py | 88 ++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 23 deletions(-) diff --git a/openfisca_core/commons/__init__.py b/openfisca_core/commons/__init__.py index 42c1ada223..eec40ddec4 100644 --- a/openfisca_core/commons/__init__.py +++ b/openfisca_core/commons/__init__.py @@ -1,29 +1,71 @@ -# Transitional imports to ensure non-breaking changes. -# Could be deprecated in the next major release. -# -# How imports are being used today: -# -# >>> from openfisca_core.module import symbol -# -# The previous example provokes cyclic dependency problems -# that prevent us from modularizing the different components -# of the library so to make them easier to test and to maintain. -# -# How could them be used after the next major release: -# -# >>> from openfisca_core import module -# >>> module.symbol() -# -# And for classes: -# -# >>> from openfisca_core.module import Symbol -# >>> Symbol() -# -# See: https://www.python.org/dev/peps/pep-0008/#imports +"""Common tools for contributors and users. -from .dummy import Dummy # noqa: F401 +The tools included in this sub-package are intented, at the same time, to help +contributors who maintain OpenFisca Core, and to help users building their own +systems. + +Official Public API: + * :class:`.deprecated` + * :func:`.apply_thresholds` + * :func:`.average_rate` + * :func:`.concat` + * :func:`.empty_clone` + * :func:`.marginal_rate` + * :func:`.stringify_array` + * :func:`.switch` + +Deprecated: + * :class:`.Dummy` + +Note: + The ``deprecated`` imports are transitional, as so to ensure non-breaking + changes, and could be definitely removed from the codebase in the next + major release. + +Note: + How imports are being used today:: + + from openfisca_core.commons import * # Bad + from openfisca_core.commons.formulas import switch # Bad + from openfisca_core.commons.decorators import deprecated # Bad + + + The previous examples provoke cyclic dependency problems, that prevents us + from modularizing the different components of the library, so as to make + them easier to test and to maintain. + + How could them be used after the next major release:: + + from openfisca_core import commons + from openfisca_core.commons import deprecated + + deprecated() # Good: import classes as publicly exposed + commons.switch() # Good: use functions as publicly exposed + + .. seealso:: `PEP8#Imports`_ and `OpenFisca's Styleguide`_. + + .. _PEP8#Imports: + https://www.python.org/dev/peps/pep-0008/#imports + + .. _OpenFisca's Styleguide: + https://github.com/openfisca/openfisca-core/blob/master/STYLEGUIDE.md + +""" + +# Official Public API from .decorators import deprecated # noqa: F401 from .formulas import apply_thresholds, concat, switch # noqa: F401 from .misc import empty_clone, stringify_array # noqa: F401 from .rates import average_rate, marginal_rate # noqa: F401 + +__all__ = ["deprecated"] +__all__ = ["apply_thresholds", "concat", "switch", *__all__] +__all__ = ["empty_clone", "stringify_array", *__all__] +__all__ = ["average_rate", "marginal_rate", *__all__] + +# Deprecated + +from .dummy import Dummy # noqa: F401 + +__all__ = ["Dummy", *__all__] From 6578561fda87c630f910a5461cd45b4830dc0d0d Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 20 Sep 2021 00:35:45 +0200 Subject: [PATCH 038/205] Delete redundant tests --- tests/core/test_commons.py | 36 ----------------------- tests/core/test_formula_helpers.py | 47 ------------------------------ tests/core/test_rates.py | 20 ------------- 3 files changed, 103 deletions(-) delete mode 100644 tests/core/test_commons.py delete mode 100644 tests/core/test_formula_helpers.py delete mode 100644 tests/core/test_rates.py diff --git a/tests/core/test_commons.py b/tests/core/test_commons.py deleted file mode 100644 index ddbf30e5a9..0000000000 --- a/tests/core/test_commons.py +++ /dev/null @@ -1,36 +0,0 @@ -import numpy - -from openfisca_core import commons - -import pytest - - -def test_dummy(): - with pytest.warns(DeprecationWarning): - result = commons.Dummy() - assert result - - -def test_empty_clone(): - dummy_class = type("Dummmy", (), {}) - dummy = dummy_class() - - result = commons.empty_clone(dummy) - - assert type(result) == dummy_class - - -def test_stringify_array(): - array = numpy.array([10, 20]) - - result = commons.stringify_array(array) - - assert result == "[10, 20]" - - -def test_stringify_array_when_none(): - array = None - - result = commons.stringify_array(array) - - assert result == "None" diff --git a/tests/core/test_formula_helpers.py b/tests/core/test_formula_helpers.py deleted file mode 100644 index 51bc2a2e20..0000000000 --- a/tests/core/test_formula_helpers.py +++ /dev/null @@ -1,47 +0,0 @@ -# -*- coding: utf-8 -*- - -import numpy -import pytest - -from openfisca_core.formula_helpers import apply_thresholds as apply_thresholds -from openfisca_core.tools import assert_near - - -def test_apply_thresholds_with_too_many_thresholds(): - input = numpy.array([10]) - thresholds = [5, 4] - choice_list = [10] - with pytest.raises(AssertionError): - return apply_thresholds(input, thresholds, choice_list) - - -def test_apply_thresholds_with_too_few_thresholds(): - input = numpy.array([10]) - thresholds = [5] - choice_list = [10, 15, 20] - with pytest.raises(AssertionError): - return apply_thresholds(input, thresholds, choice_list) - - -def test_apply_thresholds(): - input = numpy.array([4, 5, 6, 7, 8]) - thresholds = [5, 7] - choice_list = [10, 15, 20] - result = apply_thresholds(input, thresholds, choice_list) - assert_near(result, [10, 10, 15, 15, 20]) - - -def test_apply_thresholds_with_as_many_thresholds_than_choices(): - input = numpy.array([4, 6, 8]) - thresholds = [5, 7] - choice_list = [10, 20] - result = apply_thresholds(input, thresholds, choice_list) - assert_near(result, [10, 20, 0]) - - -def test_apply_thresholds_with_variable_threshold(): - input = numpy.array([1000, 1000, 1000]) - thresholds = [numpy.array([500, 1500, 1000])] # Only one thresold, but varies with the person - choice_list = [True, False] # True if input <= threshold, false otherwise - result = apply_thresholds(input, thresholds, choice_list) - assert_near(result, [False, True, True]) diff --git a/tests/core/test_rates.py b/tests/core/test_rates.py deleted file mode 100644 index 8ab2170954..0000000000 --- a/tests/core/test_rates.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- - -import numpy - -from openfisca_core.rates import average_rate - - -def test_average_rate(): - '''Compute the average tax rate when the gross income is never zero''' - target = numpy.array([1, 2, 3]) - result = average_rate(target, varying = 2) - expected = numpy.array([.5, 0, -.5]) - numpy.testing.assert_equal(result, expected) - - -def test_average_rate_when_varying_is_zero(): - '''Compute the average tax rate when the varying gross income cross zero (yields infinity)''' - target = numpy.array([1, 2, 3]) - result = average_rate(target, varying = 0) - assert numpy.isinf(result[0]).all() From 949188cb54b91df66f87c7b55b02e201ead187d7 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 23 Sep 2021 20:42:28 +0200 Subject: [PATCH 039/205] Improve wording in the commons module Co-authored-by: Matti Schneider --- openfisca_core/commons/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openfisca_core/commons/__init__.py b/openfisca_core/commons/__init__.py index eec40ddec4..10015e2785 100644 --- a/openfisca_core/commons/__init__.py +++ b/openfisca_core/commons/__init__.py @@ -30,11 +30,11 @@ from openfisca_core.commons.decorators import deprecated # Bad - The previous examples provoke cyclic dependency problems, that prevents us - from modularizing the different components of the library, so as to make + The previous examples provoke cyclic dependency problems, that prevent us + from modularizing the different components of the library, which would make them easier to test and to maintain. - How could them be used after the next major release:: + How they could be used in a future release: from openfisca_core import commons from openfisca_core.commons import deprecated From e96dd4640417b712be38a5e8e16cdf5c3f227b33 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Fri, 24 Sep 2021 19:38:05 +0200 Subject: [PATCH 040/205] Remove deprecation expiration --- openfisca_core/commons/dummy.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openfisca_core/commons/dummy.py b/openfisca_core/commons/dummy.py index 732ed49a65..7cd1951931 100644 --- a/openfisca_core/commons/dummy.py +++ b/openfisca_core/commons/dummy.py @@ -9,10 +9,11 @@ class Dummy: None: ... From 6eb0bdf83a8eec295156bfddc204e05468528f1e Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 27 Sep 2021 15:11:15 +0200 Subject: [PATCH 041/205] Remove decorators --- openfisca_core/commons/__init__.py | 5 +- openfisca_core/commons/decorators.py | 76 ------------------- openfisca_core/commons/dummy.py | 9 ++- .../commons/tests/test_decorators.py | 20 ----- 4 files changed, 8 insertions(+), 102 deletions(-) delete mode 100644 openfisca_core/commons/decorators.py delete mode 100644 openfisca_core/commons/tests/test_decorators.py diff --git a/openfisca_core/commons/__init__.py b/openfisca_core/commons/__init__.py index 10015e2785..fa42930db7 100644 --- a/openfisca_core/commons/__init__.py +++ b/openfisca_core/commons/__init__.py @@ -5,7 +5,6 @@ systems. Official Public API: - * :class:`.deprecated` * :func:`.apply_thresholds` * :func:`.average_rate` * :func:`.concat` @@ -54,13 +53,11 @@ # Official Public API -from .decorators import deprecated # noqa: F401 from .formulas import apply_thresholds, concat, switch # noqa: F401 from .misc import empty_clone, stringify_array # noqa: F401 from .rates import average_rate, marginal_rate # noqa: F401 -__all__ = ["deprecated"] -__all__ = ["apply_thresholds", "concat", "switch", *__all__] +__all__ = ["apply_thresholds", "concat", "switch"] __all__ = ["empty_clone", "stringify_array", *__all__] __all__ = ["average_rate", "marginal_rate", *__all__] diff --git a/openfisca_core/commons/decorators.py b/openfisca_core/commons/decorators.py deleted file mode 100644 index 2041a7f4f7..0000000000 --- a/openfisca_core/commons/decorators.py +++ /dev/null @@ -1,76 +0,0 @@ -import functools -import warnings -import typing -from typing import Any, Callable, TypeVar - -T = Callable[..., Any] -F = TypeVar("F", bound = T) - - -class deprecated: - """Allows (soft) deprecating a functionality of OpenFisca. - - Attributes: - since (:obj:`str`): Since when the functionality is deprecated. - expires (:obj:`str`): When will it be removed forever? - - Args: - since: Since when the functionality is deprecated. - expires: When will it be removed forever? - - Examples: - >>> @deprecated(since = "35.5.0", expires = "in the future") - ... def obsolete(): - ... return "I'm obsolete!" - - >>> repr(obsolete) - '' - - >>> str(obsolete) - '' - - .. versionadded:: 35.6.0 - - """ - - since: str - expires: str - - def __init__(self, since: str, expires: str) -> None: - self.since = since - self.expires = expires - - def __call__(self, function: F) -> F: - """Wraps a function to return another one, decorated. - - Args: - function: The function or method to decorate. - - Returns: - :obj:`callable`: The decorated function. - - Examples: - >>> def obsolete(): - ... return "I'm obsolete!" - - >>> decorator = deprecated( - ... since = "35.5.0", - ... expires = "in the future", - ... ) - - >>> decorator(obsolete) - - - """ - - def wrapper(*args: Any, **kwds: Any) -> Any: - message = [ - f"{function.__qualname__} has been deprecated since", - f"version {self.since}, and will be removed in", - f"{self.expires}.", - ] - warnings.warn(" ".join(message), DeprecationWarning) - return function(*args, **kwds) - - functools.update_wrapper(wrapper, function) - return typing.cast(F, wrapper) diff --git a/openfisca_core/commons/dummy.py b/openfisca_core/commons/dummy.py index 7cd1951931..d1e9fbe814 100644 --- a/openfisca_core/commons/dummy.py +++ b/openfisca_core/commons/dummy.py @@ -1,4 +1,4 @@ -from .decorators import deprecated +import warnings class Dummy: @@ -14,6 +14,11 @@ class Dummy: """ - @deprecated(since = "34.7.0", expires = "in the future") def __init__(self) -> None: + message = [ + "The 'Dummy' class has been deprecated since version 34.7.0,", + "and will be removed in the future.", + ] + warnings.warn(" ".join(message), DeprecationWarning) + ... diff --git a/openfisca_core/commons/tests/test_decorators.py b/openfisca_core/commons/tests/test_decorators.py deleted file mode 100644 index 04c5ce3d91..0000000000 --- a/openfisca_core/commons/tests/test_decorators.py +++ /dev/null @@ -1,20 +0,0 @@ -import re - -import pytest - -from openfisca_core.commons import deprecated - - -def test_deprecated(): - """The decorated function throws a deprecation warning when used.""" - - since = "yesterday" - expires = "doomsday" - match = re.compile(f"^.*{since}.*{expires}.*$") - - @deprecated(since, expires) - def function(a: int, b: float) -> float: - return a + b - - with pytest.warns(DeprecationWarning, match = match): - assert function(1, 2.) == 3. From 37f1cdcce882c1f268346ca709eb36711cab9e55 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 02:58:08 +0200 Subject: [PATCH 042/205] Add doc checks to setup.cfg --- setup.cfg | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 880fc8d31c..502b3a86da 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,14 +10,13 @@ extend-ignore = D ignore = E128,E251,F403,F405,E501,W503,W504 in-place = true include-in-doctest = openfisca_core/commons openfisca_core/types -jobs = 0 rst-directives = attribute, deprecated, seealso, versionadded, versionchanged rst-roles = any, attr, class, exc, func, meth, obj strictness = short [pylint.message_control] disable = all -jobs = 0 +enable = C0115,C0116,R0401 score = no [tool:pytest] From 7ce2ccceea1f8a4301cc45e50798dd7f11577c7c Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 03:01:02 +0200 Subject: [PATCH 043/205] Adapt coverage config --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 502b3a86da..bdef34b16e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,7 +20,7 @@ enable = C0115,C0116,R0401 score = no [tool:pytest] -addopts = --cov-report=term-missing:skip-covered --cov-fail-under=78.69 --doctest-modules --disable-pytest-warnings --showlocals +addopts = --cov-report=term-missing:skip-covered --cov-fail-under=78.58 --doctest-modules --disable-pytest-warnings --showlocals doctest_optionflags = ELLIPSIS IGNORE_EXCEPTION_DETAIL NUMBER NORMALIZE_WHITESPACE python_files = **/*.py testpaths = openfisca_core/commons openfisca_core/types tests From 7f15099c1c2f5c5c3844740c7c5c0f841064e6f6 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 03:16:17 +0200 Subject: [PATCH 044/205] Add explanation to checks in Makefile --- setup.cfg | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index bdef34b16e..0512b02b34 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,8 +1,8 @@ -; E128/133: We prefer hang-closing visual indents -; E251: We prefer `function(x = 1)` over `function(x=1)` -; E501: We do not enforce a maximum line length -; F403/405: We ignore * imports -; W503/504: We break lines before binary operators (Knuth's style) +; E128/133: We prefer hang-closing visual indents +; E251: We prefer `function(x = 1)` over `function(x=1)` +; E501: We do not enforce a maximum line length +; F403/405: We ignore * imports +; W503/504: We break lines before binary operators (Knuth's style) [flake8] hang-closing = true @@ -14,6 +14,10 @@ rst-directives = attribute, deprecated, seealso, versionadded, versionchang rst-roles = any, attr, class, exc, func, meth, obj strictness = short +; C0115: We document classes. +; C0116: We document public functions. +; R0401: We avoid cyclic imports —required for unit/doc tests. + [pylint.message_control] disable = all enable = C0115,C0116,R0401 From b215b30ad5b2f7edae6d80a7a1f61af691664a18 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 03:28:25 +0200 Subject: [PATCH 045/205] Remove unnecessary ellipsis --- openfisca_core/commons/dummy.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/openfisca_core/commons/dummy.py b/openfisca_core/commons/dummy.py index d1e9fbe814..14515fd7e0 100644 --- a/openfisca_core/commons/dummy.py +++ b/openfisca_core/commons/dummy.py @@ -20,5 +20,3 @@ def __init__(self) -> None: "and will be removed in the future.", ] warnings.warn(" ".join(message), DeprecationWarning) - - ... From e2e1fe944913226bc8df2578587b6ea19e9576b4 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 16:02:01 +0200 Subject: [PATCH 046/205] Rollback commons module doc --- openfisca_core/commons/__init__.py | 86 ++++++++---------------------- 1 file changed, 23 insertions(+), 63 deletions(-) diff --git a/openfisca_core/commons/__init__.py b/openfisca_core/commons/__init__.py index fa42930db7..db41ed1874 100644 --- a/openfisca_core/commons/__init__.py +++ b/openfisca_core/commons/__init__.py @@ -1,68 +1,28 @@ -"""Common tools for contributors and users. +# Transitional imports to ensure non-breaking changes. +# Could be deprecated in the next major release. +# +# How imports are being used today: +# +# >>> from openfisca_core.module import symbol +# +# The previous example provokes cyclic dependency problems +# that prevent us from modularizing the different components +# of the library so to make them easier to test and to maintain. +# +# How could them be used after the next major release: +# +# >>> from openfisca_core import module +# >>> module.symbol() +# +# And for classes: +# +# >>> from openfisca_core.module import Symbol +# >>> Symbol() +# +# See: https://www.python.org/dev/peps/pep-0008/#imports -The tools included in this sub-package are intented, at the same time, to help -contributors who maintain OpenFisca Core, and to help users building their own -systems. - -Official Public API: - * :func:`.apply_thresholds` - * :func:`.average_rate` - * :func:`.concat` - * :func:`.empty_clone` - * :func:`.marginal_rate` - * :func:`.stringify_array` - * :func:`.switch` - -Deprecated: - * :class:`.Dummy` - -Note: - The ``deprecated`` imports are transitional, as so to ensure non-breaking - changes, and could be definitely removed from the codebase in the next - major release. - -Note: - How imports are being used today:: - - from openfisca_core.commons import * # Bad - from openfisca_core.commons.formulas import switch # Bad - from openfisca_core.commons.decorators import deprecated # Bad - - - The previous examples provoke cyclic dependency problems, that prevent us - from modularizing the different components of the library, which would make - them easier to test and to maintain. - - How they could be used in a future release: - - from openfisca_core import commons - from openfisca_core.commons import deprecated - - deprecated() # Good: import classes as publicly exposed - commons.switch() # Good: use functions as publicly exposed - - .. seealso:: `PEP8#Imports`_ and `OpenFisca's Styleguide`_. - - .. _PEP8#Imports: - https://www.python.org/dev/peps/pep-0008/#imports - - .. _OpenFisca's Styleguide: - https://github.com/openfisca/openfisca-core/blob/master/STYLEGUIDE.md - -""" - -# Official Public API +from .dummy import Dummy # noqa: F401 from .formulas import apply_thresholds, concat, switch # noqa: F401 from .misc import empty_clone, stringify_array # noqa: F401 from .rates import average_rate, marginal_rate # noqa: F401 - -__all__ = ["apply_thresholds", "concat", "switch"] -__all__ = ["empty_clone", "stringify_array", *__all__] -__all__ = ["average_rate", "marginal_rate", *__all__] - -# Deprecated - -from .dummy import Dummy # noqa: F401 - -__all__ = ["Dummy", *__all__] From 851b77044b1174ec9b46525d84d9f986b57d6c93 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 16:04:19 +0200 Subject: [PATCH 047/205] Rollback dummy doc --- openfisca_core/commons/dummy.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/openfisca_core/commons/dummy.py b/openfisca_core/commons/dummy.py index 14515fd7e0..4136a0d429 100644 --- a/openfisca_core/commons/dummy.py +++ b/openfisca_core/commons/dummy.py @@ -2,17 +2,7 @@ class Dummy: - """A class that did nothing. - - Examples: - >>> Dummy() - None: message = [ @@ -20,3 +10,4 @@ def __init__(self) -> None: "and will be removed in the future.", ] warnings.warn(" ".join(message), DeprecationWarning) + pass From 778655d0422bacb9430e315b1447af5559b24828 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 16:14:55 +0200 Subject: [PATCH 048/205] Rollback formulas doc --- openfisca_core/commons/formulas.py | 91 +++++------------------------- setup.cfg | 2 +- 2 files changed, 16 insertions(+), 77 deletions(-) diff --git a/openfisca_core/commons/formulas.py b/openfisca_core/commons/formulas.py index a750717f1d..5b49387fde 100644 --- a/openfisca_core/commons/formulas.py +++ b/openfisca_core/commons/formulas.py @@ -1,33 +1,9 @@ -from typing import Any, Dict, List - import numpy -from openfisca_core.types import ArrayLike, ArrayType - - -def apply_thresholds( - input: ArrayType[float], - thresholds: ArrayLike[float], - choices: ArrayLike[float], - ) -> ArrayType[float]: - """Makes a choice based on an input and thresholds. - - From list of ``choices``, it selects one of them based on a list of - inputs, depending on the position of each ``input`` whithin a list of - ``thresholds``. It does so for each ``input`` provided. - - Args: - input: A list of inputs to make a choice. - thresholds: A list of thresholds to choose. - choices: A list of the possible choices. - - Returns: - :obj:`numpy.ndarray` of :obj:`float`: - A list of the choices made. - Raises: - :exc:`AssertionError`: When the number of ``thresholds`` (t) and the - number of choices (c) are not either t == c or t == c - 1. +def apply_thresholds(input, thresholds, choices): + """ + Return one of the choices depending on the input position compared to thresholds, for each input. Examples: >>> input = numpy.array([4, 5, 6, 7, 8]) @@ -38,34 +14,17 @@ def apply_thresholds( """ - condlist: List[ArrayType[bool]] - condlist = [input <= threshold for threshold in thresholds] - if len(condlist) == len(choices) - 1: - # If a choice is provided for input > highest threshold, last condition - # must be true to return it. + # If a choice is provided for input > highest threshold, last condition must be true to return it. condlist += [True] - assert len(condlist) == len(choices), \ - " ".join([ - "apply_thresholds must be called with the same number of", - "thresholds than choices, or one more choice", - ]) - + "apply_thresholds must be called with the same number of thresholds than choices, or one more choice" return numpy.select(condlist, choices) -def concat(this: ArrayLike[str], that: ArrayLike[str]) -> ArrayType[str]: - """Concatenates the values of two arrays. - - Args: - this: An array to concatenate. - that: Another array to concatenate. - - Returns: - :obj:`numpy.ndarray` of :obj:`float`: - An array with the concatenated values. +def concat(this, that): + """ Examples: >>> this = ["this", "that"] @@ -75,36 +34,18 @@ def concat(this: ArrayLike[str], that: ArrayLike[str]) -> ArrayType[str]: """ - if isinstance(this, numpy.ndarray) and \ - not numpy.issubdtype(this.dtype, numpy.str_): + if isinstance(this, numpy.ndarray) and not numpy.issubdtype(this.dtype, numpy.str): this = this.astype('str') - - if isinstance(that, numpy.ndarray) and \ - not numpy.issubdtype(that.dtype, numpy.str_): + if isinstance(that, numpy.ndarray) and not numpy.issubdtype(that.dtype, numpy.str): that = that.astype('str') - return numpy.char.add(this, that) - - -def switch( - conditions: ArrayType[float], - value_by_condition: Dict[float, Any], - ) -> ArrayType[float]: - """Reproduces a switch statement. + return numpy.core.defchararray.add(this, that) - Given an array of conditions, returns an array of the same size, - replacing each condition item by the corresponding given value. - Args: - conditions: An array of conditions. - value_by_condition: Values to replace for each condition. - - Returns: - :obj:`numpy.ndarray` of :obj:`float`: - An array with the replaced values. - - Raises: - :exc:`AssertionError`: When ``value_by_condition`` is empty. +def switch(conditions, value_by_condition): + ''' + Reproduces a switch statement: given an array of conditions, return an array of the same size replacing each + condition item by the corresponding given value. Examples: >>> conditions = numpy.array([1, 1, 1, 2]) @@ -112,14 +53,12 @@ def switch( >>> switch(conditions, value_by_condition) array([80, 80, 80, 90]) - """ + ''' assert len(value_by_condition) > 0, \ "switch must be called with at least one value" - condlist = [ conditions == condition for condition in value_by_condition.keys() ] - return numpy.select(condlist, value_by_condition.values()) diff --git a/setup.cfg b/setup.cfg index 0512b02b34..3b09cc591c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -24,7 +24,7 @@ enable = C0115,C0116,R0401 score = no [tool:pytest] -addopts = --cov-report=term-missing:skip-covered --cov-fail-under=78.58 --doctest-modules --disable-pytest-warnings --showlocals +addopts = --cov-report=term-missing:skip-covered --cov-fail-under=78.55 --doctest-modules --disable-pytest-warnings --showlocals doctest_optionflags = ELLIPSIS IGNORE_EXCEPTION_DETAIL NUMBER NORMALIZE_WHITESPACE python_files = **/*.py testpaths = openfisca_core/commons openfisca_core/types tests From fa398aaf2dc0be384901f754f9eb5735230b3d18 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 16:19:05 +0200 Subject: [PATCH 049/205] Rollback misc doc --- openfisca_core/commons/misc.py | 40 ++++++++-------------------------- setup.cfg | 3 +-- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/openfisca_core/commons/misc.py b/openfisca_core/commons/misc.py index 5056389c6e..5dd54f70c5 100644 --- a/openfisca_core/commons/misc.py +++ b/openfisca_core/commons/misc.py @@ -1,18 +1,8 @@ -from typing import TypeVar +import numpy -from openfisca_core.types import ArrayType -T = TypeVar("T") - - -def empty_clone(original: T) -> T: - """Creates an empty instance of the same class of the original object. - - Args: - original: An object to clone. - - Returns: - The cloned, empty, object. +def empty_clone(original): + """Create a new empty instance of the same class of the original object. Examples: >>> Foo = type("Foo", (list,), {}) @@ -29,33 +19,21 @@ def empty_clone(original: T) -> T: """ - Dummy: object - new: T - - Dummy = type( - "Dummy", - (original.__class__,), - {"__init__": lambda self: None}, - ) + class Dummy(original.__class__): + def __init__(self) -> None: + pass new = Dummy() new.__class__ = original.__class__ return new -def stringify_array(array: ArrayType) -> str: - """Generates a clean string representation of a numpy array. - - Args: - array: An array. - - Returns: - :obj:`str`: - "None" if the ``array`` is None, the stringified ``array`` otherwise. +def stringify_array(array: numpy.ndarray) -> str: + """ + Generate a clean string representation of a NumPY array. Examples: >>> import numpy - >>> stringify_array(None) 'None' diff --git a/setup.cfg b/setup.cfg index 3b09cc591c..2035a86a4a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -14,13 +14,12 @@ rst-directives = attribute, deprecated, seealso, versionadded, versionchang rst-roles = any, attr, class, exc, func, meth, obj strictness = short -; C0115: We document classes. ; C0116: We document public functions. ; R0401: We avoid cyclic imports —required for unit/doc tests. [pylint.message_control] disable = all -enable = C0115,C0116,R0401 +enable = C0116,R0401 score = no [tool:pytest] From 21de68160130768acc77cb22089cfb135f3442bc Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 16:22:13 +0200 Subject: [PATCH 050/205] Rollback rates doc --- openfisca_core/commons/rates.py | 107 +++++--------------------------- setup.cfg | 17 ++--- 2 files changed, 25 insertions(+), 99 deletions(-) diff --git a/openfisca_core/commons/rates.py b/openfisca_core/commons/rates.py index 487abd3aea..9148a1ec4d 100644 --- a/openfisca_core/commons/rates.py +++ b/openfisca_core/commons/rates.py @@ -1,36 +1,13 @@ -from typing import Optional - import numpy -from openfisca_core.types import ArrayLike, ArrayType - - -def average_rate( - target: ArrayType[float], - varying: ArrayLike[float], - trim: Optional[ArrayLike[float]] = None, - ) -> ArrayType[float]: - """Computes the average rate of a target net income. - - Given a ``target`` net income, and according to the ``varying`` gross - income. Optionally, a ``trim`` can be applied consisting on the lower and - upper bounds of the average rate to be computed. - - Note: - Usually, ``target`` and ``varying`` are the same size. - - Args: - target: The targeted net income. - varying: The varying gross income. - trim: The lower and upper bounds of the average rate. - Returns: - :obj:`numpy.ndarray` of :obj:`float`: +def average_rate(target = None, varying = None, trim = None): + ''' + Computes the average rate of a targeted net income, according to the varying gross income. - The average rate for each target. - - When ``trim`` is provided, values that are out of the provided bounds - are replaced by :obj:`numpy.nan`. + :param target: Targeted net income, numerator + :param varying: Varying gross income, denominator + :param trim: Lower and upper bound of average rate to return Examples: >>> target = numpy.array([1, 2, 3]) @@ -39,55 +16,18 @@ def average_rate( >>> average_rate(target, varying, trim) array([ nan, 0. , -0.5]) - """ - - average_rate: ArrayType[float] + ''' average_rate = 1 - target / varying - if trim is not None: - - average_rate = numpy.where( - average_rate <= max(trim), - average_rate, - numpy.nan, - ) - - average_rate = numpy.where( - average_rate >= min(trim), - average_rate, - numpy.nan, - ) + average_rate = numpy.where(average_rate <= max(trim), average_rate, numpy.nan) + average_rate = numpy.where(average_rate >= min(trim), average_rate, numpy.nan) return average_rate -def marginal_rate( - target: ArrayType[float], - varying: ArrayType[float], - trim: Optional[ArrayLike[float]] = None, - ) -> ArrayType[float]: - """Computes the marginal rate of a target net income. - - Given a ``target`` net income, and according to the ``varying`` gross - income. Optionally, a ``trim`` can be applied consisting of the lower and - upper bounds of the marginal rate to be computed. - - Note: - Usually, ``target`` and ``varying`` are the same size. - - Args: - target: The targeted net income. - varying: The varying gross income. - trim: The lower and upper bounds of the marginal rate. - - Returns: - :obj:`numpy.ndarray` of :obj:`float`: - - The marginal rate for each target. - - When ``trim`` is provided, values that are out of the provided bounds - are replaced by :obj:`numpy.nan`. +def marginal_rate(target = None, varying = None, trim = None): + """ Examples: >>> target = numpy.array([1, 2, 3]) @@ -98,27 +38,10 @@ def marginal_rate( """ - marginal_rate: ArrayType[float] - - marginal_rate = ( - + 1 - - (target[:-1] - - target[1:]) / (varying[:-1] - - varying[1:]) - ) - + # target: numerator, varying: denominator + marginal_rate = 1 - (target[:-1] - target[1:]) / (varying[:-1] - varying[1:]) if trim is not None: - - marginal_rate = numpy.where( - marginal_rate <= max(trim), - marginal_rate, - numpy.nan, - ) - - marginal_rate = numpy.where( - marginal_rate >= min(trim), - marginal_rate, - numpy.nan, - ) + marginal_rate = numpy.where(marginal_rate <= max(trim), marginal_rate, numpy.nan) + marginal_rate = numpy.where(marginal_rate >= min(trim), marginal_rate, numpy.nan) return marginal_rate diff --git a/setup.cfg b/setup.cfg index 2035a86a4a..20cdf46bfc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,12 +1,15 @@ -; E128/133: We prefer hang-closing visual indents -; E251: We prefer `function(x = 1)` over `function(x=1)` -; E501: We do not enforce a maximum line length -; F403/405: We ignore * imports -; W503/504: We break lines before binary operators (Knuth's style) +; DXXX: http://www.pydocstyle.org/en/2.1.1/error_codes.html#grouping. +; DAR101: We do not (yet) document class/function attributes/arguments. +; DAR201: We do not (yet) document method/function returns. +; E128/133: We prefer hang-closing visual indents. +; E251: We prefer `function(x = 1)` over `function(x=1)`. +; E501: We do not enforce a maximum line length. +; F403/405: We ignore * imports. +; W503/504: We break lines before binary operators (Knuth's style). [flake8] hang-closing = true -extend-ignore = D +extend-ignore = D,DAR101,DAR201 ignore = E128,E251,F403,F405,E501,W503,W504 in-place = true include-in-doctest = openfisca_core/commons openfisca_core/types @@ -23,7 +26,7 @@ enable = C0116,R0401 score = no [tool:pytest] -addopts = --cov-report=term-missing:skip-covered --cov-fail-under=78.55 --doctest-modules --disable-pytest-warnings --showlocals +addopts = --cov-report=term-missing:skip-covered --cov-fail-under=78.54 --doctest-modules --disable-pytest-warnings --showlocals doctest_optionflags = ELLIPSIS IGNORE_EXCEPTION_DETAIL NUMBER NORMALIZE_WHITESPACE python_files = **/*.py testpaths = openfisca_core/commons openfisca_core/types tests From f3b5ed3f715d3893817ec2b995566dfa483bf10f Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 16:34:12 +0200 Subject: [PATCH 051/205] Rollback mypy update --- setup.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 432205cfd9..35c296b4b0 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,6 @@ general_requirements = [ 'dpath >= 1.5.0, < 2.0.0', - 'nptyping >= 1.4.3, < 2.0.0', 'numexpr >= 2.7.0, <= 3.0', 'numpy >= 1.11, < 1.21', 'psutil >= 5.4.7, < 6.0.0', @@ -32,13 +31,11 @@ 'flake8-docstrings == 1.6.0', 'flake8-print >= 3.1.0, < 4.0.0', 'flake8-rst-docstrings < 1.0.0', - 'mypy == 0.910', - 'pylint == 2.10.2', + 'mypy >= 0.701, < 0.800', 'openfisca-country-template >= 3.10.0, < 4.0.0', 'openfisca-extension-template >= 1.2.0rc0, < 2.0.0', + 'pylint == 2.10.2', 'pytest-cov >= 2.6.1, < 3.0.0', - 'types-PyYAML == 5.4.10', - 'types-setuptools == 57.0.2', ] + api_requirements setup( From f0d1b96c8d68e4f85257632474374b791fa28375 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 16:37:50 +0200 Subject: [PATCH 052/205] Rollback add types --- openfisca_core/types/__init__.py | 46 ----------------- openfisca_core/types/data_types/__init__.py | 1 - openfisca_core/types/data_types/arrays.py | 56 --------------------- setup.cfg | 4 +- 4 files changed, 2 insertions(+), 105 deletions(-) delete mode 100644 openfisca_core/types/__init__.py delete mode 100644 openfisca_core/types/data_types/__init__.py delete mode 100644 openfisca_core/types/data_types/arrays.py diff --git a/openfisca_core/types/__init__.py b/openfisca_core/types/__init__.py deleted file mode 100644 index 36dabd1899..0000000000 --- a/openfisca_core/types/__init__.py +++ /dev/null @@ -1,46 +0,0 @@ -"""Data types and protocols used by OpenFisca Core. - -The type definitions included in this sub-package are intented mostly for -contributors, to help them better document contracts and behaviours. - -Official Public API: - * ``ArrayLike`` - * :attr:`.ArrayType` - -Note: - How imports are being used today:: - - from openfisca_core.types import * # Bad - from openfisca_core.types.data_types.arrays import ArrayLike # Bad - - - The previous examples provoke cyclic dependency problems, that prevents us - from modularizing the different components of the library, so as to make - them easier to test and to maintain. - - How could them be used after the next major release:: - - from openfisca_core.types import ArrayLike - - ArrayLike # Good: import types as publicly exposed - - .. seealso:: `PEP8#Imports`_ and `OpenFisca's Styleguide`_. - - .. _PEP8#Imports: - https://www.python.org/dev/peps/pep-0008/#imports - - .. _OpenFisca's Styleguide: - https://github.com/openfisca/openfisca-core/blob/master/STYLEGUIDE.md - -""" - -# Official Public API - -from .data_types import ( # noqa: F401 - ArrayLike, - ArrayType, - ) - -#: Official Public API - -__all__ = ["ArrayLike", "ArrayType"] diff --git a/openfisca_core/types/data_types/__init__.py b/openfisca_core/types/data_types/__init__.py deleted file mode 100644 index 6dd38194e3..0000000000 --- a/openfisca_core/types/data_types/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .arrays import ArrayLike, ArrayType # noqa: F401 diff --git a/openfisca_core/types/data_types/arrays.py b/openfisca_core/types/data_types/arrays.py deleted file mode 100644 index 3e941b4ab1..0000000000 --- a/openfisca_core/types/data_types/arrays.py +++ /dev/null @@ -1,56 +0,0 @@ -from typing import Sequence, TypeVar, Union - -from nptyping import NDArray as ArrayType - -T = TypeVar("T", bool, bytes, float, int, object, str) - -A = Union[ - ArrayType[bool], - ArrayType[bytes], - ArrayType[float], - ArrayType[int], - ArrayType[object], - ArrayType[str], - ] - -ArrayLike = Union[A, Sequence[T]] -""":obj:`typing.Generic`: Type of any castable to :class:`numpy.ndarray`. - -These include any :obj:`numpy.ndarray` and sequences (like -:obj:`list`, :obj:`tuple`, and so on). - -Examples: - >>> ArrayLike[float] - typing.Union[numpy.ndarray, typing.Sequence[float]] - - >>> ArrayLike[str] - typing.Union[numpy.ndarray, typing.Sequence[str]] - -Note: - It is possible since numpy version 1.21 to specify the type of an - array, thanks to `numpy.typing.NDArray`_:: - - from numpy.typing import NDArray - NDArray[numpy.float64] - - `mypy`_ provides `duck type compatibility`_, so an :obj:`int` is - considered to be valid whenever a :obj:`float` is expected. - -Todo: - * Refactor once numpy version >= 1.21 is used. - -.. versionadded:: 35.5.0 - -.. versionchanged:: 35.6.0 - Moved to :mod:`.types` - -.. _mypy: - https://mypy.readthedocs.io/en/stable/ - -.. _duck type compatibility: - https://mypy.readthedocs.io/en/stable/duck_type_compatibility.html - -.. _numpy.typing.NDArray: - https://numpy.org/doc/stable/reference/typing.html#numpy.typing.NDArray - -""" diff --git a/setup.cfg b/setup.cfg index 20cdf46bfc..c8bcec9fa9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,10 +26,10 @@ enable = C0116,R0401 score = no [tool:pytest] -addopts = --cov-report=term-missing:skip-covered --cov-fail-under=78.54 --doctest-modules --disable-pytest-warnings --showlocals +addopts = --cov-report=term-missing:skip-covered --cov-fail-under=78.50 --doctest-modules --disable-pytest-warnings --showlocals doctest_optionflags = ELLIPSIS IGNORE_EXCEPTION_DETAIL NUMBER NORMALIZE_WHITESPACE python_files = **/*.py -testpaths = openfisca_core/commons openfisca_core/types tests +testpaths = openfisca_core/commons tests [mypy] ignore_missing_imports = True From 1577293ac0cfdc474673f637e750b7502a0e7db3 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 16:42:33 +0200 Subject: [PATCH 053/205] Remove typing extensions --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 35c296b4b0..dec6f2bcf6 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,6 @@ 'pytest >= 4.4.1, < 6.0.0', # For openfisca test 'PyYAML >= 3.10', 'sortedcontainers == 2.2.2', - 'typing-extensions >= 3.0.0.0, < 4.0.0.0', ] api_requirements = [ From f70e66f096977ec3e345c3184976dcd4410fe8bd Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 7 Oct 2021 15:31:58 +0200 Subject: [PATCH 054/205] Apply suggestions from code review Co-authored-by: Matti Schneider --- openfisca_tasks/lint.mk | 12 ++++++------ setup.cfg | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/openfisca_tasks/lint.mk b/openfisca_tasks/lint.mk index 2e52457926..a2fe4b03a0 100644 --- a/openfisca_tasks/lint.mk +++ b/openfisca_tasks/lint.mk @@ -1,5 +1,5 @@ ## Lint the codebase. -lint: check-syntax-errors check-style lint-styling-doc check-types +lint: check-syntax-errors check-style lint-doc check-types @$(call print_pass,$@:) ## Compile python files to check for syntax errors. @@ -15,18 +15,18 @@ check-style: $(shell git ls-files "*.py") @$(call print_pass,$@:) ## Run linters to check for syntax and style errors in the doc. -lint-styling-doc: \ - lint-styling-doc-commons \ - lint-styling-doc-types \ +lint-doc: \ + lint-doc-commons \ + lint-doc-types \ ; ## Run linters to check for syntax and style errors in the doc. -lint-styling-doc-%: +lint-doc-%: @## These checks are exclusively related to doc/strings/test. @## @## They can be integrated into setup.cfg once all checks pass. @## The reason they're here is because otherwise we wouldn't be - @## able to integrate documentation improvements progresively. + @## able to integrate documentation improvements incrementally. @## @## D101: Each class has to have at least one doctest. @## D102: Each public method has to have at least one doctest. diff --git a/setup.cfg b/setup.cfg index c8bcec9fa9..75004da81c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,4 @@ -; DXXX: http://www.pydocstyle.org/en/2.1.1/error_codes.html#grouping. +; DXXX: We do not (yet) check docstrings (see https://www.pydocstyle.org/en/2.1.1/error_codes.html#grouping). ; DAR101: We do not (yet) document class/function attributes/arguments. ; DAR201: We do not (yet) document method/function returns. ; E128/133: We prefer hang-closing visual indents. @@ -26,7 +26,7 @@ enable = C0116,R0401 score = no [tool:pytest] -addopts = --cov-report=term-missing:skip-covered --cov-fail-under=78.50 --doctest-modules --disable-pytest-warnings --showlocals +addopts = --cov-report=term-missing:skip-covered --doctest-modules --disable-pytest-warnings --showlocals doctest_optionflags = ELLIPSIS IGNORE_EXCEPTION_DETAIL NUMBER NORMALIZE_WHITESPACE python_files = **/*.py testpaths = openfisca_core/commons tests From 8e8efe4897aa4200aec2b9f052cb1d2669464b21 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Mon, 20 Sep 2021 00:37:49 +0200 Subject: [PATCH 055/205] Bump patch to 35.5.4 --- CHANGELOG.md | 11 +++++++++++ setup.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fed09d73c6..f6a7f9b5dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +### 35.5.4 [#1033](https://github.com/openfisca/openfisca-core/pull/1033) + +#### Bug Fixes + +- Fix doctests of the commons module + +#### Dependencies + +- `darglint`, `flake8-docstrings`, & `pylint` + - For automatic docstring linting & validation. + ### 35.5.3 [#1020](https://github.com/openfisca/openfisca-core/pull/1020) #### Technical changes diff --git a/setup.py b/setup.py index dec6f2bcf6..66b49c1377 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ setup( name = 'OpenFisca-Core', - version = '35.5.3', + version = '35.5.4', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From 39adeaf44d715ea30e98d1e62f93f797a6a416f6 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 15:39:01 +0200 Subject: [PATCH 056/205] Add tasks to lint the doc --- openfisca_tasks/lint.mk | 10 +++++----- openfisca_tasks/publish.mk | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/openfisca_tasks/lint.mk b/openfisca_tasks/lint.mk index a2fe4b03a0..99ecf0d6d3 100644 --- a/openfisca_tasks/lint.mk +++ b/openfisca_tasks/lint.mk @@ -26,12 +26,12 @@ lint-doc-%: @## @## They can be integrated into setup.cfg once all checks pass. @## The reason they're here is because otherwise we wouldn't be - @## able to integrate documentation improvements incrementally. + @## able to integrate documentation improvements progresively. @## - @## D101: Each class has to have at least one doctest. - @## D102: Each public method has to have at least one doctest. - @## D103: Each public function has to have at least one doctest. - @## DARXXX: https://github.com/terrencepreilly/darglint#error-codes. + @## D101: Missing docstring in public class. + @## D102: Missing docstring in public method. + @## D103: Missing docstring in public function. + @## DAR: https://github.com/terrencepreilly/darglint#error-codes. @## @$(call print_help,$(subst $*,%,$@:)) @flake8 --select=D101,D102,D103,DAR openfisca_core/$* diff --git a/openfisca_tasks/publish.mk b/openfisca_tasks/publish.mk index ac0ef2c053..2bcd2c0ba7 100644 --- a/openfisca_tasks/publish.mk +++ b/openfisca_tasks/publish.mk @@ -5,3 +5,4 @@ build: @$(call print_help,$@:) @python setup.py bdist_wheel @find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \; + @$(call print_pass,$@:) From 5123590f147d5246db4a652903a3e12bfad25948 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 15:44:30 +0200 Subject: [PATCH 057/205] Add config to lint documentation --- openfisca_tasks/lint.mk | 5 ----- setup.cfg | 14 ++++++-------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/openfisca_tasks/lint.mk b/openfisca_tasks/lint.mk index 99ecf0d6d3..886072bb2b 100644 --- a/openfisca_tasks/lint.mk +++ b/openfisca_tasks/lint.mk @@ -28,11 +28,6 @@ lint-doc-%: @## The reason they're here is because otherwise we wouldn't be @## able to integrate documentation improvements progresively. @## - @## D101: Missing docstring in public class. - @## D102: Missing docstring in public method. - @## D103: Missing docstring in public function. - @## DAR: https://github.com/terrencepreilly/darglint#error-codes. - @## @$(call print_help,$(subst $*,%,$@:)) @flake8 --select=D101,D102,D103,DAR openfisca_core/$* @pylint openfisca_core/$* diff --git a/setup.cfg b/setup.cfg index 75004da81c..213867581a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,15 +1,16 @@ -; DXXX: We do not (yet) check docstrings (see https://www.pydocstyle.org/en/2.1.1/error_codes.html#grouping). -; DAR101: We do not (yet) document class/function attributes/arguments. -; DAR201: We do not (yet) document method/function returns. +; C011X: We (progressively) document the code base. +; D10X: We (progressively) check docstrings (see https://www.pydocstyle.org/en/2.1.1/error_codes.html#grouping). +; DARXXX: We (progressively) check docstrings (see https://github.com/terrencepreilly/darglint#error-codes). ; E128/133: We prefer hang-closing visual indents. ; E251: We prefer `function(x = 1)` over `function(x=1)`. ; E501: We do not enforce a maximum line length. ; F403/405: We ignore * imports. +; R0401: We avoid cyclic imports —required for unit/doc tests. ; W503/504: We break lines before binary operators (Knuth's style). [flake8] +extend-ignore = D hang-closing = true -extend-ignore = D,DAR101,DAR201 ignore = E128,E251,F403,F405,E501,W503,W504 in-place = true include-in-doctest = openfisca_core/commons openfisca_core/types @@ -17,12 +18,9 @@ rst-directives = attribute, deprecated, seealso, versionadded, versionchang rst-roles = any, attr, class, exc, func, meth, obj strictness = short -; C0116: We document public functions. -; R0401: We avoid cyclic imports —required for unit/doc tests. - [pylint.message_control] disable = all -enable = C0116,R0401 +enable = C0115,C0116,R0401 score = no [tool:pytest] From fd64557cd7a322861ad1672628614703f6878b54 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 15:45:46 +0200 Subject: [PATCH 058/205] Add doc to commons module --- openfisca_core/commons/__init__.py | 86 ++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 23 deletions(-) diff --git a/openfisca_core/commons/__init__.py b/openfisca_core/commons/__init__.py index db41ed1874..fa42930db7 100644 --- a/openfisca_core/commons/__init__.py +++ b/openfisca_core/commons/__init__.py @@ -1,28 +1,68 @@ -# Transitional imports to ensure non-breaking changes. -# Could be deprecated in the next major release. -# -# How imports are being used today: -# -# >>> from openfisca_core.module import symbol -# -# The previous example provokes cyclic dependency problems -# that prevent us from modularizing the different components -# of the library so to make them easier to test and to maintain. -# -# How could them be used after the next major release: -# -# >>> from openfisca_core import module -# >>> module.symbol() -# -# And for classes: -# -# >>> from openfisca_core.module import Symbol -# >>> Symbol() -# -# See: https://www.python.org/dev/peps/pep-0008/#imports +"""Common tools for contributors and users. -from .dummy import Dummy # noqa: F401 +The tools included in this sub-package are intented, at the same time, to help +contributors who maintain OpenFisca Core, and to help users building their own +systems. + +Official Public API: + * :func:`.apply_thresholds` + * :func:`.average_rate` + * :func:`.concat` + * :func:`.empty_clone` + * :func:`.marginal_rate` + * :func:`.stringify_array` + * :func:`.switch` + +Deprecated: + * :class:`.Dummy` + +Note: + The ``deprecated`` imports are transitional, as so to ensure non-breaking + changes, and could be definitely removed from the codebase in the next + major release. + +Note: + How imports are being used today:: + + from openfisca_core.commons import * # Bad + from openfisca_core.commons.formulas import switch # Bad + from openfisca_core.commons.decorators import deprecated # Bad + + + The previous examples provoke cyclic dependency problems, that prevent us + from modularizing the different components of the library, which would make + them easier to test and to maintain. + + How they could be used in a future release: + + from openfisca_core import commons + from openfisca_core.commons import deprecated + + deprecated() # Good: import classes as publicly exposed + commons.switch() # Good: use functions as publicly exposed + + .. seealso:: `PEP8#Imports`_ and `OpenFisca's Styleguide`_. + + .. _PEP8#Imports: + https://www.python.org/dev/peps/pep-0008/#imports + + .. _OpenFisca's Styleguide: + https://github.com/openfisca/openfisca-core/blob/master/STYLEGUIDE.md + +""" + +# Official Public API from .formulas import apply_thresholds, concat, switch # noqa: F401 from .misc import empty_clone, stringify_array # noqa: F401 from .rates import average_rate, marginal_rate # noqa: F401 + +__all__ = ["apply_thresholds", "concat", "switch"] +__all__ = ["empty_clone", "stringify_array", *__all__] +__all__ = ["average_rate", "marginal_rate", *__all__] + +# Deprecated + +from .dummy import Dummy # noqa: F401 + +__all__ = ["Dummy", *__all__] From d4267efae4e039b7decb8625b5c313fbd768af99 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 15:46:57 +0200 Subject: [PATCH 059/205] Add doc to dummy --- openfisca_core/commons/dummy.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/openfisca_core/commons/dummy.py b/openfisca_core/commons/dummy.py index 4136a0d429..5f1b0be330 100644 --- a/openfisca_core/commons/dummy.py +++ b/openfisca_core/commons/dummy.py @@ -2,7 +2,17 @@ class Dummy: - """A class that does nothing.""" + """A class that did nothing. + + Examples: + >>> Dummy() + None: message = [ From 365067255198c166271903819df8dfa34547eb5b Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 15:49:30 +0200 Subject: [PATCH 060/205] Add doc to formulas --- openfisca_core/commons/formulas.py | 50 +++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/openfisca_core/commons/formulas.py b/openfisca_core/commons/formulas.py index 5b49387fde..34870a42d5 100644 --- a/openfisca_core/commons/formulas.py +++ b/openfisca_core/commons/formulas.py @@ -2,8 +2,24 @@ def apply_thresholds(input, thresholds, choices): - """ - Return one of the choices depending on the input position compared to thresholds, for each input. + """Makes a choice based on an input and thresholds. + + From list of ``choices``, it selects one of them based on a list of + inputs, depending on the position of each ``input`` whithin a list of + ``thresholds``. It does so for each ``input`` provided. + + Args: + input: A list of inputs to make a choice. + thresholds: A list of thresholds to choose. + choices: A list of the possible choices. + + Returns: + :obj:`numpy.ndarray` of :obj:`float`: + A list of the choices made. + + Raises: + :exc:`AssertionError`: When the number of ``thresholds`` (t) and the + number of choices (c) are not either t == c or t == c - 1. Examples: >>> input = numpy.array([4, 5, 6, 7, 8]) @@ -24,7 +40,15 @@ def apply_thresholds(input, thresholds, choices): def concat(this, that): - """ + """Concatenates the values of two arrays. + + Args: + this: An array to concatenate. + that: Another array to concatenate. + + Returns: + :obj:`numpy.ndarray` of :obj:`float`: + An array with the concatenated values. Examples: >>> this = ["this", "that"] @@ -43,9 +67,21 @@ def concat(this, that): def switch(conditions, value_by_condition): - ''' - Reproduces a switch statement: given an array of conditions, return an array of the same size replacing each - condition item by the corresponding given value. + """Reproduces a switch statement. + + Given an array of conditions, returns an array of the same size, + replacing each condition item by the corresponding given value. + + Args: + conditions: An array of conditions. + value_by_condition: Values to replace for each condition. + + Returns: + :obj:`numpy.ndarray` of :obj:`float`: + An array with the replaced values. + + Raises: + :exc:`AssertionError`: When ``value_by_condition`` is empty. Examples: >>> conditions = numpy.array([1, 1, 1, 2]) @@ -53,7 +89,7 @@ def switch(conditions, value_by_condition): >>> switch(conditions, value_by_condition) array([80, 80, 80, 90]) - ''' + """ assert len(value_by_condition) > 0, \ "switch must be called with at least one value" From f174657234c4b8e9ec4b1a036439fe18ba9ef780 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 15:51:44 +0200 Subject: [PATCH 061/205] Add doc to misc --- openfisca_core/commons/misc.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/openfisca_core/commons/misc.py b/openfisca_core/commons/misc.py index 5dd54f70c5..fbf5ba31c7 100644 --- a/openfisca_core/commons/misc.py +++ b/openfisca_core/commons/misc.py @@ -2,7 +2,13 @@ def empty_clone(original): - """Create a new empty instance of the same class of the original object. + """Creates an empty instance of the same class of the original object. + + Args: + original: An object to clone. + + Returns: + The cloned, empty, object. Examples: >>> Foo = type("Foo", (list,), {}) @@ -29,8 +35,14 @@ def __init__(self) -> None: def stringify_array(array: numpy.ndarray) -> str: - """ - Generate a clean string representation of a NumPY array. + """Generates a clean string representation of a numpy array. + + Args: + array: An array. + + Returns: + :obj:`str`: + "None" if the ``array`` is None, the stringified ``array`` otherwise. Examples: >>> import numpy From 212cf96df07c4e533e3fd6d840f9094cd980cd12 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 15:55:55 +0200 Subject: [PATCH 062/205] Add doc to rates --- openfisca_core/commons/misc.py | 4 ++- openfisca_core/commons/rates.py | 50 +++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/openfisca_core/commons/misc.py b/openfisca_core/commons/misc.py index fbf5ba31c7..4999e6cfe4 100644 --- a/openfisca_core/commons/misc.py +++ b/openfisca_core/commons/misc.py @@ -26,8 +26,10 @@ def empty_clone(original): """ class Dummy(original.__class__): + """Dummy class for empty cloning.""" + def __init__(self) -> None: - pass + ... new = Dummy() new.__class__ = original.__class__ diff --git a/openfisca_core/commons/rates.py b/openfisca_core/commons/rates.py index 9148a1ec4d..da33bf796d 100644 --- a/openfisca_core/commons/rates.py +++ b/openfisca_core/commons/rates.py @@ -2,12 +2,27 @@ def average_rate(target = None, varying = None, trim = None): - ''' - Computes the average rate of a targeted net income, according to the varying gross income. + """Computes the average rate of a target net income. - :param target: Targeted net income, numerator - :param varying: Varying gross income, denominator - :param trim: Lower and upper bound of average rate to return + Given a ``target`` net income, and according to the ``varying`` gross + income. Optionally, a ``trim`` can be applied consisting on the lower and + upper bounds of the average rate to be computed. + + Note: + Usually, ``target`` and ``varying`` are the same size. + + Args: + target: The targeted net income. + varying: The varying gross income. + trim: The lower and upper bounds of the average rate. + + Returns: + :obj:`numpy.ndarray` of :obj:`float`: + + The average rate for each target. + + When ``trim`` is provided, values that are out of the provided bounds + are replaced by :obj:`numpy.nan`. Examples: >>> target = numpy.array([1, 2, 3]) @@ -16,7 +31,7 @@ def average_rate(target = None, varying = None, trim = None): >>> average_rate(target, varying, trim) array([ nan, 0. , -0.5]) - ''' + """ average_rate = 1 - target / varying if trim is not None: @@ -27,7 +42,27 @@ def average_rate(target = None, varying = None, trim = None): def marginal_rate(target = None, varying = None, trim = None): - """ + """Computes the marginal rate of a target net income. + + Given a ``target`` net income, and according to the ``varying`` gross + income. Optionally, a ``trim`` can be applied consisting of the lower and + upper bounds of the marginal rate to be computed. + + Note: + Usually, ``target`` and ``varying`` are the same size. + + Args: + target: The targeted net income. + varying: The varying gross income. + trim: The lower and upper bounds of the marginal rate. + + Returns: + :obj:`numpy.ndarray` of :obj:`float`: + + The marginal rate for each target. + + When ``trim`` is provided, values that are out of the provided bounds + are replaced by :obj:`numpy.nan`. Examples: >>> target = numpy.array([1, 2, 3]) @@ -38,7 +73,6 @@ def marginal_rate(target = None, varying = None, trim = None): """ - # target: numerator, varying: denominator marginal_rate = 1 - (target[:-1] - target[1:]) / (varying[:-1] - varying[1:]) if trim is not None: marginal_rate = numpy.where(marginal_rate <= max(trim), marginal_rate, numpy.nan) From 12afce0b563f772f3075e91066cc5b4eb728f840 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 7 Oct 2021 15:49:31 +0200 Subject: [PATCH 063/205] Apply suggestions from code review Co-authored-by: Matti Schneider --- openfisca_core/commons/__init__.py | 9 ++++----- openfisca_core/commons/formulas.py | 16 ++++++++-------- openfisca_core/commons/rates.py | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/openfisca_core/commons/__init__.py b/openfisca_core/commons/__init__.py index fa42930db7..b3b5d8cbb2 100644 --- a/openfisca_core/commons/__init__.py +++ b/openfisca_core/commons/__init__.py @@ -1,8 +1,7 @@ """Common tools for contributors and users. -The tools included in this sub-package are intented, at the same time, to help -contributors who maintain OpenFisca Core, and to help users building their own -systems. +The tools in this sub-package are intended, to help both contributors +to OpenFisca Core and to country packages. Official Public API: * :func:`.apply_thresholds` @@ -17,8 +16,8 @@ * :class:`.Dummy` Note: - The ``deprecated`` imports are transitional, as so to ensure non-breaking - changes, and could be definitely removed from the codebase in the next + The ``deprecated`` imports are transitional, in order to ensure non-breaking + changes, and could be removed from the codebase in the next major release. Note: diff --git a/openfisca_core/commons/formulas.py b/openfisca_core/commons/formulas.py index 34870a42d5..3a93477bc5 100644 --- a/openfisca_core/commons/formulas.py +++ b/openfisca_core/commons/formulas.py @@ -4,18 +4,18 @@ def apply_thresholds(input, thresholds, choices): """Makes a choice based on an input and thresholds. - From list of ``choices``, it selects one of them based on a list of - inputs, depending on the position of each ``input`` whithin a list of - ``thresholds``. It does so for each ``input`` provided. + From a list of ``choices``, this function selects one of these values based on a list + of inputs, depending on the value of each ``input`` within a list of + ``thresholds``. Args: - input: A list of inputs to make a choice. + input: A list of inputs to make a choice from. thresholds: A list of thresholds to choose. - choices: A list of the possible choices. + choices: A list of the possible values to choose from. Returns: :obj:`numpy.ndarray` of :obj:`float`: - A list of the choices made. + A list of the values chosen. Raises: :exc:`AssertionError`: When the number of ``thresholds`` (t) and the @@ -67,10 +67,10 @@ def concat(this, that): def switch(conditions, value_by_condition): - """Reproduces a switch statement. + """Mimicks a switch statement. Given an array of conditions, returns an array of the same size, - replacing each condition item by the corresponding given value. + replacing each condition item with the matching given value. Args: conditions: An array of conditions. diff --git a/openfisca_core/commons/rates.py b/openfisca_core/commons/rates.py index da33bf796d..bb94e24776 100644 --- a/openfisca_core/commons/rates.py +++ b/openfisca_core/commons/rates.py @@ -5,7 +5,7 @@ def average_rate(target = None, varying = None, trim = None): """Computes the average rate of a target net income. Given a ``target`` net income, and according to the ``varying`` gross - income. Optionally, a ``trim`` can be applied consisting on the lower and + income. Optionally, a ``trim`` can be applied consisting of the lower and upper bounds of the average rate to be computed. Note: From fd75c501cbf7365167a438e9145d091bbef85543 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 15:58:52 +0200 Subject: [PATCH 064/205] Bump patch to 35.5.5 --- CHANGELOG.md | 6 ++++++ setup.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6a7f9b5dc..153dd51231 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +### 35.5.5 [#1055](https://github.com/openfisca/openfisca-core/pull/1055) + +#### Documentation + +- Complete the documentation of the commons module + ### 35.5.4 [#1033](https://github.com/openfisca/openfisca-core/pull/1033) #### Bug Fixes diff --git a/setup.py b/setup.py index 66b49c1377..acb886dde0 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ setup( name = 'OpenFisca-Core', - version = '35.5.4', + version = '35.5.5', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From a0077ee147a8f1c26bd699d8dc45e0a6abde2c7e Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 28 Apr 2021 16:45:37 +0000 Subject: [PATCH 065/205] Upgrade to GitHub-native Dependabot --- .github/dependabot.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000000..a111f8ee8f --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,23 @@ +version: 2 +updates: +- package-ecosystem: pip + directory: "/" + schedule: + interval: daily + time: "00:00" + timezone: Europe/Paris + open-pull-requests-limit: 2 + reviewers: + - Morendil + - fpagnoux + - sandcha + - maukoquiroga + labels: + - kind:improvement + ignore: + - dependency-name: flake8-bugbear + versions: + - ">= 20.1.1.a, < 20.1.2" + - dependency-name: numpy + versions: + - ">= 1.18.a, < 1.19" From 6de033d73a6564eb7fa0abc1ced03019dfa120a1 Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Thu, 7 Oct 2021 16:30:29 +0200 Subject: [PATCH 066/205] Check dependencies on a monthly basis --- .github/dependabot.yml | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a111f8ee8f..fcb2acc162 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,21 +3,6 @@ updates: - package-ecosystem: pip directory: "/" schedule: - interval: daily - time: "00:00" - timezone: Europe/Paris - open-pull-requests-limit: 2 - reviewers: - - Morendil - - fpagnoux - - sandcha - - maukoquiroga + interval: monthly labels: - - kind:improvement - ignore: - - dependency-name: flake8-bugbear - versions: - - ">= 20.1.1.a, < 20.1.2" - - dependency-name: numpy - versions: - - ">= 1.18.a, < 1.19" + - kind:dependencies From 1b0d835ac7eeb9ebcac62ff5010fa6c00724f488 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 14:55:28 +0200 Subject: [PATCH 067/205] Add strict type-linting for commons --- openfisca_tasks/lint.mk | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/openfisca_tasks/lint.mk b/openfisca_tasks/lint.mk index 886072bb2b..115c6267bb 100644 --- a/openfisca_tasks/lint.mk +++ b/openfisca_tasks/lint.mk @@ -1,5 +1,5 @@ ## Lint the codebase. -lint: check-syntax-errors check-style lint-doc check-types +lint: check-syntax-errors check-style lint-doc check-types lint-typing-strict @$(call print_pass,$@:) ## Compile python files to check for syntax errors. @@ -39,6 +39,22 @@ check-types: @mypy --package openfisca_core --package openfisca_web_api @$(call print_pass,$@:) +## Run static type checkers for type errors (strict). +lint-typing-strict: \ + lint-typing-strict-commons \ + lint-typing-strict-types \ + ; + +## Run static type checkers for type errors (strict). +lint-typing-strict-%: + @$(call print_help,$(subst $*,%,$@:)) + @mypy \ + --cache-dir .mypy_cache-openfisca_core.$* \ + --implicit-reexport \ + --strict \ + --package openfisca_core.$* + @$(call print_pass,$@:) + ## Run code formatters to correct style errors. format-style: $(shell git ls-files "*.py") @$(call print_help,$@:) From ec78d711da56718671332f7c5a7a0b9b0c3002df Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 15:02:08 +0200 Subject: [PATCH 068/205] Add nptyping --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index acb886dde0..993b498bf1 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ general_requirements = [ 'dpath >= 1.5.0, < 2.0.0', + 'nptyping == 1.4.4', 'numexpr >= 2.7.0, <= 3.0', 'numpy >= 1.11, < 1.21', 'psutil >= 5.4.7, < 6.0.0', @@ -29,7 +30,7 @@ 'flake8-bugbear >= 19.3.0, < 20.0.0', 'flake8-docstrings == 1.6.0', 'flake8-print >= 3.1.0, < 4.0.0', - 'flake8-rst-docstrings < 1.0.0', + 'flake8-rst-docstrings == 0.2.3', 'mypy >= 0.701, < 0.800', 'openfisca-country-template >= 3.10.0, < 4.0.0', 'openfisca-extension-template >= 1.2.0rc0, < 2.0.0', From e41220c8a5b4c72b36ab3265b813c14a46f27b82 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 15:03:26 +0200 Subject: [PATCH 069/205] Add typing extensions --- setup.cfg | 6 ++++-- setup.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index 213867581a..108d152f59 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,9 +31,11 @@ testpaths = openfisca_core/commons tests [mypy] ignore_missing_imports = True +install_types = True +non_interactive = True [mypy-openfisca_core.commons.tests.*] -ignore_errors = True +ignore_errors = True [mypy-openfisca_core.scripts.*] -ignore_errors = True +ignore_errors = True diff --git a/setup.py b/setup.py index 993b498bf1..151f899e8c 100644 --- a/setup.py +++ b/setup.py @@ -14,6 +14,7 @@ 'pytest >= 4.4.1, < 6.0.0', # For openfisca test 'PyYAML >= 3.10', 'sortedcontainers == 2.2.2', + 'typing-extensions == 3.10.0.2', ] api_requirements = [ @@ -31,7 +32,7 @@ 'flake8-docstrings == 1.6.0', 'flake8-print >= 3.1.0, < 4.0.0', 'flake8-rst-docstrings == 0.2.3', - 'mypy >= 0.701, < 0.800', + 'mypy == 0.910', 'openfisca-country-template >= 3.10.0, < 4.0.0', 'openfisca-extension-template >= 1.2.0rc0, < 2.0.0', 'pylint == 2.10.2', From 8ed1c4fb2248117984578fda743dd3616b8ee717 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 15:07:48 +0200 Subject: [PATCH 070/205] Add types to formulas --- openfisca_core/commons/formulas.py | 50 +++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/openfisca_core/commons/formulas.py b/openfisca_core/commons/formulas.py index 3a93477bc5..4d67c910ec 100644 --- a/openfisca_core/commons/formulas.py +++ b/openfisca_core/commons/formulas.py @@ -1,12 +1,20 @@ +from typing import Any, Dict, Sequence + import numpy +from openfisca_core.types import ArrayLike, ArrayType + -def apply_thresholds(input, thresholds, choices): +def apply_thresholds( + input: ArrayType[float], + thresholds: ArrayLike[float], + choices: ArrayLike[float], + ) -> ArrayType[float]: """Makes a choice based on an input and thresholds. - From a list of ``choices``, this function selects one of these values based on a list - of inputs, depending on the value of each ``input`` within a list of - ``thresholds``. + From a list of ``choices``, this function selects one of these values + based on a list of inputs, depending on the value of each ``input`` within + a list of ``thresholds``. Args: input: A list of inputs to make a choice from. @@ -30,16 +38,24 @@ def apply_thresholds(input, thresholds, choices): """ + condlist: Sequence[ArrayType[bool]] condlist = [input <= threshold for threshold in thresholds] + if len(condlist) == len(choices) - 1: - # If a choice is provided for input > highest threshold, last condition must be true to return it. + # If a choice is provided for input > highest threshold, last condition + # must be true to return it. condlist += [True] + assert len(condlist) == len(choices), \ - "apply_thresholds must be called with the same number of thresholds than choices, or one more choice" + " ".join([ + "'apply_thresholds' must be called with the same number of", + "thresholds than choices, or one more choice.", + ]) + return numpy.select(condlist, choices) -def concat(this, that): +def concat(this: ArrayLike[str], that: ArrayLike[str]) -> ArrayType[str]: """Concatenates the values of two arrays. Args: @@ -58,15 +74,23 @@ def concat(this, that): """ - if isinstance(this, numpy.ndarray) and not numpy.issubdtype(this.dtype, numpy.str): + if isinstance(this, numpy.ndarray) and \ + not numpy.issubdtype(this.dtype, numpy.str_): + this = this.astype('str') - if isinstance(that, numpy.ndarray) and not numpy.issubdtype(that.dtype, numpy.str): + + if isinstance(that, numpy.ndarray) and \ + not numpy.issubdtype(that.dtype, numpy.str_): + that = that.astype('str') - return numpy.core.defchararray.add(this, that) + return numpy.char.add(this, that) -def switch(conditions, value_by_condition): +def switch( + conditions: ArrayType[float], + value_by_condition: Dict[float, Any], + ) -> ArrayType[float]: """Mimicks a switch statement. Given an array of conditions, returns an array of the same size, @@ -92,9 +116,11 @@ def switch(conditions, value_by_condition): """ assert len(value_by_condition) > 0, \ - "switch must be called with at least one value" + "'switch' must be called with at least one value." + condlist = [ conditions == condition for condition in value_by_condition.keys() ] + return numpy.select(condlist, value_by_condition.values()) From fc6bd890678c88ea771c53d57d66022a4be4ce5f Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 15:12:19 +0200 Subject: [PATCH 071/205] Add types to misc --- openfisca_core/commons/misc.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/openfisca_core/commons/misc.py b/openfisca_core/commons/misc.py index 4999e6cfe4..dd05cea11b 100644 --- a/openfisca_core/commons/misc.py +++ b/openfisca_core/commons/misc.py @@ -1,7 +1,11 @@ -import numpy +from typing import TypeVar +from openfisca_core.types import ArrayType -def empty_clone(original): +T = TypeVar("T") + + +def empty_clone(original: T) -> T: """Creates an empty instance of the same class of the original object. Args: @@ -25,18 +29,21 @@ def empty_clone(original): """ - class Dummy(original.__class__): - """Dummy class for empty cloning.""" + Dummy: object + new: T - def __init__(self) -> None: - ... + Dummy = type( + "Dummy", + (original.__class__,), + {"__init__": lambda self: None}, + ) new = Dummy() new.__class__ = original.__class__ return new -def stringify_array(array: numpy.ndarray) -> str: +def stringify_array(array: ArrayType) -> str: """Generates a clean string representation of a numpy array. Args: From 2206364643bad25c196b16c2b0a2f5add96f78f5 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 15:14:17 +0200 Subject: [PATCH 072/205] Add types to rates --- openfisca_core/commons/rates.py | 57 +++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/openfisca_core/commons/rates.py b/openfisca_core/commons/rates.py index bb94e24776..af862a502d 100644 --- a/openfisca_core/commons/rates.py +++ b/openfisca_core/commons/rates.py @@ -1,7 +1,15 @@ +from typing import Optional + import numpy +from openfisca_core.types import ArrayLike, ArrayType + -def average_rate(target = None, varying = None, trim = None): +def average_rate( + target: ArrayType[float], + varying: ArrayLike[float], + trim: Optional[ArrayLike[float]] = None, + ) -> ArrayType[float]: """Computes the average rate of a target net income. Given a ``target`` net income, and according to the ``varying`` gross @@ -33,15 +41,32 @@ def average_rate(target = None, varying = None, trim = None): """ + average_rate: ArrayType[float] + average_rate = 1 - target / varying + if trim is not None: - average_rate = numpy.where(average_rate <= max(trim), average_rate, numpy.nan) - average_rate = numpy.where(average_rate >= min(trim), average_rate, numpy.nan) + + average_rate = numpy.where( + average_rate <= max(trim), + average_rate, + numpy.nan, + ) + + average_rate = numpy.where( + average_rate >= min(trim), + average_rate, + numpy.nan, + ) return average_rate -def marginal_rate(target = None, varying = None, trim = None): +def marginal_rate( + target: ArrayType[float], + varying: ArrayType[float], + trim: Optional[ArrayLike[float]] = None, + ) -> ArrayType[float]: """Computes the marginal rate of a target net income. Given a ``target`` net income, and according to the ``varying`` gross @@ -73,9 +98,27 @@ def marginal_rate(target = None, varying = None, trim = None): """ - marginal_rate = 1 - (target[:-1] - target[1:]) / (varying[:-1] - varying[1:]) + marginal_rate: ArrayType[float] + + marginal_rate = ( + + 1 + - (target[:-1] + - target[1:]) / (varying[:-1] + - varying[1:]) + ) + if trim is not None: - marginal_rate = numpy.where(marginal_rate <= max(trim), marginal_rate, numpy.nan) - marginal_rate = numpy.where(marginal_rate >= min(trim), marginal_rate, numpy.nan) + + marginal_rate = numpy.where( + marginal_rate <= max(trim), + marginal_rate, + numpy.nan, + ) + + marginal_rate = numpy.where( + marginal_rate >= min(trim), + marginal_rate, + numpy.nan, + ) return marginal_rate From 54c25fd21b4f9944e75bf5d9f4f266452cba8de5 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 30 Sep 2021 14:41:23 +0200 Subject: [PATCH 073/205] Correct marginal rate calculation Co-authored-by: Mahdi Ben Jelloul --- openfisca_core/commons/rates.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/openfisca_core/commons/rates.py b/openfisca_core/commons/rates.py index af862a502d..d7d07ea1d8 100644 --- a/openfisca_core/commons/rates.py +++ b/openfisca_core/commons/rates.py @@ -102,9 +102,8 @@ def marginal_rate( marginal_rate = ( + 1 - - (target[:-1] - - target[1:]) / (varying[:-1] - - varying[1:]) + - (target[:-1] - target[1:]) + / (varying[:-1] - varying[1:]) ) if trim is not None: From c32fac4ca5a4ea1de5cc5f8e42606a7f9704dea1 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 30 Sep 2021 16:11:23 +0200 Subject: [PATCH 074/205] Fix switch type annotation --- openfisca_core/commons/formulas.py | 12 +++-- openfisca_core/commons/rates.py | 2 +- openfisca_core/types/__init__.py | 45 ++++++++++++++++++ openfisca_core/types/data_types/__init__.py | 1 + openfisca_core/types/data_types/arrays.py | 51 +++++++++++++++++++++ 5 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 openfisca_core/types/__init__.py create mode 100644 openfisca_core/types/data_types/__init__.py create mode 100644 openfisca_core/types/data_types/arrays.py diff --git a/openfisca_core/commons/formulas.py b/openfisca_core/commons/formulas.py index 4d67c910ec..6a90622147 100644 --- a/openfisca_core/commons/formulas.py +++ b/openfisca_core/commons/formulas.py @@ -1,9 +1,11 @@ -from typing import Any, Dict, Sequence +from typing import Any, Dict, Sequence, TypeVar import numpy from openfisca_core.types import ArrayLike, ArrayType +T = TypeVar("T") + def apply_thresholds( input: ArrayType[float], @@ -88,9 +90,9 @@ def concat(this: ArrayLike[str], that: ArrayLike[str]) -> ArrayType[str]: def switch( - conditions: ArrayType[float], - value_by_condition: Dict[float, Any], - ) -> ArrayType[float]: + conditions: ArrayType[Any], + value_by_condition: Dict[float, T], + ) -> ArrayType[T]: """Mimicks a switch statement. Given an array of conditions, returns an array of the same size, @@ -101,7 +103,7 @@ def switch( value_by_condition: Values to replace for each condition. Returns: - :obj:`numpy.ndarray` of :obj:`float`: + :obj:`numpy.ndarray`: An array with the replaced values. Raises: diff --git a/openfisca_core/commons/rates.py b/openfisca_core/commons/rates.py index d7d07ea1d8..d682824207 100644 --- a/openfisca_core/commons/rates.py +++ b/openfisca_core/commons/rates.py @@ -102,7 +102,7 @@ def marginal_rate( marginal_rate = ( + 1 - - (target[:-1] - target[1:]) + - (target[:-1] - target[1:]) / (varying[:-1] - varying[1:]) ) diff --git a/openfisca_core/types/__init__.py b/openfisca_core/types/__init__.py new file mode 100644 index 0000000000..e14cfea65d --- /dev/null +++ b/openfisca_core/types/__init__.py @@ -0,0 +1,45 @@ +"""Data types and protocols used by OpenFisca Core. + +The type definitions included in this sub-package are intented for +contributors, to help them better understand and document contracts +and expected behaviours. + +Official Public API: + * ``ArrayLike`` + * :attr:`.ArrayType` + +Note: + How imports are being used today:: + + from openfisca_core.types import * # Bad + from openfisca_core.types.data_types.arrays import ArrayLike # Bad + + + The previous examples provoke cyclic dependency problems, that prevents us + from modularizing the different components of the library, so as to make + them easier to test and to maintain. + + How could them be used after the next major release:: + + from openfisca_core.types import ArrayLike + + ArrayLike # Good: import types as publicly exposed + + .. seealso:: `PEP8#Imports`_ and `OpenFisca's Styleguide`_. + + .. _PEP8#Imports: + https://www.python.org/dev/peps/pep-0008/#imports + + .. _OpenFisca's Styleguide: + https://github.com/openfisca/openfisca-core/blob/master/STYLEGUIDE.md + +""" + +# Official Public API + +from .data_types import ( # noqa: F401 + ArrayLike, + ArrayType, + ) + +__all__ = ["ArrayLike", "ArrayType"] diff --git a/openfisca_core/types/data_types/__init__.py b/openfisca_core/types/data_types/__init__.py new file mode 100644 index 0000000000..6dd38194e3 --- /dev/null +++ b/openfisca_core/types/data_types/__init__.py @@ -0,0 +1 @@ +from .arrays import ArrayLike, ArrayType # noqa: F401 diff --git a/openfisca_core/types/data_types/arrays.py b/openfisca_core/types/data_types/arrays.py new file mode 100644 index 0000000000..5cfef639c5 --- /dev/null +++ b/openfisca_core/types/data_types/arrays.py @@ -0,0 +1,51 @@ +from typing import Sequence, TypeVar, Union + +from nptyping import types, NDArray as ArrayType + +import numpy + +T = TypeVar("T", bool, bytes, float, int, object, str) + +types._ndarray_meta._Type = Union[type, numpy.dtype, TypeVar] + +ArrayLike = Union[ArrayType[T], Sequence[T]] +""":obj:`typing.Generic`: Type of any castable to :class:`numpy.ndarray`. + +These include any :obj:`numpy.ndarray` and sequences (like +:obj:`list`, :obj:`tuple`, and so on). + +Examples: + >>> ArrayLike[float] + typing.Union[numpy.ndarray, typing.Sequence[float]] + + >>> ArrayLike[str] + typing.Union[numpy.ndarray, typing.Sequence[str]] + +Note: + It is possible since numpy version 1.21 to specify the type of an + array, thanks to `numpy.typing.NDArray`_:: + + from numpy.typing import NDArray + NDArray[numpy.float64] + + `mypy`_ provides `duck type compatibility`_, so an :obj:`int` is + considered to be valid whenever a :obj:`float` is expected. + +Todo: + * Refactor once numpy version >= 1.21 is used. + +.. versionadded:: 35.5.0 + +.. versionchanged:: 35.6.0 + Moved to :mod:`.types` + +.. _mypy: + https://mypy.readthedocs.io/en/stable/ + +.. _duck type compatibility: + https://mypy.readthedocs.io/en/stable/duck_type_compatibility.html + +.. _numpy.typing.NDArray: + https://numpy.org/doc/stable/reference/typing.html#numpy.typing.NDArray + +""" From 4e07f30668256bf0363ff4cebe50e771818169f4 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 7 Oct 2021 14:23:06 +0200 Subject: [PATCH 075/205] Do not use slashes in .gitignore --- .gitignore | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 4b56efc6da..a110d33440 100644 --- a/.gitignore +++ b/.gitignore @@ -3,18 +3,18 @@ .spyderproject .pydevproject .vscode -.settings/ -.vscode/ -build/ -dist/ -doc/ +.settings +.vscode +build +dist +doc *.egg-info *.mo *.pyc *~ -/cover -/.coverage -/tags +cover +.coverage +tags .tags* .noseids .pytest_cache From 13c954e3b7f2b9ad710c7ea16c09c86a79f3949c Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Thu, 7 Oct 2021 16:54:24 +0200 Subject: [PATCH 076/205] Sort .gitignore --- .gitignore | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index a110d33440..c66d2bd194 100644 --- a/.gitignore +++ b/.gitignore @@ -1,22 +1,22 @@ -.venv -.project -.spyderproject -.pydevproject -.vscode -.settings -.vscode -build -dist -doc *.egg-info *.mo *.pyc *~ -cover .coverage -tags -.tags* +.mypy_cache .noseids +.project +.pydevproject .pytest_cache -.mypy_cache +.settings +.spyderproject +.tags* +.venv +.vscode +.vscode +build +cover +dist +doc performance.json +tags From def6bf0ee3d8fcbfa54f9d0b786b6c4b5b6d7381 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Wed, 29 Sep 2021 15:17:08 +0200 Subject: [PATCH 077/205] Bump minor to 35.6.0 --- CHANGELOG.md | 20 ++++++++++++++++++++ setup.py | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 153dd51231..684c94323a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,25 @@ # Changelog +## 35.6.0 [#1054](https://github.com/openfisca/openfisca-core/pull/1054) + +#### New Features + +- Introduce `openfisca_core.types` + +#### Documentation + +- Complete typing of the commons module + +#### Dependencies + +- `nptyping` + - To add backport-support for numpy typing + - Can be removed once lower-bound numpy version is 1.21+ + +- `typing_extensions` + - To add backport-support for `typing.Protocol` and `typing.Literal` + - Can be removed once lower-bound python version is 3.8+ + ### 35.5.5 [#1055](https://github.com/openfisca/openfisca-core/pull/1055) #### Documentation diff --git a/setup.py b/setup.py index 151f899e8c..fb03815a1d 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( name = 'OpenFisca-Core', - version = '35.5.5', + version = '35.6.0', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From da3b7704faf417b270ce99bf10f3e0efd6e74c96 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Sun, 17 Oct 2021 13:00:34 +0100 Subject: [PATCH 078/205] Add containing_entity property to entities --- openfisca_core/entities/group_entity.py | 3 ++- openfisca_core/entities/helpers.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/openfisca_core/entities/group_entity.py b/openfisca_core/entities/group_entity.py index d0a4113b35..39447fb996 100644 --- a/openfisca_core/entities/group_entity.py +++ b/openfisca_core/entities/group_entity.py @@ -6,7 +6,7 @@ class GroupEntity(Entity): Represents an entity composed of several persons with different roles, on which calculations are run. """ - def __init__(self, key, plural, label, doc, roles): + def __init__(self, key, plural, label, doc, roles, containing_entities = []): super().__init__(key, plural, label, doc) self.roles_description = roles self.roles = [] @@ -23,3 +23,4 @@ def __init__(self, key, plural, label, doc, roles): role.max = len(role.subroles) self.flattened_roles = sum([role2.subroles or [role2] for role2 in self.roles], []) self.is_person = False + self.containing_entities = containing_entities diff --git a/openfisca_core/entities/helpers.py b/openfisca_core/entities/helpers.py index d1c66a66ba..428d146058 100644 --- a/openfisca_core/entities/helpers.py +++ b/openfisca_core/entities/helpers.py @@ -1,8 +1,8 @@ from openfisca_core import entities -def build_entity(key, plural, label, doc = "", roles = None, is_person = False, class_override = None): +def build_entity(key, plural, label, doc = "", roles = None, is_person = False, containing_entities = [], class_override = None): if is_person: return entities.Entity(key, plural, label, doc) else: - return entities.GroupEntity(key, plural, label, doc, roles) + return entities.GroupEntity(key, plural, label, doc, roles, containing_entities = containing_entities) From e0410100fed476ed32135e0edc3590f9a5ca3998 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Sun, 17 Oct 2021 13:00:51 +0100 Subject: [PATCH 079/205] Add shortcut to projectors --- openfisca_core/projectors/helpers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openfisca_core/projectors/helpers.py b/openfisca_core/projectors/helpers.py index 502eee1dfb..7bc55e0fd9 100644 --- a/openfisca_core/projectors/helpers.py +++ b/openfisca_core/projectors/helpers.py @@ -21,3 +21,5 @@ def get_projector_from_shortcut(population, shortcut, parent = None): role = next((role for role in population.entity.flattened_roles if (role.max == 1) and (role.key == shortcut)), None) if role: return projectors.UniqueRoleToEntityProjector(population, role, parent) + if shortcut in population.entity.containing_entities: + return getattr(projectors.FirstPersonToEntityProjector(population, parent), shortcut) From 6776b6e63a22200c149759c59f5c8901c0029d92 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Sun, 17 Oct 2021 13:00:56 +0100 Subject: [PATCH 080/205] Add test --- tests/core/test_formulas.py | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/core/test_formulas.py b/tests/core/test_formulas.py index 876ca239d1..47f14eeb24 100644 --- a/tests/core/test_formulas.py +++ b/tests/core/test_formulas.py @@ -94,3 +94,81 @@ def test_compare_multiplication_and_switch(simulation, month): uses_multiplication = simulation.calculate('uses_multiplication', period = month) uses_switch = simulation.calculate('uses_switch', period = month) assert numpy.all(uses_switch == uses_multiplication) + + +def test_group_encapsulation(): + from openfisca_core.taxbenefitsystems import TaxBenefitSystem + from openfisca_core.entities import build_entity + from openfisca_core.periods import ETERNITY + person_entity = build_entity( + key="person", + plural="people", + label="A person", + is_person=True, + ) + family_entity = build_entity( + key="family", + plural="families", + label="A family (all members in the same household)", + containing_entities=["household"], + roles=[{ + "key": "member", + "plural": "members", + "label": "Member", + }] + ) + household_entity = build_entity( + key="household", + plural="households", + label="A household, containing one or more families", + roles=[{ + "key": "member", + "plural": "members", + "label": "Member", + }] + ) + + entities = [person_entity, family_entity, household_entity] + + system = TaxBenefitSystem(entities) + + class household_level_variable(Variable): + value_type = int + entity = household_entity + definition_period = ETERNITY + + class projected_family_level_variable(Variable): + value_type = int + entity = family_entity + definition_period = ETERNITY + + def formula(family, period): + return family.household("household_level_variable", period) + + system.add_variables(household_level_variable, projected_family_level_variable) + + simulation = SimulationBuilder().build_from_dict(system, { + "people": { + "person1": {}, + "person2": {}, + "person3": {} + }, + "families": { + "family1": { + "members": ["person1", "person2"] + }, + "family2": { + "members": ["person3"] + }, + }, + "households": { + "household1": { + "members": ["person1", "person2", "person3"], + "household_level_variable": { + "eternity": 5 + } + } + } + }) + + assert (simulation.calculate("projected_family_level_variable", "2021-01-01") == 5).all() From ecf268a8b9c9acfb88128bbec555207a5aa66ebb Mon Sep 17 00:00:00 2001 From: Nikhil Date: Sun, 17 Oct 2021 13:10:33 +0100 Subject: [PATCH 081/205] Don't use mutable arguments in defaults --- openfisca_core/entities/group_entity.py | 2 +- openfisca_core/entities/helpers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openfisca_core/entities/group_entity.py b/openfisca_core/entities/group_entity.py index 39447fb996..e6171d7660 100644 --- a/openfisca_core/entities/group_entity.py +++ b/openfisca_core/entities/group_entity.py @@ -6,7 +6,7 @@ class GroupEntity(Entity): Represents an entity composed of several persons with different roles, on which calculations are run. """ - def __init__(self, key, plural, label, doc, roles, containing_entities = []): + def __init__(self, key, plural, label, doc, roles, containing_entities = ()): super().__init__(key, plural, label, doc) self.roles_description = roles self.roles = [] diff --git a/openfisca_core/entities/helpers.py b/openfisca_core/entities/helpers.py index 428d146058..e8fe69cf29 100644 --- a/openfisca_core/entities/helpers.py +++ b/openfisca_core/entities/helpers.py @@ -1,7 +1,7 @@ from openfisca_core import entities -def build_entity(key, plural, label, doc = "", roles = None, is_person = False, containing_entities = [], class_override = None): +def build_entity(key, plural, label, doc = "", roles = None, is_person = False, containing_entities = (), class_override = None): if is_person: return entities.Entity(key, plural, label, doc) else: From 39a9dc44dec0876bacc4f005ff636c42e83bbaab Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff <35577657+nikhilwoodruff@users.noreply.github.com> Date: Mon, 18 Oct 2021 13:58:49 +0100 Subject: [PATCH 082/205] Apply suggestions from code review Co-authored-by: Matti Schneider --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 684c94323a..c13ab894e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 35.7.0 [#1070](https://github.com/openfisca/openfisca-core/pulls/1070) + +#### New Features + +- Add group population shortcut to containing groups entities + ## 35.6.0 [#1054](https://github.com/openfisca/openfisca-core/pull/1054) #### New Features From 48287243d291104438c7b7dfd718970db0e5d2fb Mon Sep 17 00:00:00 2001 From: Nikhil Date: Wed, 20 Oct 2021 15:45:21 +0100 Subject: [PATCH 083/205] Add documentation to test --- tests/core/test_formulas.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/core/test_formulas.py b/tests/core/test_formulas.py index 47f14eeb24..8851671755 100644 --- a/tests/core/test_formulas.py +++ b/tests/core/test_formulas.py @@ -97,9 +97,17 @@ def test_compare_multiplication_and_switch(simulation, month): def test_group_encapsulation(): + """Projects a calculation to all members of an entity. + + When a household contains more than one family + Variables can be defined for the the household + And calculations are projected to all the member families. + + """ from openfisca_core.taxbenefitsystems import TaxBenefitSystem from openfisca_core.entities import build_entity from openfisca_core.periods import ETERNITY + person_entity = build_entity( key="person", plural="people", From 35d5b923b70acf4fe6cb0dda1466463a00296214 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Wed, 20 Oct 2021 15:45:31 +0100 Subject: [PATCH 084/205] Add unit tests for projector shortcut --- tests/core/test_projectors.py | 86 +++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/core/test_projectors.py diff --git a/tests/core/test_projectors.py b/tests/core/test_projectors.py new file mode 100644 index 0000000000..bd44129266 --- /dev/null +++ b/tests/core/test_projectors.py @@ -0,0 +1,86 @@ +from openfisca_core.simulations.simulation_builder import SimulationBuilder +from openfisca_core.taxbenefitsystems import TaxBenefitSystem +from openfisca_core.entities import build_entity + +def test_shortcut_to_containing_entity_provided(): + """ + Tests that, when an entity provides a containing entity, + the shortcut to that containing entity is provided. + """ + person_entity = build_entity( + key="person", + plural="people", + label="A person", + is_person=True, + ) + family_entity = build_entity( + key="family", + plural="families", + label="A family (all members in the same household)", + containing_entities=["household"], + roles=[{ + "key": "member", + "plural": "members", + "label": "Member", + }] + ) + household_entity = build_entity( + key="household", + plural="households", + label="A household, containing one or more families", + roles=[{ + "key": "member", + "plural": "members", + "label": "Member", + }] + ) + + entities = [person_entity, family_entity, household_entity] + + system = TaxBenefitSystem(entities) + simulation = SimulationBuilder().build_from_dict(system, {}) + assert simulation.populations["family"].household.entity.key == "household" + +def test_shortcut_to_containing_entity_not_provided(): + """ + Tests that, when an entity doesn't provide a containing + entity, the shortcut to that containing entity is not provided. + """ + person_entity = build_entity( + key="person", + plural="people", + label="A person", + is_person=True, + ) + family_entity = build_entity( + key="family", + plural="families", + label="A family (all members in the same household)", + containing_entities=[], + roles=[{ + "key": "member", + "plural": "members", + "label": "Member", + }] + ) + household_entity = build_entity( + key="household", + plural="households", + label="A household, containing one or more families", + roles=[{ + "key": "member", + "plural": "members", + "label": "Member", + }] + ) + + entities = [person_entity, family_entity, household_entity] + + system = TaxBenefitSystem(entities) + simulation = SimulationBuilder().build_from_dict(system, {}) + try: + simulation.populations["family"].household + assert False + except AttributeError: + pass + \ No newline at end of file From 6befed484130650ed0b684231b2164edc268f303 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Wed, 20 Oct 2021 15:45:50 +0100 Subject: [PATCH 085/205] Add documentation for `containing_entities` --- openfisca_core/entities/group_entity.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/openfisca_core/entities/group_entity.py b/openfisca_core/entities/group_entity.py index e6171d7660..617c96400f 100644 --- a/openfisca_core/entities/group_entity.py +++ b/openfisca_core/entities/group_entity.py @@ -2,8 +2,25 @@ class GroupEntity(Entity): - """ - Represents an entity composed of several persons with different roles, on which calculations are run. + """Represents an entity containing several other entities with different roles. + + A :class:`.GroupEntity` represents an :class:`.Entity` containing + several other :class:`.Entity` with different :class:`.Role`, and on + which calculations can be run. + + Args: + key: A key to identify the group entity. + plural: The ``key``, pluralised. + label: A summary description. + doc: A full description. + roles: The list of :class:`.Role` of the group entity. + containing_entities: The list of keys of group entities whose + members are guaranteed to be a superset of this group's entities. + + .. versionchanged:: 3.7.0 + Added ``containing_entities``, that allows the defining of group entities + which entirely contain other group entities. + """ def __init__(self, key, plural, label, doc, roles, containing_entities = ()): From 76aa526c05eb2c9c927b7fbaf5b1fc1f09a3bc9c Mon Sep 17 00:00:00 2001 From: Nikhil Date: Wed, 20 Oct 2021 15:54:38 +0100 Subject: [PATCH 086/205] Apply formatting --- openfisca_core/entities/group_entity.py | 10 +++++----- tests/core/test_projectors.py | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/openfisca_core/entities/group_entity.py b/openfisca_core/entities/group_entity.py index 617c96400f..626bfedf6e 100644 --- a/openfisca_core/entities/group_entity.py +++ b/openfisca_core/entities/group_entity.py @@ -4,7 +4,7 @@ class GroupEntity(Entity): """Represents an entity containing several other entities with different roles. - A :class:`.GroupEntity` represents an :class:`.Entity` containing + A :class:`.GroupEntity` represents an :class:`.Entity` containing several other :class:`.Entity` with different :class:`.Role`, and on which calculations can be run. @@ -14,11 +14,11 @@ class GroupEntity(Entity): label: A summary description. doc: A full description. roles: The list of :class:`.Role` of the group entity. - containing_entities: The list of keys of group entities whose - members are guaranteed to be a superset of this group's entities. + containing_entities: The list of keys of group entities whose + members are guaranteed to be a superset of this group's entities. - .. versionchanged:: 3.7.0 - Added ``containing_entities``, that allows the defining of group entities + .. versionchanged:: 3.7.0 + Added ``containing_entities``, that allows the defining of group entities which entirely contain other group entities. """ diff --git a/tests/core/test_projectors.py b/tests/core/test_projectors.py index bd44129266..5a88771df7 100644 --- a/tests/core/test_projectors.py +++ b/tests/core/test_projectors.py @@ -2,6 +2,7 @@ from openfisca_core.taxbenefitsystems import TaxBenefitSystem from openfisca_core.entities import build_entity + def test_shortcut_to_containing_entity_provided(): """ Tests that, when an entity provides a containing entity, @@ -41,9 +42,10 @@ def test_shortcut_to_containing_entity_provided(): simulation = SimulationBuilder().build_from_dict(system, {}) assert simulation.populations["family"].household.entity.key == "household" + def test_shortcut_to_containing_entity_not_provided(): """ - Tests that, when an entity doesn't provide a containing + Tests that, when an entity doesn't provide a containing entity, the shortcut to that containing entity is not provided. """ person_entity = build_entity( @@ -80,7 +82,6 @@ def test_shortcut_to_containing_entity_not_provided(): simulation = SimulationBuilder().build_from_dict(system, {}) try: simulation.populations["family"].household - assert False + raise AssertionError() except AttributeError: pass - \ No newline at end of file From 126ea77c8ab815558b918bc89983ef1c8dfb99bb Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff <35577657+nikhilwoodruff@users.noreply.github.com> Date: Wed, 20 Oct 2021 15:51:25 +0100 Subject: [PATCH 087/205] Permute argument order in build_entity Co-authored-by: Mauko Quiroga --- openfisca_core/entities/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openfisca_core/entities/helpers.py b/openfisca_core/entities/helpers.py index e8fe69cf29..86d7bb6a6b 100644 --- a/openfisca_core/entities/helpers.py +++ b/openfisca_core/entities/helpers.py @@ -1,7 +1,7 @@ from openfisca_core import entities -def build_entity(key, plural, label, doc = "", roles = None, is_person = False, containing_entities = (), class_override = None): +def build_entity(key, plural, label, doc = "", roles = None, is_person = False, class_override = None, containing_entities = ()): if is_person: return entities.Entity(key, plural, label, doc) else: From cd6a77eab28a7f8ad319532086bc01ac383295d3 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Thu, 21 Oct 2021 16:21:36 +0100 Subject: [PATCH 088/205] Fix formatting --- tests/core/test_projectors.py | 229 ++++++++++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) diff --git a/tests/core/test_projectors.py b/tests/core/test_projectors.py index 5a88771df7..be401bbec8 100644 --- a/tests/core/test_projectors.py +++ b/tests/core/test_projectors.py @@ -1,6 +1,8 @@ from openfisca_core.simulations.simulation_builder import SimulationBuilder from openfisca_core.taxbenefitsystems import TaxBenefitSystem from openfisca_core.entities import build_entity +from openfisca_core.model_api import Enum, Variable, ETERNITY +import numpy as np def test_shortcut_to_containing_entity_provided(): @@ -85,3 +87,230 @@ def test_shortcut_to_containing_entity_not_provided(): raise AssertionError() except AttributeError: pass + + +def test_enum_projects_downwards(): + """ + Test that an Enum-type household-level variable projects + values onto its members correctly. + """ + + person = build_entity( + key="person", + plural="people", + label="A person", + is_person=True, + ) + household = build_entity( + key="household", + plural="households", + label="A household", + roles=[{ + "key": "member", + "plural": "members", + "label": "Member", + }] + ) + + entities = [person, household] + + system = TaxBenefitSystem(entities) + + class enum(Enum): + FIRST_OPTION = "First option" + SECOND_OPTION = "Second option" + + class household_enum_variable(Variable): + value_type = Enum + possible_values = enum + default_value = enum.FIRST_OPTION + entity = household + definition_period = ETERNITY + + class projected_enum_variable(Variable): + value_type = Enum + possible_values = enum + default_value = enum.FIRST_OPTION + entity = person + definition_period = ETERNITY + + def formula(person, period): + return person.household("household_enum_variable", period) + + system.add_variables(household_enum_variable, projected_enum_variable) + + simulation = SimulationBuilder().build_from_dict(system, { + "people": { + "person1": {}, + "person2": {}, + "person3": {} + }, + "households": { + "household1": { + "members": ["person1", "person2", "person3"], + "household_enum_variable": { + "eternity": "SECOND_OPTION" + } + } + } + }) + + assert (simulation.calculate("projected_enum_variable", "2021-01-01").decode_to_str() == np.array(["SECOND_OPTION"] * 3)).all() + + +def test_enum_projects_upwards(): + """ + Test that an Enum-type person-level variable projects + values onto its household (from the first person) correctly. + """ + + person = build_entity( + key="person", + plural="people", + label="A person", + is_person=True, + ) + household = build_entity( + key="household", + plural="households", + label="A household", + roles=[{ + "key": "member", + "plural": "members", + "label": "Member", + }] + ) + + entities = [person, household] + + system = TaxBenefitSystem(entities) + + class enum(Enum): + FIRST_OPTION = "First option" + SECOND_OPTION = "Second option" + + class household_projected_variable(Variable): + value_type = Enum + possible_values = enum + default_value = enum.FIRST_OPTION + entity = household + definition_period = ETERNITY + + def formula(household, period): + return household.value_from_first_person(household.members("person_enum_variable", period)) + + class person_enum_variable(Variable): + value_type = Enum + possible_values = enum + default_value = enum.FIRST_OPTION + entity = person + definition_period = ETERNITY + + system.add_variables(household_projected_variable, person_enum_variable) + + simulation = SimulationBuilder().build_from_dict(system, { + "people": { + "person1": { + "person_enum_variable": { + "ETERNITY": "SECOND_OPTION" + } + }, + "person2": {}, + "person3": {} + }, + "households": { + "household1": { + "members": ["person1", "person2", "person3"], + } + } + }) + + assert (simulation.calculate("household_projected_variable", "2021-01-01").decode_to_str() == np.array(["SECOND_OPTION"])).all() + + +def test_enum_projects_between_containing_groups(): + """ + Test that an Enum-type person-level variable projects + values onto its household (from the first person) correctly. + """ + + person_entity = build_entity( + key="person", + plural="people", + label="A person", + is_person=True, + ) + family_entity = build_entity( + key="family", + plural="families", + label="A family (all members in the same household)", + containing_entities=["household"], + roles=[{ + "key": "member", + "plural": "members", + "label": "Member", + }] + ) + household_entity = build_entity( + key="household", + plural="households", + label="A household, containing one or more families", + roles=[{ + "key": "member", + "plural": "members", + "label": "Member", + }] + ) + + entities = [person_entity, family_entity, household_entity] + + system = TaxBenefitSystem(entities) + + class enum(Enum): + FIRST_OPTION = "First option" + SECOND_OPTION = "Second option" + + class household_level_variable(Variable): + value_type = Enum + possible_values = enum + default_value = enum.FIRST_OPTION + entity = household_entity + definition_period = ETERNITY + + class projected_family_level_variable(Variable): + value_type = Enum + possible_values = enum + default_value = enum.FIRST_OPTION + entity = family_entity + definition_period = ETERNITY + + def formula(family, period): + return family.household("household_level_variable", period) + + system.add_variables(household_level_variable, projected_family_level_variable) + + simulation = SimulationBuilder().build_from_dict(system, { + "people": { + "person1": {}, + "person2": {}, + "person3": {} + }, + "families": { + "family1": { + "members": ["person1", "person2"] + }, + "family2": { + "members": ["person3"] + }, + }, + "households": { + "household1": { + "members": ["person1", "person2", "person3"], + "household_level_variable": { + "eternity": "SECOND_OPTION" + } + } + } + }) + + assert (simulation.calculate("projected_family_level_variable", "2021-01-01").decode_to_str() == np.array(["SECOND_OPTION"])).all() From 869d5671f47ba23d456bbe5ac732c7858bbc473e Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff <35577657+nikhilwoodruff@users.noreply.github.com> Date: Tue, 26 Oct 2021 21:03:38 +0100 Subject: [PATCH 089/205] Fix argument indentation in group entity doc Co-authored-by: Mauko Quiroga --- openfisca_core/entities/group_entity.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openfisca_core/entities/group_entity.py b/openfisca_core/entities/group_entity.py index 626bfedf6e..556801657a 100644 --- a/openfisca_core/entities/group_entity.py +++ b/openfisca_core/entities/group_entity.py @@ -15,9 +15,9 @@ class GroupEntity(Entity): doc: A full description. roles: The list of :class:`.Role` of the group entity. containing_entities: The list of keys of group entities whose - members are guaranteed to be a superset of this group's entities. + members are guaranteed to be a superset of this group's entities. - .. versionchanged:: 3.7.0 + .. versionchanged:: 35.7.0 Added ``containing_entities``, that allows the defining of group entities which entirely contain other group entities. From 68685e1c18fc7e87acb8ef4ca6edc45ae64c0ef1 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 26 Oct 2021 23:39:15 +0200 Subject: [PATCH 090/205] Ignore check RST301 --- openfisca_core/entities/group_entity.py | 10 +++++----- setup.cfg | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/openfisca_core/entities/group_entity.py b/openfisca_core/entities/group_entity.py index 556801657a..0d58acc6ba 100644 --- a/openfisca_core/entities/group_entity.py +++ b/openfisca_core/entities/group_entity.py @@ -2,7 +2,7 @@ class GroupEntity(Entity): - """Represents an entity containing several other entities with different roles. + """Represents an entity containing several others with different roles. A :class:`.GroupEntity` represents an :class:`.Entity` containing several other :class:`.Entity` with different :class:`.Role`, and on @@ -14,12 +14,12 @@ class GroupEntity(Entity): label: A summary description. doc: A full description. roles: The list of :class:`.Role` of the group entity. - containing_entities: The list of keys of group entities whose - members are guaranteed to be a superset of this group's entities. + containing_entities: The list of keys of group entities whose members + are guaranteed to be a superset of this group's entities. .. versionchanged:: 35.7.0 - Added ``containing_entities``, that allows the defining of group entities - which entirely contain other group entities. + Added ``containing_entities``, that allows the defining of group + entities which entirely contain other group entities. """ diff --git a/setup.cfg b/setup.cfg index 108d152f59..25b348db77 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,12 +6,13 @@ ; E501: We do not enforce a maximum line length. ; F403/405: We ignore * imports. ; R0401: We avoid cyclic imports —required for unit/doc tests. +; RST301: We use Google Python Style (see https://pypi.org/project/flake8-rst-docstrings/) ; W503/504: We break lines before binary operators (Knuth's style). [flake8] extend-ignore = D hang-closing = true -ignore = E128,E251,F403,F405,E501,W503,W504 +ignore = E128,E251,F403,F405,E501,RST301,W503,W504 in-place = true include-in-doctest = openfisca_core/commons openfisca_core/types rst-directives = attribute, deprecated, seealso, versionadded, versionchanged From acd2dff93a7aeefbdda90295abaecf6a4aee5534 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Sun, 17 Oct 2021 13:14:52 +0100 Subject: [PATCH 091/205] Bump minor to 35.7.0 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index fb03815a1d..a9164b8cbd 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( name = 'OpenFisca-Core', - version = '35.6.0', + version = '35.7.0', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From 154b27a53aa04756a49ff4358a6e42e3ebedc502 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 26 Oct 2021 19:52:04 +0200 Subject: [PATCH 092/205] Fix coverage config --- openfisca_tasks/test_code.mk | 6 +++--- setup.cfg | 12 +++++++++++- setup.py | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/openfisca_tasks/test_code.mk b/openfisca_tasks/test_code.mk index ffa87efbc4..13c2ea68cc 100644 --- a/openfisca_tasks/test_code.mk +++ b/openfisca_tasks/test_code.mk @@ -19,7 +19,7 @@ test-code: test-core test-country test-extension ## Run openfisca-core tests. test-core: $(shell git ls-files "tests/*.py") @$(call print_help,$@:) - @PYTEST_ADDOPTS="${PYTEST_ADDOPTS} --cov=openfisca_core --cov=openfisca_web_api ${pytest_args}" \ + @PYTEST_ADDOPTS="$${PYTEST_ADDOPTS} ${pytest_args}" \ openfisca test $? \ ${openfisca_args} @$(call print_pass,$@:) @@ -27,7 +27,7 @@ test-core: $(shell git ls-files "tests/*.py") ## Run country-template tests. test-country: @$(call print_help,$@:) - @PYTEST_ADDOPTS="${PYTEST_ADDOPTS} ${pytest_args}" \ + @PYTEST_ADDOPTS="$${PYTEST_ADDOPTS} ${pytest_args}" \ openfisca test ${python_packages}/openfisca_country_template/tests \ --country-package openfisca_country_template \ ${openfisca_args} @@ -36,7 +36,7 @@ test-country: ## Run extension-template tests. test-extension: @$(call print_help,$@:) - @PYTEST_ADDOPTS="${PYTEST_ADDOPTS} ${pytest_args}" \ + @PYTEST_ADDOPTS="$${PYTEST_ADDOPTS} ${pytest_args}" \ openfisca test ${python_packages}/openfisca_extension_template/tests \ --country-package openfisca_country_template \ --extensions openfisca_extension_template \ diff --git a/setup.cfg b/setup.cfg index 25b348db77..4c3609c9af 100644 --- a/setup.cfg +++ b/setup.cfg @@ -24,8 +24,18 @@ disable = all enable = C0115,C0116,R0401 score = no +[coverage:paths] +source = . */site-packages + +[coverage:run] +branch = true +source = openfisca_core, openfisca_web_api + +[coverage:report] +show_missing = true + [tool:pytest] -addopts = --cov-report=term-missing:skip-covered --doctest-modules --disable-pytest-warnings --showlocals +addopts = --cov --doctest-modules --disable-pytest-warnings --showlocals doctest_optionflags = ELLIPSIS IGNORE_EXCEPTION_DETAIL NUMBER NORMALIZE_WHITESPACE python_files = **/*.py testpaths = openfisca_core/commons tests diff --git a/setup.py b/setup.py index a9164b8cbd..0d674d5264 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ 'openfisca-country-template >= 3.10.0, < 4.0.0', 'openfisca-extension-template >= 1.2.0rc0, < 2.0.0', 'pylint == 2.10.2', - 'pytest-cov >= 2.6.1, < 3.0.0', + 'pytest-cov == 3.0.0', ] + api_requirements setup( From 8fccce5e152f688bdefa98418be18cac53b2d2ea Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 26 Oct 2021 21:35:33 +0200 Subject: [PATCH 093/205] Fix test collection --- openfisca_tasks/test_code.mk | 14 ++++++++++++-- setup.cfg | 6 ++++-- setup.py | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/openfisca_tasks/test_code.mk b/openfisca_tasks/test_code.mk index 13c2ea68cc..548a2f4755 100644 --- a/openfisca_tasks/test_code.mk +++ b/openfisca_tasks/test_code.mk @@ -1,3 +1,6 @@ +## The openfisca command module. +openfisca = openfisca_core.scripts.openfisca_command + ## The path to the installed packages. python_packages = $(shell python -c "import sysconfig; print(sysconfig.get_paths()[\"purelib\"])") @@ -17,11 +20,13 @@ test-code: test-core test-country test-extension @$(call print_pass,$@:) ## Run openfisca-core tests. -test-core: $(shell git ls-files "tests/*.py") +test-core: $(shell pytest -qq --co | cut -f1 -d ":") @$(call print_help,$@:) @PYTEST_ADDOPTS="$${PYTEST_ADDOPTS} ${pytest_args}" \ - openfisca test $? \ + coverage run -m \ + ${openfisca} test $? \ ${openfisca_args} + @${MAKE} test-cov @$(call print_pass,$@:) ## Run country-template tests. @@ -42,3 +47,8 @@ test-extension: --extensions openfisca_extension_template \ ${openfisca_args} @$(call print_pass,$@:) + +## Print the coverage report. +test-cov: + @$(call print_help,$@:) + @coverage report diff --git a/setup.cfg b/setup.cfg index 4c3609c9af..855af2bbe1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,12 +33,14 @@ source = openfisca_core, openfisca_web_api [coverage:report] show_missing = true +skip_covered = true +skip_empty = true [tool:pytest] -addopts = --cov --doctest-modules --disable-pytest-warnings --showlocals +addopts = --doctest-modules --disable-pytest-warnings --showlocals doctest_optionflags = ELLIPSIS IGNORE_EXCEPTION_DETAIL NUMBER NORMALIZE_WHITESPACE python_files = **/*.py -testpaths = openfisca_core/commons tests +testpaths = openfisca_core/commons openfisca_core/types tests [mypy] ignore_missing_imports = True diff --git a/setup.py b/setup.py index 0d674d5264..3603c2ea16 100644 --- a/setup.py +++ b/setup.py @@ -26,6 +26,7 @@ dev_requirements = [ 'autopep8 >= 1.4.0, < 1.6.0', + 'coverage == 6.0.2', 'darglint == 1.8.0', 'flake8 >= 3.9.0, < 4.0.0', 'flake8-bugbear >= 19.3.0, < 20.0.0', @@ -36,7 +37,6 @@ 'openfisca-country-template >= 3.10.0, < 4.0.0', 'openfisca-extension-template >= 1.2.0rc0, < 2.0.0', 'pylint == 2.10.2', - 'pytest-cov == 3.0.0', ] + api_requirements setup( From 47266ac6d56c6bba57b9cbd28f8afce594a0c619 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 26 Oct 2021 21:38:55 +0200 Subject: [PATCH 094/205] Add a coverage safety threshold --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 855af2bbe1..bb3ff50fc5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,6 +32,7 @@ branch = true source = openfisca_core, openfisca_web_api [coverage:report] +fail_under = 75 show_missing = true skip_covered = true skip_empty = true From 97ff07f9c0ea5a0917b8d968af71a22e3256f70d Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 26 Oct 2021 22:34:15 +0200 Subject: [PATCH 095/205] Remove coverage threshold Co-authored-by: Matti Schneider --- openfisca_tasks/test_code.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/openfisca_tasks/test_code.mk b/openfisca_tasks/test_code.mk index 548a2f4755..e3fa452009 100644 --- a/openfisca_tasks/test_code.mk +++ b/openfisca_tasks/test_code.mk @@ -26,7 +26,6 @@ test-core: $(shell pytest -qq --co | cut -f1 -d ":") coverage run -m \ ${openfisca} test $? \ ${openfisca_args} - @${MAKE} test-cov @$(call print_pass,$@:) ## Run country-template tests. From 8c06712df26bd14cdfec1d6e92d0696222c9b621 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 26 Oct 2021 22:51:35 +0200 Subject: [PATCH 096/205] Apply suggestions from review Co-authored-by: Matti Schneider --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c13ab894e9..27d95ddaa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### 35.7.1 [#1075](https://github.com/openfisca/openfisca-core/pull/1075) + +#### Bug fix + +- Fix the collection of OpenFisca-Core tests coverage data + - Tests within `openfisca_core/*` were not run + ## 35.7.0 [#1070](https://github.com/openfisca/openfisca-core/pulls/1070) #### New Features From c69d2ab818ea9544fd359af608f128b84937acda Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 26 Oct 2021 23:56:17 +0200 Subject: [PATCH 097/205] Prefer long options in scripts for readability --- openfisca_tasks/test_code.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openfisca_tasks/test_code.mk b/openfisca_tasks/test_code.mk index e3fa452009..4abcce6aed 100644 --- a/openfisca_tasks/test_code.mk +++ b/openfisca_tasks/test_code.mk @@ -20,7 +20,7 @@ test-code: test-core test-country test-extension @$(call print_pass,$@:) ## Run openfisca-core tests. -test-core: $(shell pytest -qq --co | cut -f1 -d ":") +test-core: $(shell pytest --quiet --quiet --collect-only | cut -f 1 -d ":") @$(call print_help,$@:) @PYTEST_ADDOPTS="$${PYTEST_ADDOPTS} ${pytest_args}" \ coverage run -m \ From 693a6cb9cfee95cfbdf576c2d2e958e283f36f54 Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Tue, 26 Oct 2021 21:45:38 +0200 Subject: [PATCH 098/205] Bump patch to 35.7.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3603c2ea16..36e30a751e 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( name = 'OpenFisca-Core', - version = '35.7.0', + version = '35.7.1', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From 70440fe192d2cfc02d6cca12777765554bef4535 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 10:07:17 +0200 Subject: [PATCH 099/205] Add GitHub Actions config --- .github/get-numpy-version.py | 38 ++++ .github/has-functional-changes.sh | 12 ++ .github/is-version-number-acceptable.sh | 33 ++++ .github/lint-changed-python-files.sh | 11 ++ .github/lint-changed-yaml-tests.sh | 11 ++ .github/publish-git-tag.sh | 4 + .github/publish-python-package.sh | 4 + .github/workflows/workflow.yml | 225 ++++++++++++++++++++++++ 8 files changed, 338 insertions(+) create mode 100755 .github/get-numpy-version.py create mode 100755 .github/has-functional-changes.sh create mode 100755 .github/is-version-number-acceptable.sh create mode 100755 .github/lint-changed-python-files.sh create mode 100755 .github/lint-changed-yaml-tests.sh create mode 100755 .github/publish-git-tag.sh create mode 100755 .github/publish-python-package.sh create mode 100644 .github/workflows/workflow.yml diff --git a/.github/get-numpy-version.py b/.github/get-numpy-version.py new file mode 100755 index 0000000000..64cb68532e --- /dev/null +++ b/.github/get-numpy-version.py @@ -0,0 +1,38 @@ +#! /usr/bin/env python + +from __future__ import annotations + +import os +import sys +import typing +from packaging import version +from typing import NoReturn, Union + +import numpy + +if typing.TYPE_CHECKING: + from packaging.version import LegacyVersion, Version + + +def prev() -> NoReturn: + release = _installed().release + + if release is None: + sys.exit(os.EX_DATAERR) + + major, minor, _ = release + + if minor == 0: + sys.exit(os.EX_DATAERR) + + minor -= 1 + print(f"{major}.{minor}.0") # noqa: T001 + sys.exit(os.EX_OK) + + +def _installed() -> Union[LegacyVersion, Version]: + return version.parse(numpy.__version__) + + +if __name__ == "__main__": + globals()[sys.argv[1]]() diff --git a/.github/has-functional-changes.sh b/.github/has-functional-changes.sh new file mode 100755 index 0000000000..15706e8a1b --- /dev/null +++ b/.github/has-functional-changes.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env bash + +IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore LICENSE* .github/* tests/*" + +last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in master through an unlikely intermediary merge commit + +if git diff-index --name-only --exit-code $last_tagged_commit -- . `echo " $IGNORE_DIFF_ON" | sed 's/ / :(exclude)/g'` # Check if any file that has not be listed in IGNORE_DIFF_ON has changed since the last tag was published. +then + echo "No functional changes detected." + exit 1 +else echo "The functional files above were changed." +fi diff --git a/.github/is-version-number-acceptable.sh b/.github/is-version-number-acceptable.sh new file mode 100755 index 0000000000..f4fb2c1bcf --- /dev/null +++ b/.github/is-version-number-acceptable.sh @@ -0,0 +1,33 @@ +#! /usr/bin/env bash + +if [[ ${GITHUB_REF#refs/heads/} == master ]] +then + echo "No need for a version check on master." + exit 0 +fi + +if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh +then + echo "No need for a version update." + exit 0 +fi + +current_version=`python setup.py --version` + +if git rev-parse --verify --quiet $current_version +then + echo "Version $current_version already exists in commit:" + git --no-pager log -1 $current_version + echo + echo "Update the version number in setup.py before merging this branch into master." + echo "Look at the CONTRIBUTING.md file to learn how the version number should be updated." + exit 1 +fi + +if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh | grep --quiet CHANGELOG.md +then + echo "CHANGELOG.md has not been modified, while functional changes were made." + echo "Explain what you changed before merging this branch into master." + echo "Look at the CONTRIBUTING.md file to learn how to write the changelog." + exit 2 +fi diff --git a/.github/lint-changed-python-files.sh b/.github/lint-changed-python-files.sh new file mode 100755 index 0000000000..72d8aad639 --- /dev/null +++ b/.github/lint-changed-python-files.sh @@ -0,0 +1,11 @@ +#! /usr/bin/env bash + +last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in master through an unlikely intermediary merge commit + +if ! changes=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "*.py") +then + echo "Linting the following Python files:" + echo $changes + flake8 $changes +else echo "No changed Python files to lint" +fi diff --git a/.github/lint-changed-yaml-tests.sh b/.github/lint-changed-yaml-tests.sh new file mode 100755 index 0000000000..16e99432b6 --- /dev/null +++ b/.github/lint-changed-yaml-tests.sh @@ -0,0 +1,11 @@ +#! /usr/bin/env bash + +last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in master through an unlikely intermediary merge commit + +if ! changes=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "tests/*.yaml") +then + echo "Linting the following changed YAML tests:" + echo $changes + yamllint $changes +else echo "No changed YAML tests to lint" +fi diff --git a/.github/publish-git-tag.sh b/.github/publish-git-tag.sh new file mode 100755 index 0000000000..4450357cbc --- /dev/null +++ b/.github/publish-git-tag.sh @@ -0,0 +1,4 @@ +#! /usr/bin/env bash + +git tag `python setup.py --version` +git push --tags # update the repository version diff --git a/.github/publish-python-package.sh b/.github/publish-python-package.sh new file mode 100755 index 0000000000..8d331bd946 --- /dev/null +++ b/.github/publish-python-package.sh @@ -0,0 +1,4 @@ +#! /usr/bin/env bash + +python setup.py bdist_wheel # build this package in the dist directory +twine upload dist/* --username $PYPI_USERNAME --password $PYPI_PASSWORD # publish diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 0000000000..53a467210e --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,225 @@ +name: OpenFisca Core + +on: [ push ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} # Cache the entire build Python environment + - name: Build + if: steps.restore-install.outputs.cache-hit != 'true' + run: make build + - name: Cache build release + id: restore-build-release + uses: actions/cache@v2 + with: + path: dist + key: ${{ github.ref }}${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }} + + test-python: + runs-on: ubuntu-latest + needs: [ build ] + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + - name: Run Core tests + run: env PYTEST_ADDOPTS="--exitfirst" make test + + check-numpy: + runs-on: ubuntu-latest + needs: [ build ] + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + - name: Check NumPy typing against latest 3 minor versions + run: for i in {1..3}; do VERSION=$(${GITHUB_WORKSPACE}/.github/get-numpy-version.py prev) && pip install numpy==$VERSION && make check-types; done + + test-country-template: + runs-on: ubuntu-latest + needs: [ build ] + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + - name: Run Country Template tests + run: | + COUNTRY_TEMPLATE_PATH=`python -c "import openfisca_country_template; print(openfisca_country_template.CountryTaxBenefitSystem().get_package_metadata()['location'])"` + openfisca test $COUNTRY_TEMPLATE_PATH/openfisca_country_template/tests/ + + test-docs: + runs-on: ubuntu-latest + needs: [ build ] + steps: + - uses: actions/checkout@v2 + - name: Checkout docs + run: make test-doc-checkout branch=${GITHUB_REF#refs/heads/} + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + - name: Cache docs + id: restore-docs + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: ${{ github.ref }}${{ env.pythonLocation }}-docs-${{ hashFiles('doc/requirements.txt') }} + - name: Install dependencies + run: make test-doc-install + - name: Run doc tests + run: make test-doc-build + + lint-files: + runs-on: ubuntu-latest + needs: [ build ] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch all the tags + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + - run: make check-syntax-errors + - run: make check-style + - name: Lint Python files + run: "${GITHUB_WORKSPACE}/.github/lint-changed-python-files.sh" + - name: Lint YAML tests + run: "${GITHUB_WORKSPACE}/.github/lint-changed-yaml-tests.sh" + + check-version: + runs-on: ubuntu-latest + needs: [ test-python, check-numpy, test-country-template, test-doc, lint-files ] # Last job to run + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch all the tags + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Check version number has been properly updated + run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" + + sumbit-coverage: + runs-on: ubuntu-latest + needs: [ test-python, check-numpy, test-country-template ] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch all the tags + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + - name: Submit coverage to Coveralls + run: | + pip install coveralls + coveralls + + check-for-functional-changes: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/master' # Only triggered for the `master` branch + needs: [ check-version ] + outputs: + status: ${{ steps.stop-early.outputs.status }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch all the tags + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7.12 + - id: stop-early + run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi + + deploy: + runs-on: ubuntu-latest + needs: [ check-for-functional-changes ] + if: needs.check-for-functional-changes.outputs.status == 'success' + env: + PYPI_USERNAME: openfisca-bot + PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch all the tags + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + - name: Cache build release + id: restore-build-release + uses: actions/cache@v2 + with: + path: dist + key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }} + - name: Upload a Python package to PyPi + run: twine upload dist/* --username $PYPI_USERNAME --password $PYPI_PASSWORD + - name: Publish a git tag + run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" + - name: Update doc + run: | + curl -X POST --header "Content-Type: application/json" -d '{"branch":"master"}' https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=$CIRCLE_TOKEN From 811b6219f6e7534609ce7fad71cd84490014d608 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 10:08:49 +0200 Subject: [PATCH 100/205] Correct indent --- .github/workflows/workflow.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 53a467210e..c2bfcb2ca8 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -52,9 +52,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.7 + uses: actions/setup-python@v2 + with: + python-version: 3.7 - name: Cache build id: restore-build uses: actions/cache@v2 From dc70f8904ba62f4314c6a1d1e4f0ce8e26bce68f Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 10:09:47 +0200 Subject: [PATCH 101/205] Correct indent --- .github/workflows/workflow.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index c2bfcb2ca8..98f4897b00 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -70,9 +70,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.7 + uses: actions/setup-python@v2 + with: + python-version: 3.7 - name: Cache build id: restore-build uses: actions/cache@v2 From 698f1a85b2652e6c6d945cd508b482b61c0943aa Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 10:11:51 +0200 Subject: [PATCH 102/205] Change quotes --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 98f4897b00..af5cc8bdf0 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -222,4 +222,4 @@ jobs: run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" - name: Update doc run: | - curl -X POST --header "Content-Type: application/json" -d '{"branch":"master"}' https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=$CIRCLE_TOKEN + curl -X POST --header 'Content-Type: application/json' -d '{"branch":"master"}' https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=$CIRCLE_TOKEN From e12cf4adf0432508e128b49d0f974abaecb12c1d Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 10:13:16 +0200 Subject: [PATCH 103/205] Correct job name --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index af5cc8bdf0..b66566e984 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -138,7 +138,7 @@ jobs: check-version: runs-on: ubuntu-latest - needs: [ test-python, check-numpy, test-country-template, test-doc, lint-files ] # Last job to run + needs: [ test-python, check-numpy, test-country-template, test-docs, lint-files ] # Last job to run steps: - uses: actions/checkout@v2 with: From 0c64a30b325d1747369cd296cbe25d3e389dcb52 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 10:40:50 +0200 Subject: [PATCH 104/205] Test pytest --- .github/workflows/workflow.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index b66566e984..65447ec28e 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -44,7 +44,8 @@ jobs: path: ${{ env.pythonLocation }} key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} - name: Run Core tests - run: env PYTEST_ADDOPTS="--exitfirst" make test + # run: env PYTEST_ADDOPTS="--exitfirst" make test + run: pytest check-numpy: runs-on: ubuntu-latest From 4334c29adbc5e5d640c268e23df680da546d5151 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 10:53:12 +0200 Subject: [PATCH 105/205] Test make test --- .github/workflows/workflow.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 65447ec28e..b66566e984 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -44,8 +44,7 @@ jobs: path: ${{ env.pythonLocation }} key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} - name: Run Core tests - # run: env PYTEST_ADDOPTS="--exitfirst" make test - run: pytest + run: env PYTEST_ADDOPTS="--exitfirst" make test check-numpy: runs-on: ubuntu-latest From 9c8643181bd48cc71c33a43c9acba9c786e1747e Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 11:20:24 +0200 Subject: [PATCH 106/205] Test make test --- .github/workflows/workflow.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index b66566e984..f6c1025ca7 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -44,7 +44,9 @@ jobs: path: ${{ env.pythonLocation }} key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} - name: Run Core tests - run: env PYTEST_ADDOPTS="--exitfirst" make test + run: | + shopt -s globstar + env PYTEST_ADDOPTS="--exitfirst" make test check-numpy: runs-on: ubuntu-latest From f390aa43d3a2af517f2edd39678e6fde4692d3f3 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 11:29:28 +0200 Subject: [PATCH 107/205] Add test to build job --- .github/workflows/workflow.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f6c1025ca7..4804b3078c 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -27,6 +27,8 @@ jobs: with: path: dist key: ${{ github.ref }}${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }} + - name: Run tests + run: env PYTEST_ADDOPTS="--exitfirst" make test test-python: runs-on: ubuntu-latest From 7b8f2f817a4367f4810a26c34dedba03dc2d1eb9 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 11:35:00 +0200 Subject: [PATCH 108/205] Test pytest in build --- .github/workflows/workflow.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 4804b3078c..9f654dda73 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -34,7 +34,8 @@ jobs: runs-on: ubuntu-latest needs: [ build ] steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: @@ -46,9 +47,7 @@ jobs: path: ${{ env.pythonLocation }} key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} - name: Run Core tests - run: | - shopt -s globstar - env PYTEST_ADDOPTS="--exitfirst" make test + run: env PYTEST_ADDOPTS="--exitfirst" make test check-numpy: runs-on: ubuntu-latest From 0c6c8e0ce561360f29a890c1f64e9157763393f0 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 11:38:57 +0200 Subject: [PATCH 109/205] Add dist cache to test-python --- .github/workflows/workflow.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 9f654dda73..0ddeee26bc 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -46,6 +46,12 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + - name: Cache build release + id: restore-build-release + uses: actions/cache@v2 + with: + path: dist + key: ${{ github.ref }}${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }} - name: Run Core tests run: env PYTEST_ADDOPTS="--exitfirst" make test From 080405c6f0cbc7702ffff52c8ecfd840feeac8ff Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 12:09:42 +0200 Subject: [PATCH 110/205] Add cache coverage --- .github/workflows/workflow.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 0ddeee26bc..c4203e58c1 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -27,15 +27,21 @@ jobs: with: path: dist key: ${{ github.ref }}${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }} + - name: Cache coverage + id: restore-coverage + uses: actions/cache@v2 + with: + path: .coverage + key: ${{ github.ref }}${{ env.pythonLocation }}-coverage - name: Run tests run: env PYTEST_ADDOPTS="--exitfirst" make test + test-python: runs-on: ubuntu-latest needs: [ build ] steps: - - name: Checkout - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: @@ -46,12 +52,12 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} - - name: Cache build release - id: restore-build-release + - name: Cache coverage + id: restore-coverage uses: actions/cache@v2 with: - path: dist - key: ${{ github.ref }}${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }} + path: .coverage + key: ${{ github.ref }}${{ env.pythonLocation }}-coverage - name: Run Core tests run: env PYTEST_ADDOPTS="--exitfirst" make test From de9ea78594075c9785524fca29d98d1e3a1e2fdb Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 12:13:15 +0200 Subject: [PATCH 111/205] Test make test alone --- .github/workflows/workflow.yml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index c4203e58c1..6e19e3a2f7 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -27,12 +27,6 @@ jobs: with: path: dist key: ${{ github.ref }}${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }} - - name: Cache coverage - id: restore-coverage - uses: actions/cache@v2 - with: - path: .coverage - key: ${{ github.ref }}${{ env.pythonLocation }}-coverage - name: Run tests run: env PYTEST_ADDOPTS="--exitfirst" make test @@ -52,14 +46,8 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} - - name: Cache coverage - id: restore-coverage - uses: actions/cache@v2 - with: - path: .coverage - key: ${{ github.ref }}${{ env.pythonLocation }}-coverage - name: Run Core tests - run: env PYTEST_ADDOPTS="--exitfirst" make test + run: make test check-numpy: runs-on: ubuntu-latest From 9d83e474d4d893bdf0a2f3eefde3e16d2b160064 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 12:16:04 +0200 Subject: [PATCH 112/205] Add install to test job --- .github/workflows/workflow.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 6e19e3a2f7..31b924aebb 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -46,6 +46,7 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + - run: make install - name: Run Core tests run: make test From 935da567a4d4d75bde7596ac62450ba073772bed Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 13:05:41 +0200 Subject: [PATCH 113/205] Add github token --- .github/workflows/workflow.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 31b924aebb..bc83b1e416 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -34,6 +34,8 @@ jobs: test-python: runs-on: ubuntu-latest needs: [ build ] + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - name: Set up Python @@ -46,7 +48,6 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} - - run: make install - name: Run Core tests run: make test @@ -157,6 +158,8 @@ jobs: sumbit-coverage: runs-on: ubuntu-latest needs: [ test-python, check-numpy, test-country-template ] + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 with: From f0f0fe213a57b5c6f4a197dfa6892885eb6fa37a Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 13:07:14 +0200 Subject: [PATCH 114/205] Remove tests from build --- .github/workflows/workflow.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index bc83b1e416..61526433bb 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -27,9 +27,6 @@ jobs: with: path: dist key: ${{ github.ref }}${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }} - - name: Run tests - run: env PYTEST_ADDOPTS="--exitfirst" make test - test-python: runs-on: ubuntu-latest From 01ed806bc189571cf66e3835de70d7bac6cb329e Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 29 Sep 2021 13:09:27 +0200 Subject: [PATCH 115/205] Add build to test job --- .github/workflows/workflow.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 61526433bb..084fb9accd 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -18,7 +18,7 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} # Cache the entire build Python environment - - name: Build + - name: Build package if: steps.restore-install.outputs.cache-hit != 'true' run: make build - name: Cache build release @@ -45,6 +45,8 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + - name: Build package + run: make build - name: Run Core tests run: make test From 6ff431c21131c0a9050b9882d7cd74a2e97675cc Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 10:25:56 +0200 Subject: [PATCH 116/205] Add restore keys to build cache --- .github/workflows/workflow.yml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 084fb9accd..4bd58af450 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -17,7 +17,11 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} # Cache the entire build Python environment + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} # Cache the entire build Python environment + restore-keys: | + ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }} + ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + ${{ env.pythonLocation }}-build- - name: Build package if: steps.restore-install.outputs.cache-hit != 'true' run: make build @@ -26,7 +30,7 @@ jobs: uses: actions/cache@v2 with: path: dist - key: ${{ github.ref }}${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }} + key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} test-python: runs-on: ubuntu-latest @@ -44,7 +48,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - name: Build package run: make build - name: Run Core tests @@ -64,7 +68,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - name: Check NumPy typing against latest 3 minor versions run: for i in {1..3}; do VERSION=$(${GITHUB_WORKSPACE}/.github/get-numpy-version.py prev) && pip install numpy==$VERSION && make check-types; done @@ -82,7 +86,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - name: Run Country Template tests run: | COUNTRY_TEMPLATE_PATH=`python -c "import openfisca_country_template; print(openfisca_country_template.CountryTaxBenefitSystem().get_package_metadata()['location'])"` @@ -104,7 +108,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - name: Cache docs id: restore-docs uses: actions/cache@v2 @@ -132,7 +136,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + key: $${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - run: make check-syntax-errors - run: make check-style - name: Lint Python files @@ -172,7 +176,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ github.ref }}${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - name: Submit coverage to Coveralls run: | pip install coveralls @@ -215,13 +219,13 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - name: Cache build release id: restore-build-release uses: actions/cache@v2 with: path: dist - key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }} + key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - name: Upload a Python package to PyPi run: twine upload dist/* --username $PYPI_USERNAME --password $PYPI_PASSWORD - name: Publish a git tag From 7f3740809fc4cf4d507b7297cd9b2cd52d910fc1 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 10:27:33 +0200 Subject: [PATCH 117/205] Remove cache hit condition --- .github/workflows/workflow.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 4bd58af450..cf1ee25d8c 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -23,7 +23,6 @@ jobs: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} ${{ env.pythonLocation }}-build- - name: Build package - if: steps.restore-install.outputs.cache-hit != 'true' run: make build - name: Cache build release id: restore-build-release From c1f4f43b2fff848ece14ea22e1528ead3ff82af9 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 10:35:31 +0200 Subject: [PATCH 118/205] Remove build from test --- .github/workflows/workflow.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index cf1ee25d8c..0dc1940da3 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -48,8 +48,6 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - - name: Build package - run: make build - name: Run Core tests run: make test From bfa5f734cc51f2c6d5ecab2bc3897de18c790e43 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 10:38:27 +0200 Subject: [PATCH 119/205] Remove restore keys --- .github/workflows/workflow.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 0dc1940da3..41bda55e0b 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -18,10 +18,6 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} # Cache the entire build Python environment - restore-keys: | - ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }} - ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} - ${{ env.pythonLocation }}-build- - name: Build package run: make build - name: Cache build release From daaa366a26ae62b66bf896d89114cf68b5fa0879 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 10:43:09 +0200 Subject: [PATCH 120/205] Add restore keys and correct typo --- .github/workflows/workflow.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 41bda55e0b..4afd3a88e1 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -18,6 +18,10 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} # Cache the entire build Python environment + restore-keys: | + ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }} + ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} + ${{ env.pythonLocation }}-build- - name: Build package run: make build - name: Cache build release @@ -129,7 +133,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: $${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - run: make check-syntax-errors - run: make check-style - name: Lint Python files From 114f5213356d3fc28f001f7a43d58c8fe0aeeb25 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 10:55:32 +0200 Subject: [PATCH 121/205] Remove step output from check-for-functional-changes --- .github/workflows/workflow.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 4afd3a88e1..700db8a802 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -194,12 +194,11 @@ jobs: with: python-version: 3.7.12 - id: stop-early - run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi + run: "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" deploy: runs-on: ubuntu-latest needs: [ check-for-functional-changes ] - if: needs.check-for-functional-changes.outputs.status == 'success' env: PYPI_USERNAME: openfisca-bot PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} From e090bd472bfc847b07b92e141d3b68b7e48ce2a6 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 10:59:03 +0200 Subject: [PATCH 122/205] Test pytest --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 700db8a802..e5db2b5d2e 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -49,7 +49,7 @@ jobs: path: ${{ env.pythonLocation }} key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - name: Run Core tests - run: make test + run: pytest check-numpy: runs-on: ubuntu-latest From 46efb5dc6e8d4e19ba77b5ba01ac1d2c8a99a702 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 11:08:13 +0200 Subject: [PATCH 123/205] Add Python version patch --- .github/workflows/workflow.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index e5db2b5d2e..0deca47792 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -11,7 +11,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -41,7 +41,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -59,7 +59,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -77,7 +77,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -99,7 +99,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -127,7 +127,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -151,7 +151,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Check version number has been properly updated run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" @@ -167,7 +167,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -209,7 +209,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 From bd1700f296ae2262b78af4ff63e964ff361fbde0 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 11:28:45 +0200 Subject: [PATCH 124/205] Add env cache --- .github/workflows/workflow.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 0deca47792..4277fc54fd 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -22,6 +22,12 @@ jobs: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }} ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} ${{ env.pythonLocation }}-build- + - name: Cache env + id: restore-env + uses: actions/cache@v2 + with: + path: ${{ env }} + key: ${{ env }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - name: Build package run: make build - name: Cache build release @@ -34,8 +40,6 @@ jobs: test-python: runs-on: ubuntu-latest needs: [ build ] - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - name: Set up Python @@ -48,6 +52,12 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + - name: Cache env + id: restore-env + uses: actions/cache@v2 + with: + path: ${{ env }} + key: ${{ env }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - name: Run Core tests run: pytest From 1dd12404af16653c1008045becbc6f984425e5d7 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 11:31:57 +0200 Subject: [PATCH 125/205] Cache entire home dir --- .github/workflows/workflow.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 4277fc54fd..06f60fc475 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -26,8 +26,8 @@ jobs: id: restore-env uses: actions/cache@v2 with: - path: ${{ env }} - key: ${{ env }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + path: . + key: build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - name: Build package run: make build - name: Cache build release @@ -50,8 +50,8 @@ jobs: id: restore-build uses: actions/cache@v2 with: - path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + path: . + key: build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - name: Cache env id: restore-env uses: actions/cache@v2 From 9164ab75a94d64dd09bfde24829c2a232f3d0228 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 11:35:21 +0200 Subject: [PATCH 126/205] Cache entire home dir --- .github/workflows/workflow.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 06f60fc475..38f1e5e2a4 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -50,14 +50,14 @@ jobs: id: restore-build uses: actions/cache@v2 with: - path: . - key: build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + path: ${{ env.pythonLocation }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - name: Cache env id: restore-env uses: actions/cache@v2 with: - path: ${{ env }} - key: ${{ env }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + path: . + key: build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - name: Run Core tests run: pytest From 0b68e0f17522e39b4a8abb6576aa965a95b9754c Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 11:48:14 +0200 Subject: [PATCH 127/205] Add build to Python test job --- .github/workflows/workflow.yml | 36 ++++++++++++---------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 38f1e5e2a4..7a14dcecee 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -11,7 +11,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7.12 + python-version: 3.7 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -22,12 +22,6 @@ jobs: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }} ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} ${{ env.pythonLocation }}-build- - - name: Cache env - id: restore-env - uses: actions/cache@v2 - with: - path: . - key: build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - name: Build package run: make build - name: Cache build release @@ -45,21 +39,17 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7.12 + python-version: 3.7 - name: Cache build id: restore-build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} - - name: Cache env - id: restore-env - uses: actions/cache@v2 - with: - path: . - key: build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + - name: Build package + run: make build - name: Run Core tests - run: pytest + run: env PYTEST_ADDOPTS="--exitfirst" make test check-numpy: runs-on: ubuntu-latest @@ -69,7 +59,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7.12 + python-version: 3.7 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -87,7 +77,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7.12 + python-version: 3.7 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -109,7 +99,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7.12 + python-version: 3.7 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -137,7 +127,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7.12 + python-version: 3.7 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -161,7 +151,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7.12 + python-version: 3.7 - name: Check version number has been properly updated run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" @@ -177,7 +167,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7.12 + python-version: 3.7 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -202,7 +192,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7.12 + python-version: 3.7 - id: stop-early run: "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" @@ -219,7 +209,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7.12 + python-version: 3.7 - name: Cache build id: restore-build uses: actions/cache@v2 From 1c5ebc77d8c9cce288dd9cf83dc58cffc953c252 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 12:06:25 +0200 Subject: [PATCH 128/205] Add coverage cache --- .github/workflows/workflow.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 7a14dcecee..502fd6bf0b 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -30,6 +30,12 @@ jobs: with: path: dist key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + - name: Cache coverage + id: restore-coverage + uses: actions/cache@v2 + with: + path: .coverage + key: ${{ hashFiles('.coverage) }}-${{ github.sha }} test-python: runs-on: ubuntu-latest @@ -174,6 +180,12 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + - name: Cache coverage + id: restore-coverage + uses: actions/cache@v2 + with: + path: .coverage + key: ${{ hashFiles('.coverage) }}-${{ github.sha }} - name: Submit coverage to Coveralls run: | pip install coveralls From d0df3103822cb30b9cda2755f6e2a19d5ffc8a78 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 12:07:21 +0200 Subject: [PATCH 129/205] Remove branch ref from build cache key --- .github/workflows/workflow.yml | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 502fd6bf0b..d9cccc7718 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -17,9 +17,8 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} # Cache the entire build Python environment + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} # Cache the entire build Python environment restore-keys: | - ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }} ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} ${{ env.pythonLocation }}-build- - name: Build package @@ -29,7 +28,7 @@ jobs: uses: actions/cache@v2 with: path: dist - key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Cache coverage id: restore-coverage uses: actions/cache@v2 @@ -51,7 +50,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Build package run: make build - name: Run Core tests @@ -71,7 +70,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Check NumPy typing against latest 3 minor versions run: for i in {1..3}; do VERSION=$(${GITHUB_WORKSPACE}/.github/get-numpy-version.py prev) && pip install numpy==$VERSION && make check-types; done @@ -89,7 +88,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Run Country Template tests run: | COUNTRY_TEMPLATE_PATH=`python -c "import openfisca_country_template; print(openfisca_country_template.CountryTaxBenefitSystem().get_package_metadata()['location'])"` @@ -111,7 +110,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Cache docs id: restore-docs uses: actions/cache@v2 @@ -139,7 +138,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} - run: make check-syntax-errors - run: make check-style - name: Lint Python files @@ -179,7 +178,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Cache coverage id: restore-coverage uses: actions/cache@v2 @@ -227,13 +226,13 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Cache build release id: restore-build-release uses: actions/cache@v2 with: path: dist - key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }}-${{ github.ref }}-${{ github.sha }} + key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Upload a Python package to PyPi run: twine upload dist/* --username $PYPI_USERNAME --password $PYPI_PASSWORD - name: Publish a git tag From e5b0819c786069a8efc8f191161b8a2a0c5f9571 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 12:10:47 +0200 Subject: [PATCH 130/205] Add missing quotes --- .github/workflows/workflow.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index d9cccc7718..7f2dcc4162 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -34,7 +34,7 @@ jobs: uses: actions/cache@v2 with: path: .coverage - key: ${{ hashFiles('.coverage) }}-${{ github.sha }} + key: ${{ hashFiles('.coverage') }}-${{ github.sha }} test-python: runs-on: ubuntu-latest @@ -184,7 +184,7 @@ jobs: uses: actions/cache@v2 with: path: .coverage - key: ${{ hashFiles('.coverage) }}-${{ github.sha }} + key: ${{ hashFiles('.coverage') }}-${{ github.sha }} - name: Submit coverage to Coveralls run: | pip install coveralls From b8280e16f9c9e304196bff549b0dcea7d7e7b504 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 12:18:34 +0200 Subject: [PATCH 131/205] Add coverage artifact --- .github/workflows/workflow.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 7f2dcc4162..6b615dbe00 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -29,12 +29,11 @@ jobs: with: path: dist key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }}-${{ github.sha }} - - name: Cache coverage - id: restore-coverage - uses: actions/cache@v2 + - name: Upload coverage after build + uses: actions/upload-artifact@v2 with: + name: coverage path: .coverage - key: ${{ hashFiles('.coverage') }}-${{ github.sha }} test-python: runs-on: ubuntu-latest @@ -179,12 +178,10 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} - - name: Cache coverage - id: restore-coverage - uses: actions/cache@v2 + - name: Download coverage from build + uses: actions/download-artifact@v2 with: - path: .coverage - key: ${{ hashFiles('.coverage') }}-${{ github.sha }} + name: coverage - name: Submit coverage to Coveralls run: | pip install coveralls From e3567a6d7a35ca995551139b3ed4b1f40d7b1b03 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 12:25:49 +0200 Subject: [PATCH 132/205] List all dir --- .github/workflows/workflow.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 6b615dbe00..e1c6bf69c7 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -29,6 +29,7 @@ jobs: with: path: dist key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }}-${{ github.sha }} + - run: ls -l - name: Upload coverage after build uses: actions/upload-artifact@v2 with: From 577cadb121db9e384194418c927dba9d544903b5 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 12:30:49 +0200 Subject: [PATCH 133/205] List all dir --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index e1c6bf69c7..03e73edc71 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -29,7 +29,7 @@ jobs: with: path: dist key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }}-${{ github.sha }} - - run: ls -l + - run: ls -al - name: Upload coverage after build uses: actions/upload-artifact@v2 with: From f3ca36de6141a39085c3d24b76ff5874434b94af Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 12:48:48 +0200 Subject: [PATCH 134/205] Add Coveralls GitHub Actions support --- .github/workflows/workflow.yml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 03e73edc71..7077f9cd05 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -29,12 +29,6 @@ jobs: with: path: dist key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }}-${{ github.sha }} - - run: ls -al - - name: Upload coverage after build - uses: actions/upload-artifact@v2 - with: - name: coverage - path: .coverage test-python: runs-on: ubuntu-latest @@ -179,14 +173,9 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} - - name: Download coverage from build - uses: actions/download-artifact@v2 - with: - name: coverage - name: Submit coverage to Coveralls run: | - pip install coveralls - coveralls + coveralls --service=github check-for-functional-changes: runs-on: ubuntu-latest From 2a2f699b4aae51b5e6257452237cfbc03a331233 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 12:52:22 +0200 Subject: [PATCH 135/205] Install coveralls --- .github/workflows/workflow.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 7077f9cd05..2f9e3d04bb 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -175,6 +175,7 @@ jobs: key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Submit coverage to Coveralls run: | + pip install coveralls coveralls --service=github check-for-functional-changes: From 1931d3d419886fd40da6e3e976c24e738c8931b3 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 13:28:20 +0200 Subject: [PATCH 136/205] Change job order --- .github/workflows/workflow.yml | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 2f9e3d04bb..02417ad7b5 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -140,23 +140,9 @@ jobs: - name: Lint YAML tests run: "${GITHUB_WORKSPACE}/.github/lint-changed-yaml-tests.sh" - check-version: - runs-on: ubuntu-latest - needs: [ test-python, check-numpy, test-country-template, test-docs, lint-files ] # Last job to run - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch all the tags - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.7 - - name: Check version number has been properly updated - run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" - sumbit-coverage: runs-on: ubuntu-latest - needs: [ test-python, check-numpy, test-country-template ] + needs: [ test-python, check-numpy, test-country-template, lint-files ] env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: @@ -177,6 +163,19 @@ jobs: run: | pip install coveralls coveralls --service=github + check-version: + runs-on: ubuntu-latest + needs: [ test-python, check-numpy, test-country-template, test-docs, lint-files ] # Last job to run + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch all the tags + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Check version number has been properly updated + run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" check-for-functional-changes: runs-on: ubuntu-latest From 6baf1c06b182c9b6361d6e6255800f851badbb60 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 13:29:07 +0200 Subject: [PATCH 137/205] Add build to submit coverage --- .github/workflows/workflow.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 02417ad7b5..6fe1e4b6dc 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -159,6 +159,7 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} + - run: make build - name: Submit coverage to Coveralls run: | pip install coveralls From 2f1135c3b3324ae50490de2804bedaec4d04ce50 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 13:35:05 +0200 Subject: [PATCH 138/205] Remove build from submit coverage --- .github/workflows/workflow.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 6fe1e4b6dc..02417ad7b5 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -159,7 +159,6 @@ jobs: with: path: ${{ env.pythonLocation }} key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} - - run: make build - name: Submit coverage to Coveralls run: | pip install coveralls From 24b6b2fe5ae6e67c3156335d5d70e3878257db8f Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 13:38:09 +0200 Subject: [PATCH 139/205] Remove circleci config --- .circleci/config.yml | 187 ---------------------- .circleci/get-numpy-version.py | 38 ----- .circleci/has-functional-changes.sh | 12 -- .circleci/is-version-number-acceptable.sh | 33 ---- .circleci/publish-git-tag.sh | 4 - .circleci/publish-python-package.sh | 4 - 6 files changed, 278 deletions(-) delete mode 100644 .circleci/config.yml delete mode 100755 .circleci/get-numpy-version.py delete mode 100755 .circleci/has-functional-changes.sh delete mode 100755 .circleci/is-version-number-acceptable.sh delete mode 100755 .circleci/publish-git-tag.sh delete mode 100755 .circleci/publish-python-package.sh diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 67c45002e0..0000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,187 +0,0 @@ -version: 2 -jobs: - run_tests: - docker: - - image: python:3.7 - environment: - TERM: xterm-256color # To colorize output of make tasks. - - steps: - - checkout - - - restore_cache: - key: v1-py3-{{ .Branch }}-{{ checksum "setup.py" }} - - - run: - name: Create a virtualenv - command: | - mkdir -p /tmp/venv/openfisca_core - python -m venv /tmp/venv/openfisca_core - echo "source /tmp/venv/openfisca_core/bin/activate" >> $BASH_ENV - - - run: - name: Install dependencies - command: | - make install - make clean - # pip install --editable git+https://github.com/openfisca/country-template.git@BRANCH_NAME#egg=OpenFisca-Country-Template # use a specific branch of OpenFisca-Country-Template - # pip install --editable git+https://github.com/openfisca/extension-template.git@BRANCH_NAME#egg=OpenFisca-Extension-Template # use a specific branch of OpenFisca-Extension-Template - - - save_cache: - key: v1-py3-{{ .Branch }}-{{ checksum "setup.py" }} - paths: - - /tmp/venv/openfisca_core - - - run: - name: Run linters - command: make lint - - - run: - name: Run openfisca-core tests - command: make test-core pytest_args="--exitfirst" - - - run: - name: Run country-template tests - command: make test-country pytest_args="--exitfirst" - - - run: - name: Run extension-template tests - command: make test-extension pytest_args="--exitfirst" - - - run: - name: Check NumPy typing against latest 3 minor versions - command: for i in {1..3}; do VERSION=$(.circleci/get-numpy-version.py prev) && pip install numpy==$VERSION && make check-types; done - - - persist_to_workspace: - root: . - paths: - - .coverage - - test_docs: - docker: - - image: python:3.7 - environment: - TERM: xterm-256color # To colorize output of make tasks. - - steps: - - checkout - - - run: - name: Checkout docs - command: make test-doc-checkout branch=$CIRCLE_BRANCH - - - restore_cache: - key: v1-py3-{{ .Branch }}-{{ checksum "setup.py" }} - - - restore_cache: - key: v1-py3-docs-{{ .Branch }}-{{ checksum "doc/requirements.txt" }} - - - run: - name: Create a virtualenv - command: | - mkdir -p /tmp/venv/openfisca_doc - python -m venv /tmp/venv/openfisca_doc - echo "source /tmp/venv/openfisca_doc/bin/activate" >> $BASH_ENV - - - run: - name: Install dependencies - command: make test-doc-install - - - save_cache: - key: v1-py3-docs-{{ .Branch }}-{{ checksum "doc/requirements.txt" }} - paths: - - /tmp/venv/openfisca_doc - - - run: - name: Run doc tests - command: make test-doc-build - - - check_version: - docker: - - image: python:3.7 - - steps: - - checkout - - - run: - name: Check version number has been properly updated - command: | - git fetch - .circleci/is-version-number-acceptable.sh - - submit_coverage: - docker: - - image: python:3.7 - - steps: - - checkout - - - attach_workspace: - at: . - - - restore_cache: - key: v1-py3-{{ .Branch }}-{{ checksum "setup.py" }} - - - run: - name: Submit coverage to Coveralls - command: | - source /tmp/venv/openfisca_core/bin/activate - pip install coveralls - coveralls - - - save_cache: - key: v1-py3-{{ .Branch }}-{{ checksum "setup.py" }} - paths: - - /tmp/venv/openfisca_core - - deploy: - docker: - - image: python:3.7 - environment: - PYPI_USERNAME: openfisca-bot - # PYPI_PASSWORD: this value is set in CircleCI's web interface; do not set it here, it is a secret! - - steps: - - checkout - - - restore_cache: - key: v1-py3-{{ .Branch }}-{{ checksum "setup.py" }} - - - run: - name: Check for functional changes - command: if ! .circleci/has-functional-changes.sh ; then circleci step halt ; fi - - - run: - name: Upload a Python package to Pypi - command: | - source /tmp/venv/openfisca_core/bin/activate - .circleci/publish-python-package.sh - - - run: - name: Publish a git tag - command: .circleci/publish-git-tag.sh - - - run: - name: Update doc - command: | - curl -X POST --header "Content-Type: application/json" -d '{"branch":"master"}' https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=$CIRCLE_TOKEN - -workflows: - version: 2 - build_and_deploy: - jobs: - - run_tests - - test_docs - - check_version - - submit_coverage: - requires: - - run_tests - - deploy: - requires: - - run_tests - - test_docs - - check_version - filters: - branches: - only: master diff --git a/.circleci/get-numpy-version.py b/.circleci/get-numpy-version.py deleted file mode 100755 index 64cb68532e..0000000000 --- a/.circleci/get-numpy-version.py +++ /dev/null @@ -1,38 +0,0 @@ -#! /usr/bin/env python - -from __future__ import annotations - -import os -import sys -import typing -from packaging import version -from typing import NoReturn, Union - -import numpy - -if typing.TYPE_CHECKING: - from packaging.version import LegacyVersion, Version - - -def prev() -> NoReturn: - release = _installed().release - - if release is None: - sys.exit(os.EX_DATAERR) - - major, minor, _ = release - - if minor == 0: - sys.exit(os.EX_DATAERR) - - minor -= 1 - print(f"{major}.{minor}.0") # noqa: T001 - sys.exit(os.EX_OK) - - -def _installed() -> Union[LegacyVersion, Version]: - return version.parse(numpy.__version__) - - -if __name__ == "__main__": - globals()[sys.argv[1]]() diff --git a/.circleci/has-functional-changes.sh b/.circleci/has-functional-changes.sh deleted file mode 100755 index b591716932..0000000000 --- a/.circleci/has-functional-changes.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/env bash - -IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore LICENSE* .circleci/* .github/* openfisca_tasks/*.mk tasks/*.mk tests/*" - -last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in master through an unlikely intermediary merge commit - -if git diff-index --name-only --exit-code $last_tagged_commit -- . `echo " $IGNORE_DIFF_ON" | sed 's/ / :(exclude)/g'` # Check if any file that has not be listed in IGNORE_DIFF_ON has changed since the last tag was published. -then - echo "No functional changes detected." - exit 1 -else echo "The functional files above were changed." -fi diff --git a/.circleci/is-version-number-acceptable.sh b/.circleci/is-version-number-acceptable.sh deleted file mode 100755 index ae370e2a17..0000000000 --- a/.circleci/is-version-number-acceptable.sh +++ /dev/null @@ -1,33 +0,0 @@ -#! /usr/bin/env bash - -if [[ $CIRCLE_BRANCH == master ]] -then - echo "No need for a version check on master." - exit 0 -fi - -if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh -then - echo "No need for a version update." - exit 0 -fi - -current_version=`python setup.py --version` - -if git rev-parse --verify --quiet $current_version -then - echo "Version $current_version already exists in commit:" - git --no-pager log -1 $current_version - echo - echo "Update the version number in setup.py before merging this branch into master." - echo "Look at the CONTRIBUTING.md file to learn how the version number should be updated." - exit 1 -fi - -if ! $(dirname "$BASH_SOURCE")/has-functional-changes.sh | grep --quiet CHANGELOG.md -then - echo "CHANGELOG.md has not been modified, while functional changes were made." - echo "Explain what you changed before merging this branch into master." - echo "Look at the CONTRIBUTING.md file to learn how to write the changelog." - exit 2 -fi diff --git a/.circleci/publish-git-tag.sh b/.circleci/publish-git-tag.sh deleted file mode 100755 index 4450357cbc..0000000000 --- a/.circleci/publish-git-tag.sh +++ /dev/null @@ -1,4 +0,0 @@ -#! /usr/bin/env bash - -git tag `python setup.py --version` -git push --tags # update the repository version diff --git a/.circleci/publish-python-package.sh b/.circleci/publish-python-package.sh deleted file mode 100755 index 8d331bd946..0000000000 --- a/.circleci/publish-python-package.sh +++ /dev/null @@ -1,4 +0,0 @@ -#! /usr/bin/env bash - -python setup.py bdist_wheel # build this package in the dist directory -twine upload dist/* --username $PYPI_USERNAME --password $PYPI_PASSWORD # publish From a63919502b72f9bde7413149e8675ec6a58865cb Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 30 Sep 2021 13:58:44 +0200 Subject: [PATCH 140/205] Add Circle Token to env --- .github/workflows/workflow.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 02417ad7b5..0758455c63 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -199,7 +199,8 @@ jobs: needs: [ check-for-functional-changes ] env: PYPI_USERNAME: openfisca-bot - PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} # Add to GitHub secrets + CIRCLE_TOKEN: ${{ secrets.CIRCLE_TOKEN }} # Add to GitHub secrets steps: - uses: actions/checkout@v2 with: From 2b26fc23298f6648519621a7dd89261cd30852e8 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Fri, 1 Oct 2021 14:53:02 +0200 Subject: [PATCH 141/205] Change test-python name --- .github/workflows/workflow.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 0758455c63..2dea192524 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -30,7 +30,7 @@ jobs: path: dist key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }}-${{ github.sha }} - test-python: + test-core: runs-on: ubuntu-latest needs: [ build ] steps: @@ -142,7 +142,7 @@ jobs: sumbit-coverage: runs-on: ubuntu-latest - needs: [ test-python, check-numpy, test-country-template, lint-files ] + needs: [ test-core, check-numpy, test-country-template, lint-files ] env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: @@ -165,7 +165,7 @@ jobs: coveralls --service=github check-version: runs-on: ubuntu-latest - needs: [ test-python, check-numpy, test-country-template, test-docs, lint-files ] # Last job to run + needs: [ test-core, check-numpy, test-country-template, test-docs, lint-files ] # Last job to run steps: - uses: actions/checkout@v2 with: From 621b8492f64ab388ab02d7abcf275aaae2b7bcf9 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 20 Oct 2021 11:27:15 +0200 Subject: [PATCH 142/205] Rename cache keys --- .github/workflows/workflow.yml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 2dea192524..37133ad74e 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -17,18 +17,18 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} # Cache the entire build Python environment + key: build-${{ env.pythonLocation }}${{ hashFiles('setup.py') }}-${{ github.sha }} restore-keys: | - ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }} - ${{ env.pythonLocation }}-build- + build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }} + build-${{ env.pythonLocation }}- - name: Build package run: make build - - name: Cache build release - id: restore-build-release + - name: Cache release + id: restore-release uses: actions/cache@v2 with: path: dist - key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }}-${{ github.sha }} + key: release-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} test-core: runs-on: ubuntu-latest @@ -44,7 +44,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Build package run: make build - name: Run Core tests @@ -64,7 +64,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Check NumPy typing against latest 3 minor versions run: for i in {1..3}; do VERSION=$(${GITHUB_WORKSPACE}/.github/get-numpy-version.py prev) && pip install numpy==$VERSION && make check-types; done @@ -82,7 +82,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Run Country Template tests run: | COUNTRY_TEMPLATE_PATH=`python -c "import openfisca_country_template; print(openfisca_country_template.CountryTaxBenefitSystem().get_package_metadata()['location'])"` @@ -104,13 +104,13 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Cache docs id: restore-docs uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ github.ref }}${{ env.pythonLocation }}-docs-${{ hashFiles('doc/requirements.txt') }} + key: docs-${{ env.pythonLocation }}-${{ hashFiles('doc/requirements.txt') }}--${{ github.sha }} - name: Install dependencies run: make test-doc-install - name: Run doc tests @@ -132,7 +132,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - run: make check-syntax-errors - run: make check-style - name: Lint Python files @@ -158,7 +158,7 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Submit coverage to Coveralls run: | pip install coveralls @@ -214,13 +214,13 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-build-${{ hashFiles('setup.py') }}-${{ github.sha }} - - name: Cache build release - id: restore-build-release + key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} + - name: Cache release + id: restore-release uses: actions/cache@v2 with: path: dist - key: ${{ env.pythonLocation }}-build-release-${{ hashFiles('setup.py') }}-${{ github.sha }} + key: release-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Upload a Python package to PyPi run: twine upload dist/* --username $PYPI_USERNAME --password $PYPI_PASSWORD - name: Publish a git tag From 319e96a48242d33b7c861982ea714c15d464bbbd Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 20 Oct 2021 11:29:40 +0200 Subject: [PATCH 143/205] Add Python patch --- .github/workflows/workflow.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 37133ad74e..470bd35c2d 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -11,13 +11,13 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} - key: build-${{ env.pythonLocation }}${{ hashFiles('setup.py') }}-${{ github.sha }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} restore-keys: | build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }} build-${{ env.pythonLocation }}- @@ -38,7 +38,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -58,7 +58,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -76,7 +76,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -98,7 +98,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -126,7 +126,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -152,7 +152,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 @@ -173,7 +173,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Check version number has been properly updated run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" @@ -190,7 +190,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - id: stop-early run: "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" @@ -208,7 +208,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.7.12 - name: Cache build id: restore-build uses: actions/cache@v2 From 52c752974a152e617ef77b71ee67e230b092ef20 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Fri, 22 Oct 2021 17:52:56 +0200 Subject: [PATCH 144/205] Add comments --- .github/workflows/workflow.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 470bd35c2d..4b877ab1fb 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -11,14 +11,14 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7.12 + python-version: 3.7.12 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any potentiel difference in patches between jobs will lead to a cache not found error. - name: Cache build id: restore-build uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - restore-keys: | + restore-keys: | # in case of a cache miss (systematically unless the same commit is built repeatedly), the keys below will be used to restore dependencies from previous builds, and the cache will be stored at the end of the job, making up-to-date dependencies available for all jobs of the workflow; see more at https://docs.github.com/en/actions/advanced-guides/caching-dependencies-to-speed-up-workflows#example-using-the-cache-action build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }} build-${{ env.pythonLocation }}- - name: Build package From 9cb521da69609a5ee2cca9182ec2d704fcd52dfc Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Fri, 22 Oct 2021 17:54:48 +0200 Subject: [PATCH 145/205] Add new line --- .github/workflows/workflow.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 4b877ab1fb..9e0a17686e 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -163,6 +163,7 @@ jobs: run: | pip install coveralls coveralls --service=github + check-version: runs-on: ubuntu-latest needs: [ test-core, check-numpy, test-country-template, test-docs, lint-files ] # Last job to run From 89b34fdc59b107c353baa0683fc3db93a3de4ebe Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Fri, 22 Oct 2021 17:59:54 +0200 Subject: [PATCH 146/205] Add step output condition to deploy --- .github/workflows/workflow.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 9e0a17686e..01198f37b3 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -193,11 +193,12 @@ jobs: with: python-version: 3.7.12 - id: stop-early - run: "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" + run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi deploy: runs-on: ubuntu-latest needs: [ check-for-functional-changes ] + if: needs.check-for-functional-changes.outputs.status == 'success' env: PYPI_USERNAME: openfisca-bot PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} # Add to GitHub secrets From 88c600f7710fa003c1d1509e53a31bc9e8684c73 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Fri, 22 Oct 2021 18:18:08 +0200 Subject: [PATCH 147/205] Remove build step from test-core --- .github/workflows/workflow.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 01198f37b3..cc5664d63a 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -45,8 +45,6 @@ jobs: with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - - name: Build package - run: make build - name: Run Core tests run: env PYTEST_ADDOPTS="--exitfirst" make test From 50b05a887896e949d0e12334087edfe7e54090c7 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Fri, 22 Oct 2021 18:34:17 +0200 Subject: [PATCH 148/205] Move submit coverage step to test core job --- .github/workflows/workflow.yml | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index cc5664d63a..783b992ada 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -47,6 +47,10 @@ jobs: key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Run Core tests run: env PYTEST_ADDOPTS="--exitfirst" make test + - name: Submit coverage to Coveralls + run: | + pip install coveralls + coveralls --service=github check-numpy: runs-on: ubuntu-latest @@ -89,6 +93,8 @@ jobs: test-docs: runs-on: ubuntu-latest needs: [ build ] + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - name: Checkout docs @@ -138,30 +144,6 @@ jobs: - name: Lint YAML tests run: "${GITHUB_WORKSPACE}/.github/lint-changed-yaml-tests.sh" - sumbit-coverage: - runs-on: ubuntu-latest - needs: [ test-core, check-numpy, test-country-template, lint-files ] - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch all the tags - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.7.12 - - name: Cache build - id: restore-build - uses: actions/cache@v2 - with: - path: ${{ env.pythonLocation }} - key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - - name: Submit coverage to Coveralls - run: | - pip install coveralls - coveralls --service=github - check-version: runs-on: ubuntu-latest needs: [ test-core, check-numpy, test-country-template, test-docs, lint-files ] # Last job to run From efcdb6299cadd8614f4fd0611a9ac156c49dc440 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Fri, 22 Oct 2021 18:38:36 +0200 Subject: [PATCH 149/205] Add GitHub Actions token to test core job --- .github/workflows/workflow.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 783b992ada..6cfcb1b6c2 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -33,6 +33,8 @@ jobs: test-core: runs-on: ubuntu-latest needs: [ build ] + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - name: Set up Python @@ -93,8 +95,6 @@ jobs: test-docs: runs-on: ubuntu-latest needs: [ build ] - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v2 - name: Checkout docs From 13a99f11649652cd446e7056cb1f487f84293476 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Fri, 22 Oct 2021 19:07:45 +0200 Subject: [PATCH 150/205] Change core test command --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 6cfcb1b6c2..6eac483088 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -48,7 +48,7 @@ jobs: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Run Core tests - run: env PYTEST_ADDOPTS="--exitfirst" make test + run: make test-core pytest_args="--exitfirst" - name: Submit coverage to Coveralls run: | pip install coveralls From 2ae236071075dd7ed004f58b665716b27779426a Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Fri, 22 Oct 2021 21:15:50 +0200 Subject: [PATCH 151/205] Add term to env --- .github/workflows/workflow.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 6eac483088..692d281c66 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -35,6 +35,7 @@ jobs: needs: [ build ] env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TERM: xterm-256color # To colorize output of make tasks. steps: - uses: actions/checkout@v2 - name: Set up Python From 98241c516248c2a6eafe926f1f47a041af7cda32 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Mon, 25 Oct 2021 08:29:15 +0200 Subject: [PATCH 152/205] Add build to test core --- .github/workflows/workflow.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 692d281c66..88879e29b4 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -48,6 +48,8 @@ jobs: with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} + - name: Build package + run: make build - name: Run Core tests run: make test-core pytest_args="--exitfirst" - name: Submit coverage to Coveralls From ef397fe5a9625ddd9ab6085df4e1d2d4a84031ee Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Mon, 25 Oct 2021 08:56:50 +0200 Subject: [PATCH 153/205] Remove build from test core --- .github/workflows/workflow.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 88879e29b4..692d281c66 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -48,8 +48,6 @@ jobs: with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - - name: Build package - run: make build - name: Run Core tests run: make test-core pytest_args="--exitfirst" - name: Submit coverage to Coveralls From 76ce8cff0712b87347982616189427cfa5547433 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 11:16:30 +0200 Subject: [PATCH 154/205] Add term to env --- .github/workflows/workflow.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 692d281c66..63e10735ff 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -5,6 +5,8 @@ on: [ push ] jobs: build: runs-on: ubuntu-latest + env: + TERM: xterm-256color # To colorize output of make tasks. steps: - name: Checkout uses: actions/checkout@v2 From 2533bba39f30d26717c45fafeeceab5e3594b47c Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 11:20:04 +0200 Subject: [PATCH 155/205] Replace linting scripts with make lint --- .github/lint-changed-python-files.sh | 11 ----------- .github/lint-changed-yaml-tests.sh | 11 ----------- .github/workflows/workflow.yml | 14 ++------------ 3 files changed, 2 insertions(+), 34 deletions(-) delete mode 100755 .github/lint-changed-python-files.sh delete mode 100755 .github/lint-changed-yaml-tests.sh diff --git a/.github/lint-changed-python-files.sh b/.github/lint-changed-python-files.sh deleted file mode 100755 index 72d8aad639..0000000000 --- a/.github/lint-changed-python-files.sh +++ /dev/null @@ -1,11 +0,0 @@ -#! /usr/bin/env bash - -last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in master through an unlikely intermediary merge commit - -if ! changes=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "*.py") -then - echo "Linting the following Python files:" - echo $changes - flake8 $changes -else echo "No changed Python files to lint" -fi diff --git a/.github/lint-changed-yaml-tests.sh b/.github/lint-changed-yaml-tests.sh deleted file mode 100755 index 16e99432b6..0000000000 --- a/.github/lint-changed-yaml-tests.sh +++ /dev/null @@ -1,11 +0,0 @@ -#! /usr/bin/env bash - -last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in master through an unlikely intermediary merge commit - -if ! changes=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "tests/*.yaml") -then - echo "Linting the following changed YAML tests:" - echo $changes - yamllint $changes -else echo "No changed YAML tests to lint" -fi diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 63e10735ff..b126e35eb3 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -134,18 +134,8 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.7.12 - - name: Cache build - id: restore-build - uses: actions/cache@v2 - with: - path: ${{ env.pythonLocation }} - key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - - run: make check-syntax-errors - - run: make check-style - - name: Lint Python files - run: "${GITHUB_WORKSPACE}/.github/lint-changed-python-files.sh" - - name: Lint YAML tests - run: "${GITHUB_WORKSPACE}/.github/lint-changed-yaml-tests.sh" + - name: Run linters + run: make lint check-version: runs-on: ubuntu-latest From ab8cbbcb419fc4f187ded120091f7b9a52714f06 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 11:23:25 +0200 Subject: [PATCH 156/205] Rename test core step --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index b126e35eb3..587d5691c2 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -50,7 +50,7 @@ jobs: with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - - name: Run Core tests + - name: Run openfisca-core tests run: make test-core pytest_args="--exitfirst" - name: Submit coverage to Coveralls run: | From 5bd0a088def5d638ecfc106db68262a833c9e99c Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 11:26:54 +0200 Subject: [PATCH 157/205] Replace country test command with make command --- .github/workflows/workflow.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 587d5691c2..e74255756e 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -57,7 +57,7 @@ jobs: pip install coveralls coveralls --service=github - check-numpy: + test-country-template: runs-on: ubuntu-latest needs: [ build ] steps: @@ -72,10 +72,10 @@ jobs: with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - - name: Check NumPy typing against latest 3 minor versions - run: for i in {1..3}; do VERSION=$(${GITHUB_WORKSPACE}/.github/get-numpy-version.py prev) && pip install numpy==$VERSION && make check-types; done + - name: Run Country Template tests + run: make test-country pytest_args="--exitfirst" - test-country-template: + check-numpy: runs-on: ubuntu-latest needs: [ build ] steps: @@ -90,10 +90,8 @@ jobs: with: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - - name: Run Country Template tests - run: | - COUNTRY_TEMPLATE_PATH=`python -c "import openfisca_country_template; print(openfisca_country_template.CountryTaxBenefitSystem().get_package_metadata()['location'])"` - openfisca test $COUNTRY_TEMPLATE_PATH/openfisca_country_template/tests/ + - name: Check NumPy typing against latest 3 minor versions + run: for i in {1..3}; do VERSION=$(${GITHUB_WORKSPACE}/.github/get-numpy-version.py prev) && pip install numpy==$VERSION && make check-types; done test-docs: runs-on: ubuntu-latest From aaa094ccf797da27d91ba269e7852411cf179103 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 11:29:50 +0200 Subject: [PATCH 158/205] Add term to env for every job --- .github/workflows/workflow.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index e74255756e..44559e9d20 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -60,6 +60,8 @@ jobs: test-country-template: runs-on: ubuntu-latest needs: [ build ] + env: + TERM: xterm-256color steps: - uses: actions/checkout@v2 - name: Set up Python @@ -78,6 +80,8 @@ jobs: check-numpy: runs-on: ubuntu-latest needs: [ build ] + env: + TERM: xterm-256color steps: - uses: actions/checkout@v2 - name: Set up Python @@ -96,6 +100,8 @@ jobs: test-docs: runs-on: ubuntu-latest needs: [ build ] + env: + TERM: xterm-256color steps: - uses: actions/checkout@v2 - name: Checkout docs @@ -124,6 +130,8 @@ jobs: lint-files: runs-on: ubuntu-latest needs: [ build ] + env: + TERM: xterm-256color steps: - uses: actions/checkout@v2 with: @@ -138,6 +146,8 @@ jobs: check-version: runs-on: ubuntu-latest needs: [ test-core, check-numpy, test-country-template, test-docs, lint-files ] # Last job to run + env: + TERM: xterm-256color steps: - uses: actions/checkout@v2 with: @@ -153,6 +163,8 @@ jobs: runs-on: ubuntu-latest if: github.ref == 'refs/heads/master' # Only triggered for the `master` branch needs: [ check-version ] + env: + TERM: xterm-256color outputs: status: ${{ steps.stop-early.outputs.status }} steps: @@ -174,6 +186,7 @@ jobs: PYPI_USERNAME: openfisca-bot PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} # Add to GitHub secrets CIRCLE_TOKEN: ${{ secrets.CIRCLE_TOKEN }} # Add to GitHub secrets + TERM: xterm-256color steps: - uses: actions/checkout@v2 with: From 75e02a3f013a814a8ccdacf609e5adb2eb2d0184 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 11:30:43 +0200 Subject: [PATCH 159/205] Add build cache to linting job --- .github/workflows/workflow.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 44559e9d20..3707a9c36b 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -140,6 +140,12 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.7.12 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Run linters run: make lint From aa7546dd29cced1e3d23763566c18411422f433e Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 11:44:46 +0200 Subject: [PATCH 160/205] Test install instead of build --- .github/workflows/workflow.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 3707a9c36b..09ce543a7b 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -24,13 +24,9 @@ jobs: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }} build-${{ env.pythonLocation }}- - name: Build package - run: make build - - name: Cache release - id: restore-release - uses: actions/cache@v2 - with: - path: dist - key: release-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} + run: | + make install + make clean test-core: runs-on: ubuntu-latest From c6738894685e9c7f747bbdf8216b12789485d884 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 11:50:23 +0200 Subject: [PATCH 161/205] Remove make clean from build job --- .github/workflows/workflow.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 09ce543a7b..adee883b7f 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -26,7 +26,6 @@ jobs: - name: Build package run: | make install - make clean test-core: runs-on: ubuntu-latest From e9d116e26d2d6ff570a8d9541e5a4f34fd3f9717 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 12:03:16 +0200 Subject: [PATCH 162/205] Replace install with build --- .github/workflows/workflow.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index adee883b7f..3707a9c36b 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -24,8 +24,13 @@ jobs: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }} build-${{ env.pythonLocation }}- - name: Build package - run: | - make install + run: make build + - name: Cache release + id: restore-release + uses: actions/cache@v2 + with: + path: dist + key: release-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} test-core: runs-on: ubuntu-latest From 0a9714e984ec61245557a84ea6cc9ebfa132b475 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 12:06:27 +0200 Subject: [PATCH 163/205] Add test extension template job --- .github/workflows/workflow.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 3707a9c36b..25ded4c036 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -77,6 +77,26 @@ jobs: - name: Run Country Template tests run: make test-country pytest_args="--exitfirst" + test-extension-template: + runs-on: ubuntu-latest + needs: [ build ] + env: + TERM: xterm-256color + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7.12 + - name: Cache build + id: restore-build + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} + - name: Run Extension Template tests + run: make test-extension pytest_args="--exitfirst" + check-numpy: runs-on: ubuntu-latest needs: [ build ] From 151c5cf09fe05722783fa86206108c994a2d7206 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 12:16:27 +0200 Subject: [PATCH 164/205] Delete publish python package script --- .github/publish-python-package.sh | 4 ---- 1 file changed, 4 deletions(-) delete mode 100755 .github/publish-python-package.sh diff --git a/.github/publish-python-package.sh b/.github/publish-python-package.sh deleted file mode 100755 index 8d331bd946..0000000000 --- a/.github/publish-python-package.sh +++ /dev/null @@ -1,4 +0,0 @@ -#! /usr/bin/env bash - -python setup.py bdist_wheel # build this package in the dist directory -twine upload dist/* --username $PYPI_USERNAME --password $PYPI_PASSWORD # publish From dd29e5c6e4ae620fd09bb4a39095836c4c0d73b4 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 12:22:34 +0200 Subject: [PATCH 165/205] Add test extension to check version requirements --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 25ded4c036..4fb1e8c375 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -171,7 +171,7 @@ jobs: check-version: runs-on: ubuntu-latest - needs: [ test-core, check-numpy, test-country-template, test-docs, lint-files ] # Last job to run + needs: [ test-core, check-numpy, test-country-template, test-extension-template, test-docs, lint-files ] # Last job to run env: TERM: xterm-256color steps: From 3c6e7c656ff8f3fb331abee91636eec5827dfdcf Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 12:49:23 +0200 Subject: [PATCH 166/205] Remove unnecessary term mentions in env --- .github/workflows/workflow.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 4fb1e8c375..89b90132e7 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -171,9 +171,7 @@ jobs: check-version: runs-on: ubuntu-latest - needs: [ test-core, check-numpy, test-country-template, test-extension-template, test-docs, lint-files ] # Last job to run - env: - TERM: xterm-256color + needs: [ test-core, test-country-template, test-extension-template, check-numpy, test-docs, lint-files ] # Last job to run steps: - uses: actions/checkout@v2 with: @@ -189,8 +187,6 @@ jobs: runs-on: ubuntu-latest if: github.ref == 'refs/heads/master' # Only triggered for the `master` branch needs: [ check-version ] - env: - TERM: xterm-256color outputs: status: ${{ steps.stop-early.outputs.status }} steps: @@ -212,7 +208,6 @@ jobs: PYPI_USERNAME: openfisca-bot PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} # Add to GitHub secrets CIRCLE_TOKEN: ${{ secrets.CIRCLE_TOKEN }} # Add to GitHub secrets - TERM: xterm-256color steps: - uses: actions/checkout@v2 with: From 76f38ed52b9c9e84da00d1ff28aa25b189460296 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 15:01:47 +0200 Subject: [PATCH 167/205] Extend ignore diff on to tasks --- .github/has-functional-changes.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/has-functional-changes.sh b/.github/has-functional-changes.sh index 15706e8a1b..bf1270989a 100755 --- a/.github/has-functional-changes.sh +++ b/.github/has-functional-changes.sh @@ -1,6 +1,6 @@ #! /usr/bin/env bash -IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore LICENSE* .github/* tests/*" +IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore LICENSE* .github/* tests/* openfisca_tasks/*.mk tasks/*.mk" last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in master through an unlikely intermediary merge commit From 8d90013b6cb5a9d18c7514211fca4ac30db5bdbe Mon Sep 17 00:00:00 2001 From: Hajar AIT EL KADI <48837850+HAEKADI@users.noreply.github.com> Date: Tue, 26 Oct 2021 15:04:10 +0200 Subject: [PATCH 168/205] Delete extra space Co-authored-by: Matti Schneider --- .github/is-version-number-acceptable.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/is-version-number-acceptable.sh b/.github/is-version-number-acceptable.sh index f4fb2c1bcf..0f704a93fe 100755 --- a/.github/is-version-number-acceptable.sh +++ b/.github/is-version-number-acceptable.sh @@ -1,6 +1,6 @@ #! /usr/bin/env bash -if [[ ${GITHUB_REF#refs/heads/} == master ]] +if [[ ${GITHUB_REF#refs/heads/} == master ]] then echo "No need for a version check on master." exit 0 From da6e52aeeb7a50b13ad80d085da96cc1d3e978a1 Mon Sep 17 00:00:00 2001 From: Hajar AIT EL KADI <48837850+HAEKADI@users.noreply.github.com> Date: Tue, 26 Oct 2021 15:04:58 +0200 Subject: [PATCH 169/205] Improve comment phrasing Co-authored-by: Matti Schneider --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 89b90132e7..45bfc68a73 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -13,7 +13,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.7.12 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. Any potentiel difference in patches between jobs will lead to a cache not found error. + python-version: 3.7.12 # Patch version must be specified to avoid any cache confusion, since the cache key depends on the full Python version. If left unspecified, different patch versions could be allocated between jobs, and any such difference would lead to a cache not found error. - name: Cache build id: restore-build uses: actions/cache@v2 From 3652b30b0c3d73c252817ef44ee118e7b51b425d Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 15:14:02 +0200 Subject: [PATCH 170/205] Remove stop execution on first failure argument --- .github/workflows/workflow.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 45bfc68a73..733312612d 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -51,7 +51,7 @@ jobs: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Run openfisca-core tests - run: make test-core pytest_args="--exitfirst" + run: make test-core - name: Submit coverage to Coveralls run: | pip install coveralls @@ -75,7 +75,7 @@ jobs: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Run Country Template tests - run: make test-country pytest_args="--exitfirst" + run: make test-country test-extension-template: runs-on: ubuntu-latest @@ -95,7 +95,7 @@ jobs: path: ${{ env.pythonLocation }} key: build-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ github.sha }} - name: Run Extension Template tests - run: make test-extension pytest_args="--exitfirst" + run: make test-extension check-numpy: runs-on: ubuntu-latest From a32ba03d89f727c2a7b13b1207779cb813afa3ec Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 15:37:26 +0200 Subject: [PATCH 171/205] Add comments to check-for-functional-changes job --- .github/workflows/workflow.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 733312612d..969f42f296 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -183,6 +183,9 @@ jobs: - name: Check version number has been properly updated run: "${GITHUB_WORKSPACE}/.github/is-version-number-acceptable.sh" + # GitHub Actions does not have a halt job option, to stop from deploying if no functional changes were found. + # We build a separate job to substitute the halt option. + # The `deploy` job is dependent on the output of the `check-for-functional-changes`job. check-for-functional-changes: runs-on: ubuntu-latest if: github.ref == 'refs/heads/master' # Only triggered for the `master` branch @@ -198,7 +201,7 @@ jobs: with: python-version: 3.7.12 - id: stop-early - run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi + run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi # The `check-for-functional-changes` job should always succeed regardless of the `has-functional-changes` script's exit code. Consequently, we do not use that exit code to trigger deploy, but rather a dedicated output variable `status`, to avoid a job failure if the exit code is different from 0. deploy: runs-on: ubuntu-latest From 32034cda81e041e2f0c65694c42eb87e4a03ff05 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 15:40:32 +0200 Subject: [PATCH 172/205] Add CircleCI doc token --- .github/workflows/workflow.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 969f42f296..f880ba30aa 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -209,8 +209,8 @@ jobs: if: needs.check-for-functional-changes.outputs.status == 'success' env: PYPI_USERNAME: openfisca-bot - PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} # Add to GitHub secrets - CIRCLE_TOKEN: ${{ secrets.CIRCLE_TOKEN }} # Add to GitHub secrets + PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + CIRCLE_TOKEN: ${{ secrets.CIRCLECI_OPENFISCADOC_TOKEN }} steps: - uses: actions/checkout@v2 with: From 8c8393daf3e7231d8e7a9c5ccd5462afd83f1570 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 15:50:58 +0200 Subject: [PATCH 173/205] Test deploy for this branch --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f880ba30aa..9e192560aa 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -188,7 +188,7 @@ jobs: # The `deploy` job is dependent on the output of the `check-for-functional-changes`job. check-for-functional-changes: runs-on: ubuntu-latest - if: github.ref == 'refs/heads/master' # Only triggered for the `master` branch + if: github.ref == 'refs/heads/github-actions' # Only triggered for the `master` branch needs: [ check-version ] outputs: status: ${{ steps.stop-early.outputs.status }} From 2b5d1996e7bc2bc9d5ef9c1bdc09b164697b6961 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 15:55:13 +0200 Subject: [PATCH 174/205] Update CHANGELOG and setup --- CHANGELOG.md | 6 ++++++ setup.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27d95ddaa3..0f3787cd9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 35.8.0-beta.1 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) + +#### Technical changes + +- Switch CI provider from CircleCI to GitHub Actions + ### 35.7.1 [#1075](https://github.com/openfisca/openfisca-core/pull/1075) #### Bug fix diff --git a/setup.py b/setup.py index 36e30a751e..20958c1df1 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( name = 'OpenFisca-Core', - version = '35.7.1', + version = '35.8.0-beta.1', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From 41c5f8cdd5bf54c2643e08aa843fcd2cdeccbb19 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 16:10:15 +0200 Subject: [PATCH 175/205] Test updating doc on this branch --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 9e192560aa..dca28baf72 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -237,4 +237,4 @@ jobs: run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" - name: Update doc run: | - curl -X POST --header 'Content-Type: application/json' -d '{"branch":"master"}' https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=$CIRCLE_TOKEN + curl -X POST --header 'Content-Type: application/json' -d '{"branch":"github-actions"}' https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=$CIRCLE_TOKEN From 3bac99e3746a9372f1dfa9f57346c095717b803f Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 26 Oct 2021 16:28:53 +0200 Subject: [PATCH 176/205] Update check-for-functional-changes job comments --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index dca28baf72..a266158ad6 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -201,7 +201,7 @@ jobs: with: python-version: 3.7.12 - id: stop-early - run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi # The `check-for-functional-changes` job should always succeed regardless of the `has-functional-changes` script's exit code. Consequently, we do not use that exit code to trigger deploy, but rather a dedicated output variable `status`, to avoid a job failure if the exit code is different from 0. + run: if "${GITHUB_WORKSPACE}/.github/has-functional-changes.sh" ; then echo "::set-output name=status::success" ; fi # The `check-for-functional-changes` job should always succeed regardless of the `has-functional-changes` script's exit code. Consequently, we do not use that exit code to trigger deploy, but rather a dedicated output variable `status`, to avoid a job failure if the exit code is different from 0. Conversely, if the job fails the entire workflow would be marked as `failed` which is disturbing for contributors. deploy: runs-on: ubuntu-latest From 9f9e1ef6af42b0446509ecb8be3212da2f2a45af Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Wed, 27 Oct 2021 10:33:20 +0200 Subject: [PATCH 177/205] Update CircleCI API version to v2 --- .github/workflows/workflow.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index a266158ad6..93b0483008 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -211,6 +211,7 @@ jobs: PYPI_USERNAME: openfisca-bot PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} CIRCLE_TOKEN: ${{ secrets.CIRCLECI_OPENFISCADOC_TOKEN }} + CIRCLE_BRANCH: ${{ github.head_ref }} steps: - uses: actions/checkout@v2 with: @@ -237,4 +238,9 @@ jobs: run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" - name: Update doc run: | - curl -X POST --header 'Content-Type: application/json' -d '{"branch":"github-actions"}' https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=$CIRCLE_TOKEN + curl -X POST \ + -H 'Circle-Token: $CIRCLE_TOKEN' \ + -H 'Content-Type: application/json' \ + -H 'Accept: application/json' \ + -d "{\"branch\":\"${CIRCLE_BRANCH}\"} \ + https://circleci.com/api/v2/project/github/openfisca/openfisca-doc/build From 72334e58dc674b0ea7bed6e4ccc0fc0aaecfa98e Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 28 Oct 2021 08:45:02 +0200 Subject: [PATCH 178/205] Add missing quotation --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 93b0483008..ea99b96312 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -242,5 +242,5 @@ jobs: -H 'Circle-Token: $CIRCLE_TOKEN' \ -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ - -d "{\"branch\":\"${CIRCLE_BRANCH}\"} \ + -d "{\"branch\":\"${CIRCLE_BRANCH}\"}" \ https://circleci.com/api/v2/project/github/openfisca/openfisca-doc/build From 884929e500ed6312556e50983b493e6a68935a7a Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 28 Oct 2021 09:12:55 +0200 Subject: [PATCH 179/205] Replace CircleCI token with personnal token --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index ea99b96312..a7856e9d7d 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -210,7 +210,7 @@ jobs: env: PYPI_USERNAME: openfisca-bot PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - CIRCLE_TOKEN: ${{ secrets.CIRCLECI_OPENFISCADOC_TOKEN }} + CIRCLE_TOKEN: ${{ secrets.CIRCLECI_V1_OPENFISCADOC_TOKEN }} CIRCLE_BRANCH: ${{ github.head_ref }} steps: - uses: actions/checkout@v2 From 4614b6d30071e1dc9af6b96a196554c0ee7deb4b Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 28 Oct 2021 09:13:31 +0200 Subject: [PATCH 180/205] Update CHANGELOG and setup --- CHANGELOG.md | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f3787cd9e..744f7aae4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 35.8.0-beta.1 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) +## 35.8.0-beta.2 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) #### Technical changes diff --git a/setup.py b/setup.py index 20958c1df1..a905d1d3d2 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( name = 'OpenFisca-Core', - version = '35.8.0-beta.1', + version = '35.8.0-beta.2', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From 63951bebd03cca34887a907b0a4416cb2cebfee6 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 28 Oct 2021 10:36:58 +0200 Subject: [PATCH 181/205] Replace CircleCI API v2 with v1 --- .github/workflows/workflow.yml | 7 +------ CHANGELOG.md | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index a7856e9d7d..486f6492f7 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -238,9 +238,4 @@ jobs: run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" - name: Update doc run: | - curl -X POST \ - -H 'Circle-Token: $CIRCLE_TOKEN' \ - -H 'Content-Type: application/json' \ - -H 'Accept: application/json' \ - -d "{\"branch\":\"${CIRCLE_BRANCH}\"}" \ - https://circleci.com/api/v2/project/github/openfisca/openfisca-doc/build + curl -X POST --header 'Content-Type: application/json' -d '{"branch":"github-actions"}' https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=$CIRCLE_TOKEN diff --git a/CHANGELOG.md b/CHANGELOG.md index 744f7aae4d..4192b5d439 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 35.8.0-beta.2 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) +## 35.8.0-beta.3 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) #### Technical changes diff --git a/setup.py b/setup.py index a905d1d3d2..477de9e692 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( name = 'OpenFisca-Core', - version = '35.8.0-beta.2', + version = '35.8.0-beta.3', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From 1369f482728666c661545109e9b2fa1b090127eb Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 28 Oct 2021 10:43:45 +0200 Subject: [PATCH 182/205] Update branch name --- .github/workflows/workflow.yml | 2 +- CHANGELOG.md | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 486f6492f7..073db85a3d 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -238,4 +238,4 @@ jobs: run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" - name: Update doc run: | - curl -X POST --header 'Content-Type: application/json' -d '{"branch":"github-actions"}' https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=$CIRCLE_TOKEN + curl -X POST --header 'Content-Type: application/json' -d '{\"branch\":\"${CIRCLE_BRANCH}\"}' https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=$CIRCLE_TOKEN diff --git a/CHANGELOG.md b/CHANGELOG.md index 4192b5d439..b127c6a35a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 35.8.0-beta.3 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) +## 35.8.0-beta.4 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) #### Technical changes diff --git a/setup.py b/setup.py index 477de9e692..e12a9c2670 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( name = 'OpenFisca-Core', - version = '35.8.0-beta.3', + version = '35.8.0-beta.4', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From bfbe88030f1d301d69af9ed8ef385c8c93580fb8 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 28 Oct 2021 10:52:44 +0200 Subject: [PATCH 183/205] Change content type format --- .github/workflows/workflow.yml | 2 +- CHANGELOG.md | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 073db85a3d..e5c295ac99 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -238,4 +238,4 @@ jobs: run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" - name: Update doc run: | - curl -X POST --header 'Content-Type: application/json' -d '{\"branch\":\"${CIRCLE_BRANCH}\"}' https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=$CIRCLE_TOKEN + curl -X POST --header "Content-Type: application/json" -d "branch: $CIRCLE_BRANCH" --url https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=$CIRCLE_TOKEN diff --git a/CHANGELOG.md b/CHANGELOG.md index b127c6a35a..729abbf58e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 35.8.0-beta.4 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) +## 35.8.0-beta.5 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) #### Technical changes diff --git a/setup.py b/setup.py index e12a9c2670..a2629fc114 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( name = 'OpenFisca-Core', - version = '35.8.0-beta.4', + version = '35.8.0-beta.5', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From 57afac87f44db74bafd3566d2c6af708dc405569 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 28 Oct 2021 11:04:12 +0200 Subject: [PATCH 184/205] Use master branch for doc --- .github/workflows/workflow.yml | 3 +-- CHANGELOG.md | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index e5c295ac99..f0261ec469 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -211,7 +211,6 @@ jobs: PYPI_USERNAME: openfisca-bot PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} CIRCLE_TOKEN: ${{ secrets.CIRCLECI_V1_OPENFISCADOC_TOKEN }} - CIRCLE_BRANCH: ${{ github.head_ref }} steps: - uses: actions/checkout@v2 with: @@ -238,4 +237,4 @@ jobs: run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" - name: Update doc run: | - curl -X POST --header "Content-Type: application/json" -d "branch: $CIRCLE_BRANCH" --url https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=$CIRCLE_TOKEN + curl -X POST --header "Content-Type: application/json" -d '{"branch":"master"}' https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=$CIRCLE_TOKEN diff --git a/CHANGELOG.md b/CHANGELOG.md index 729abbf58e..d78160d177 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 35.8.0-beta.5 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) +## 35.8.0-beta.6 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) #### Technical changes diff --git a/setup.py b/setup.py index a2629fc114..3caed496ed 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( name = 'OpenFisca-Core', - version = '35.8.0-beta.5', + version = '35.8.0-beta.6', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From 66afdb494ac149d2350b3fe5d209dfcae8f01fe1 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 28 Oct 2021 17:25:18 +0200 Subject: [PATCH 185/205] Update master branch condition to deploy --- .github/workflows/workflow.yml | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f0261ec469..ac882733f4 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -188,7 +188,7 @@ jobs: # The `deploy` job is dependent on the output of the `check-for-functional-changes`job. check-for-functional-changes: runs-on: ubuntu-latest - if: github.ref == 'refs/heads/github-actions' # Only triggered for the `master` branch + if: github.ref == 'refs/heads/master' # Only triggered for the `master` branch needs: [ check-version ] outputs: status: ${{ steps.stop-early.outputs.status }} diff --git a/setup.py b/setup.py index 3caed496ed..6b4ef20dcf 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( name = 'OpenFisca-Core', - version = '35.8.0-beta.6', + version = '35.8.0', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From 2f0e3ddac6aa70f78caf5b639f233e57131e1e68 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 28 Oct 2021 17:27:17 +0200 Subject: [PATCH 186/205] Add CircleCI API toekn comment --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index ac882733f4..f2823a0640 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -210,7 +210,7 @@ jobs: env: PYPI_USERNAME: openfisca-bot PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - CIRCLE_TOKEN: ${{ secrets.CIRCLECI_V1_OPENFISCADOC_TOKEN }} + CIRCLE_TOKEN: ${{ secrets.CIRCLECI_V1_OPENFISCADOC_TOKEN }} # Personal API token created in CircleCI to grant full read and write permissions steps: - uses: actions/checkout@v2 with: From dcd7005f0cc245d2f1d5779786bb43f232ef3307 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Thu, 28 Oct 2021 17:30:33 +0200 Subject: [PATCH 187/205] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d78160d177..fac165eb76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 35.8.0-beta.6 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) +## 35.8.0 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) #### Technical changes From 6de77798439e4615999464ed4afdf48f38d8a1af Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Fri, 29 Oct 2021 09:22:48 -0300 Subject: [PATCH 188/205] Remove obsolete CircleCI badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 7f253c9114..d1ef3da459 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ [![Twitter](https://img.shields.io/badge/twitter-follow%20us!-9cf.svg?style=flat)](https://twitter.com/intent/follow?screen_name=openfisca) [![Slack](https://img.shields.io/badge/slack-join%20us!-blueviolet.svg?style=flat)](mailto:contact%40openfisca.org?subject=Join%20you%20on%20Slack%20%7C%20Nous%20rejoindre%20sur%20Slack&body=%5BEnglish%20version%20below%5D%0A%0ABonjour%2C%0A%0AVotre%C2%A0pr%C3%A9sence%C2%A0ici%C2%A0nous%C2%A0ravit%C2%A0!%20%F0%9F%98%83%0A%0ARacontez-nous%20un%20peu%20de%20vous%2C%20et%20du%20pourquoi%20de%20votre%20int%C3%A9r%C3%AAt%20de%20rejoindre%20la%20communaut%C3%A9%20OpenFisca%20sur%20Slack.%0A%0AAh%C2%A0!%20Et%20si%20vous%20pouviez%20remplir%20ce%20petit%20questionnaire%2C%20%C3%A7a%20serait%20encore%20mieux%C2%A0!%0Ahttps%3A%2F%2Fgoo.gl%2Fforms%2F45M0VR1TYKD1RGzX2%0A%0AN%E2%80%99oubliez%20pas%20de%20nous%20envoyer%20cet%20email%C2%A0!%20Sinon%2C%20on%20ne%20pourra%20pas%20vous%20contacter%20ni%20vous%20inviter%20sur%20Slack.%0A%0AAmiti%C3%A9%2C%0AL%E2%80%99%C3%A9quipe%20OpenFisca%0A%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20ENGLISH%20VERSION%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A%0AHi%2C%20%0A%0AWe're%20glad%20to%20see%20you%20here!%20%F0%9F%98%83%0A%0APlease%20tell%20us%20a%20bit%20about%20you%20and%20why%20you%20want%20to%20join%20the%20OpenFisca%20community%20on%20Slack.%0A%0AAlso%2C%20if%20you%20can%20fill%20out%20this%20short%20survey%2C%20even%20better!%0Ahttps%3A%2F%2Fgoo.gl%2Fforms%2FsOg8K1abhhm441LG2.%0A%0ADon't%20forget%20to%20send%20us%20this%20email!%20Otherwise%20we%20won't%20be%20able%20to%20contact%20you%20back%2C%20nor%20invite%20you%20on%20Slack.%0A%0ACheers%2C%0AThe%20OpenFisca%20Team) -[![CircleCI](https://img.shields.io/circleci/project/github/openfisca/openfisca-core/master.svg?style=flat)](https://circleci.com/gh/openfisca/openfisca-core) [![Coveralls](https://img.shields.io/coveralls/github/openfisca/openfisca-core/master.svg?style=flat)](https://coveralls.io/github/openfisca/openfisca-core?branch=master) [![Python](https://img.shields.io/pypi/pyversions/openfisca-core.svg)](https://pypi.python.org/pypi/openfisca-core) [![PyPi](https://img.shields.io/pypi/v/openfisca-core.svg?style=flat)](https://pypi.python.org/pypi/openfisca-core) From 8453bffb981dee7d44ae893c588404c9a106ec77 Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Fri, 29 Oct 2021 09:22:56 -0300 Subject: [PATCH 189/205] Make CI mention vendor-neutral --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d1ef3da459..7f8b79c150 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ rm -rf doc 7. Finally, open a pull request both in [core](https://github.com/openfisca/openfisca-core/compare/master...fix-doc) and in the [doc](https://github.com/openfisca/openfisca-doc/compare/master...fix-doc). -[CircleCI](.circleci/config.yml) will automatically try to build the documentation from the same branch in both core and the doc (in our example "fix-doc") so we can integrate first our changes to core, and then our changes to the doc. +Continuous integration will automatically try to build the documentation from the same branch in both core and the doc (in our example "fix-doc") so we can integrate first our changes to Core, and then our changes to the doc. If no changes were needed to the doc, then your changes to core will be verified against the production version of the doc. From ec1c3775be906fa1b90e7a5e50f6ddc5792a9c75 Mon Sep 17 00:00:00 2001 From: Hajar AIT EL KADI <48837850+HAEKADI@users.noreply.github.com> Date: Tue, 2 Nov 2021 08:43:28 +0100 Subject: [PATCH 190/205] Replace env variable with direct mention Co-authored-by: Matti Schneider --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f2823a0640..10aff151d2 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -237,4 +237,4 @@ jobs: run: "${GITHUB_WORKSPACE}/.github/publish-git-tag.sh" - name: Update doc run: | - curl -X POST --header "Content-Type: application/json" -d '{"branch":"master"}' https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=$CIRCLE_TOKEN + curl -X POST --header "Content-Type: application/json" -d '{"branch":"master"}' https://circleci.com/api/v1.1/project/github/openfisca/openfisca-doc/build?circle-token=${{ secrets.CIRCLECI_V1_OPENFISCADOC_TOKEN }} From 9b67a3c8c0d1f1c17e5e5a7d0a92c0217e8b147a Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 2 Nov 2021 08:47:44 +0100 Subject: [PATCH 191/205] Bump patch version --- CHANGELOG.md | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fac165eb76..c0bed218ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 35.8.0 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) +### 35.7.2 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) #### Technical changes diff --git a/setup.py b/setup.py index 6b4ef20dcf..0575d56776 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( name = 'OpenFisca-Core', - version = '35.8.0', + version = '35.7.2', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From 01ab4df854abaeb6924d969973c81770cdb08482 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 2 Nov 2021 10:22:05 +0100 Subject: [PATCH 192/205] Delete patch bump --- CHANGELOG.md | 6 ------ setup.py | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0bed218ff..27d95ddaa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,5 @@ # Changelog -### 35.7.2 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) - -#### Technical changes - -- Switch CI provider from CircleCI to GitHub Actions - ### 35.7.1 [#1075](https://github.com/openfisca/openfisca-core/pull/1075) #### Bug fix diff --git a/setup.py b/setup.py index 0575d56776..36e30a751e 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( name = 'OpenFisca-Core', - version = '35.7.2', + version = '35.7.1', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From ff80338e4d202d189bc42e8e689397a2406b2032 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 2 Nov 2021 10:28:59 +0100 Subject: [PATCH 193/205] Bump patch version --- CHANGELOG.md | 6 ++++++ setup.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27d95ddaa3..c0bed218ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +### 35.7.2 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) + +#### Technical changes + +- Switch CI provider from CircleCI to GitHub Actions + ### 35.7.1 [#1075](https://github.com/openfisca/openfisca-core/pull/1075) #### Bug fix diff --git a/setup.py b/setup.py index 36e30a751e..0575d56776 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( name = 'OpenFisca-Core', - version = '35.7.1', + version = '35.7.2', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From cd567c34b9f7ab7c5b6b2cc2019c170c6467b1f7 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 2 Nov 2021 10:38:59 +0100 Subject: [PATCH 194/205] Add install twine wheel to build --- openfisca_tasks/publish.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/openfisca_tasks/publish.mk b/openfisca_tasks/publish.mk index 2bcd2c0ba7..cc3a1d0b50 100644 --- a/openfisca_tasks/publish.mk +++ b/openfisca_tasks/publish.mk @@ -3,6 +3,7 @@ build: @## This allows us to be sure tests are run against the packaged version @## of openfisca-core, the same we put in the hands of users and reusers. @$(call print_help,$@:) + @pip install --upgrade pip twine wheel @python setup.py bdist_wheel @find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \; @$(call print_pass,$@:) From 61f44e2d7f8ddb762a4cfc3dfda9c9571489914d Mon Sep 17 00:00:00 2001 From: Hajar AIT EL KADI <48837850+HAEKADI@users.noreply.github.com> Date: Tue, 2 Nov 2021 11:44:29 +0100 Subject: [PATCH 195/205] Replace wheel with build Co-authored-by: Mauko Quiroga --- openfisca_tasks/publish.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openfisca_tasks/publish.mk b/openfisca_tasks/publish.mk index cc3a1d0b50..75e0184c1a 100644 --- a/openfisca_tasks/publish.mk +++ b/openfisca_tasks/publish.mk @@ -3,7 +3,7 @@ build: @## This allows us to be sure tests are run against the packaged version @## of openfisca-core, the same we put in the hands of users and reusers. @$(call print_help,$@:) - @pip install --upgrade pip twine wheel + @pip install --upgrade pip build twine @python setup.py bdist_wheel @find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \; @$(call print_pass,$@:) From 2cd3e0a1b5f142698894279e0105a37876a12693 Mon Sep 17 00:00:00 2001 From: Hajar AIT EL KADI <48837850+HAEKADI@users.noreply.github.com> Date: Tue, 2 Nov 2021 11:46:57 +0100 Subject: [PATCH 196/205] Replace bdist_wheel with build package Co-authored-by: Mauko Quiroga --- openfisca_tasks/publish.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openfisca_tasks/publish.mk b/openfisca_tasks/publish.mk index 75e0184c1a..32c81ce1b6 100644 --- a/openfisca_tasks/publish.mk +++ b/openfisca_tasks/publish.mk @@ -4,6 +4,6 @@ build: @## of openfisca-core, the same we put in the hands of users and reusers. @$(call print_help,$@:) @pip install --upgrade pip build twine - @python setup.py bdist_wheel + @python -m build @find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \; @$(call print_pass,$@:) From 2647ce43515d764b8ecd34f595a49f1387cb155e Mon Sep 17 00:00:00 2001 From: Hajar AIT EL KADI <48837850+HAEKADI@users.noreply.github.com> Date: Tue, 2 Nov 2021 11:47:31 +0100 Subject: [PATCH 197/205] Update openfisca_tasks/publish.mk Co-authored-by: Mauko Quiroga --- openfisca_tasks/publish.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openfisca_tasks/publish.mk b/openfisca_tasks/publish.mk index 32c81ce1b6..b3cd2cc60b 100644 --- a/openfisca_tasks/publish.mk +++ b/openfisca_tasks/publish.mk @@ -5,5 +5,6 @@ build: @$(call print_help,$@:) @pip install --upgrade pip build twine @python -m build - @find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \; + @pip uninstall --yes openfisca-core + @find dist -name "*.whl" -exec pip install {}[dev] \; @$(call print_pass,$@:) From dcddf93347c4798367f015d5c4361f703b470d17 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 2 Nov 2021 11:51:20 +0100 Subject: [PATCH 198/205] Remove spaces --- openfisca_tasks/publish.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openfisca_tasks/publish.mk b/openfisca_tasks/publish.mk index b3cd2cc60b..4d535a4eb8 100644 --- a/openfisca_tasks/publish.mk +++ b/openfisca_tasks/publish.mk @@ -5,6 +5,6 @@ build: @$(call print_help,$@:) @pip install --upgrade pip build twine @python -m build - @pip uninstall --yes openfisca-core - @find dist -name "*.whl" -exec pip install {}[dev] \; + @pip uninstall --yes openfisca-core + @find dist -name "*.whl" -exec pip install {}[dev] \; @$(call print_pass,$@:) From 517f3108b4a7268e1d5a2409250edb7d5d18d87d Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Tue, 2 Nov 2021 12:11:49 +0100 Subject: [PATCH 199/205] Add .PHONY: build to publish --- openfisca_tasks/publish.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openfisca_tasks/publish.mk b/openfisca_tasks/publish.mk index 4d535a4eb8..28a4b40546 100644 --- a/openfisca_tasks/publish.mk +++ b/openfisca_tasks/publish.mk @@ -1,3 +1,5 @@ +.PHONY: build + ## Install openfisca-core for deployment and publishing. build: @## This allows us to be sure tests are run against the packaged version From 97fc9005a4dc271acfe15a94c457372ec61cca07 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Tue, 2 Nov 2021 16:36:37 +0000 Subject: [PATCH 200/205] Fix message bug --- openfisca_core/populations/population.py | 2 +- src/openfisca-core | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 160000 src/openfisca-core diff --git a/openfisca_core/populations/population.py b/openfisca_core/populations/population.py index 41cdbcd8c4..a0a717ac97 100644 --- a/openfisca_core/populations/population.py +++ b/openfisca_core/populations/population.py @@ -44,7 +44,7 @@ def get_index(self, id): def check_array_compatible_with_entity(self, array): if not self.count == array.size: raise ValueError("Input {} is not a valid value for the entity {} (size = {} != {} = count)".format( - array, self.key, array.size, self.count)) + array, self.entity.key, array.size, self.count)) def check_period_validity(self, variable_name, period): if period is None: diff --git a/src/openfisca-core b/src/openfisca-core new file mode 160000 index 0000000000..da995e477e --- /dev/null +++ b/src/openfisca-core @@ -0,0 +1 @@ +Subproject commit da995e477e46276c0e2627d9e0e11eb33861d2cc From 7ff2ace65dba5158322a6185c0046bf1d564a1ec Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Thu, 11 Nov 2021 16:11:49 -0300 Subject: [PATCH 201/205] Remove submodule Probably added by accident by contributor --- src/openfisca-core | 1 - 1 file changed, 1 deletion(-) delete mode 160000 src/openfisca-core diff --git a/src/openfisca-core b/src/openfisca-core deleted file mode 160000 index da995e477e..0000000000 --- a/src/openfisca-core +++ /dev/null @@ -1 +0,0 @@ -Subproject commit da995e477e46276c0e2627d9e0e11eb33861d2cc From 14b7995036bd814a4d62b5d7c4c1dd0a6072111b Mon Sep 17 00:00:00 2001 From: Nikhil Date: Thu, 11 Nov 2021 19:39:48 +0000 Subject: [PATCH 202/205] Add entry to changelog and patch bump version --- CHANGELOG.md | 4 ++++ setup.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0bed218ff..1be6da81f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### 35.7.3 [#1081](https://github.com/openfisca/openfisca-core/pull/1081) + +- Fix misnamed attribute in mis-sized population error message + ### 35.7.2 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) #### Technical changes diff --git a/setup.py b/setup.py index 0575d56776..227eaae342 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( name = 'OpenFisca-Core', - version = '35.7.2', + version = '35.7.3', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [ From 6dfa8db5606479026e8971477f25d029cc27b69c Mon Sep 17 00:00:00 2001 From: Matti Schneider Date: Thu, 11 Nov 2021 17:00:36 -0300 Subject: [PATCH 203/205] Improve changelog message --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1be6da81f6..19a3d2b07d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### 35.7.3 [#1081](https://github.com/openfisca/openfisca-core/pull/1081) -- Fix misnamed attribute in mis-sized population error message +- Correct error message in case of mis-sized population ### 35.7.2 [#1057](https://github.com/openfisca/openfisca-core/pull/1057) From b7911a3f111252da45437f00d6d9554e38c489a1 Mon Sep 17 00:00:00 2001 From: HAEKADI Date: Fri, 12 Nov 2021 09:12:46 +0100 Subject: [PATCH 204/205] Add pull request as workflow trigger --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 10aff151d2..0a5a1771ff 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,6 +1,6 @@ name: OpenFisca Core -on: [ push ] +on: [push, pull_request] jobs: build: From 6a294a5f36c618cff2f9cadd439442946c30ffd9 Mon Sep 17 00:00:00 2001 From: sandcha Date: Wed, 1 Dec 2021 11:51:30 +0100 Subject: [PATCH 205/205] Bump patch to 35.7.4 --- CHANGELOG.md | 6 ++++++ setup.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19a3d2b07d..ba0b7714cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +### 35.7.4 [#1083](https://github.com/openfisca/openfisca-core/pull/1083) + +#### Technical changes + +- Add GitHub `pull-request` event as a trigger to GitHub Actions workflow + ### 35.7.3 [#1081](https://github.com/openfisca/openfisca-core/pull/1081) - Correct error message in case of mis-sized population diff --git a/setup.py b/setup.py index 227eaae342..2cba798a57 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ setup( name = 'OpenFisca-Core', - version = '35.7.3', + version = '35.7.4', author = 'OpenFisca Team', author_email = 'contact@openfisca.org', classifiers = [