Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Training upgrade #139

Merged
merged 29 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9f0b08c
Major proposed update to country template, introduces pyproject.toml …
verbman Mar 17, 2024
0ba2296
Allow for versions of python >= 3.9
verbman Mar 17, 2024
49726ba
Adjustment to allow OpenFisca-core tests to find repository
verbman Mar 20, 2024
8c54f5e
Update CHANGELOG.md
verbman Mar 20, 2024
08141e8
Resolution for issue 116 regarding changelog entries
verbman Mar 21, 2024
d761ec5
First response to review, quiet git commits in bootstrap.sh, not add …
verbman Apr 4, 2024
600f986
Bootstrap.sh and readme.md updates to improve flow for first users.
verbman Apr 8, 2024
d96b2f3
Disable line-length rule in yamllint, update README.md to include pip…
verbman Apr 8, 2024
b7b130f
Update pyproject.toml on install to switch from Production/Stable to …
verbman Apr 8, 2024
d0c1ffc
CHANGELOG.md updates
verbman Apr 8, 2024
4db6df3
Apply suggestions from code review
verbman Apr 9, 2024
ef71696
Snakecase and while improvements to bootstrap
verbman Apr 9, 2024
0d309ed
Apply suggestions from code review
verbman Apr 22, 2024
f38f8f9
Possible diacritics resolution, simplified bootstrap.sh file and READ…
verbman Apr 22, 2024
188ecd5
Support env variables in bootstrap.sh
MattiSG Apr 23, 2024
875d55d
Bring backwards compatibility to env variables
MattiSG Apr 23, 2024
061900c
Fix casing and improve phrasings
MattiSG Apr 23, 2024
7cdc8bc
Support spaces in jurisdiction name
MattiSG Apr 23, 2024
3fe43ce
Remove unnecessary options
MattiSG Apr 23, 2024
de24fb4
Do not create a new shell session on bootstrap
MattiSG Apr 23, 2024
ae5842a
Fix whitespace
MattiSG Apr 23, 2024
363ecd0
Unify conditions syntax
MattiSG Apr 23, 2024
40819d5
Automatically set up remote
MattiSG Apr 23, 2024
225d206
Make example changelog entry directly usable
MattiSG Apr 23, 2024
3456cb6
Simplify changelog entry
MattiSG Apr 23, 2024
4c842be
Remove unneeded command from bootstrap
verbman Apr 24, 2024
8839eef
Remove counter-productive automatic remote setup
MattiSG Apr 24, 2024
25f0e43
Add comment to keep non-interactive usage
MattiSG Apr 24, 2024
7c38ece
Add Windows compatibility note
MattiSG Apr 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[flake8]
hang-closing = true
ignore = D101,D102,D103,D107,D401,E128,E251,E501,W503
in-place = true
inline-quotes = "
multiline-quotes = """
import-order-style = appnexus
no-accept-encodings = true
application-import-names = openfisca_country_template
application-package-names = openfisca_core
exclude = .git,__pycache__,.venv,.github,.devcontainer,docs

; D101: Variables already provide label/description
; D102/103: Do not document methods/functions
; D107: Do not document __init__ method
; D401: Do not require the imperative mood
; E128/133: Prefer hang-closing visual indents
; E251: Prefer `function(x = 1)` over `function(x=1)`
; E501: Do not enforce a maximum line length
; W503/4: Break lines before binary operators (Knuth's style)
2 changes: 1 addition & 1 deletion .github/has-functional-changes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

IGNORE_DIFF_ON="README.md CONTRIBUTING.md Makefile .gitignore .github/*"

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
last_tagged_commit=$(git describe --tags --abbrev=0 --first-parent) # --first-parent ensures we don't follow tags not published in main 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
Expand Down
8 changes: 4 additions & 4 deletions .github/is-version-number-acceptable.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#! /usr/bin/env bash

if [[ ${GITHUB_REF#refs/heads/} == master ]]
if [[ ${GITHUB_REF#refs/heads/} == main ]]
then
echo "No need for a version check on master."
echo "No need for a version check on main."
exit 0
fi

Expand All @@ -19,15 +19,15 @@ 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 "Update the version number in setup.py before merging this branch into main."
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 "Explain what you changed before merging this branch into main."
echo "Look at the CONTRIBUTING.md file to learn how to write the changelog."
exit 2
fi
2 changes: 1 addition & 1 deletion .github/lint-changed-python-files.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /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
last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit

if ! changes=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "*.py")
then
Expand Down
2 changes: 1 addition & 1 deletion .github/lint-changed-yaml-tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /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
last_tagged_commit=`git describe --tags --abbrev=0 --first-parent` # --first-parent ensures we don't follow tags not published in main through an unlikely intermediary merge commit

if ! changes=$(git diff-index --name-only --diff-filter=ACMR --exit-code $last_tagged_commit -- "tests/*.yaml")
then
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Country-Template

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
types: [ assigned, opened, reopened, synchronize, ready_for_review ]
workflow_dispatch:
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
# The `deploy` job is dependent on the output of the `check-for-functional-changes`job.
check-for-functional-changes:
runs-on: ubuntu-20.04
if: github.ref == 'refs/heads/master' # Only triggered for the `master` branch
if: github.ref == 'refs/heads/main' # Only triggered for the `main` branch
needs: [ check-version-and-changelog ]
outputs:
status: ${{ steps.stop-early.outputs.status }}
Expand Down
6 changes: 6 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

extends: relaxed

rules:
line-length: disable
57 changes: 57 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
# Changelog

## 7.0.0 [#139](https://github.com/openfisca/country-template/pull/139)

* Technical improvement.
* Major change
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any breaking change, so according to semver this could just be a minor 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is the breaking change discussed between this and OpenFisca-Core tests...

* Impacted periods: all.
* Impacted areas: all
* Details:
- Improvements to `bootstrap.sh` to improve experience for first time users:
- remove the need to set `COUNTRY_NAME` and `REPOSITORY_URL` before running
- provide a confirmation option/exit script option before changes are made
- allow for hypens and spaces appropriately
- set `master` branch to `main` by default
- print to console the commit actions along with description
- Change `CONTRIBUTING.md` to allow for improved text replacements
- Replace reference to `master` with `main`
- Change `Makefile`
- Remove reference to `OpenFisca France` replace with new repository name
- replace argument `-e` with longer form `--editable` to aid newcomers
- add new formating commands for `isort`, `pyupgrade` and `yamllint`
- Author default `pyproject.toml` based on the older `setup.py` and `setup.cfg`
- Set version to 7.0.0
- Add in `[project.urls]`: `Homepage`, `Repository`, `Documentation`, `Issues` and `Changelog`
- Add in `[project.optional-dependencies]`: new dependancies `isort`, `pyupgrade` and `yamllint`
- Add `[tool.pytest.ini_options]` with filterwarnings set to `"error"`
- Add `[tool.pylint.messages_control]` from `setup.cfg` but in long form for readability
- Add `[tool.isort]` section
- Add `.flake8` and `.yamllint` to project root as these projects do not support `pyproject.toml` format
- Alter `README.md` to allow for improved text replacements
- Remove commands (line 21) for `export COUNTRY_NAME=France` and `export REPOSITORY_URL=...` due to bootstrap.sh improvements
- Adjust (Line 28) from `git push origin master` to `git push origin main`
- General changes to support change to bootstrap flow
- Remove `setup.py` and `setup.cfg`
- Update `.github/*.sh` and `.github/workflows/workflow.yaml` files to reference `main` instead of `master`
- Fix linting issues in:
- `openfisca_country_template/texts/social_security_contribution.yaml`
- `openfisca_country_template/texts/situations/income_tax.yaml`
- `openfisca_country_template/variables/demographics.py`
- `openfisca_country_template/variables/taxes.py`
- Alter `CHANGELOG.md`, add example entry and alter `bootstrap.sh` to strip out country-template entries. This resolves [issue 116](https://github.com/openfisca/country-template/issues/116).


### 6.0.3 [#136](https://github.com/openfisca/country-template/pull/136)

* Technical improvement.
Expand Down Expand Up @@ -669,3 +710,19 @@ See more on the OpenFisca-Core [changelog](https://github.com/openfisca/openfisc
- `taxes`.
* Details:
- Build the skeleton of the tax and benefit system.

# Example Entry

## 0.0.1 - [#1](https://github.com/openfisca/country-template/pull/1)

* Tax and benefit system evolution.
* Impacted periods: all.
* Impacted areas:
- `benefits`.
- `demographics`.
- `housing`.
- `income`.
- `stats`.
- `taxes`.
* Details:
- Demonstration changelog entry which can be modified for your first entry
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TL;DR: [GitHub Flow](https://guides.github.com/introduction/flow/), [SemVer](htt

## Pull requests

We follow the [GitHub Flow](https://guides.github.com/introduction/flow/): all code contributions are submitted via a pull request towards the `master` branch.
We follow the [GitHub Flow](https://guides.github.com/introduction/flow/): all code contributions are submitted via a pull request towards the `main` branch.

Opening a Pull Request means you want that code to be merged. If you want to only discuss it, send a link to your branch along with your questions through whichever communication channel you prefer.

Expand Down Expand Up @@ -48,19 +48,19 @@ Examples:

### Changelog

OpenFisca-Country-Template changes must be understood by users who don't necessarily work on the code. The Changelog must therefore be as explicit as possible.
openfisca-country_template changes must be understood by users who don't necessarily work on the code. The Changelog must therefore be as explicit as possible.

Each change must be documented with the following elements:

- On the first line appears as a title the version number, as well as a link towards the Pull Request introducing the change. The title level must match the incrementation level of the version.


> For instance :
> # 13.0.0 - [#671](https://github.com/openfisca/openfisca-france/pull/671)
> # 13.0.0 - [#671](https://example.com/repository/pull/671)
>
> ## 13.2.0 - [#676](https://github.com/openfisca/openfisca-france/pull/676)
> ## 13.2.0 - [#676](https://example.com/repository/pull/676)
>
> ### 13.1.5 - [#684](https://github.com/openfisca/openfisca-france/pull/684)
> ### 13.1.5 - [#684](https://example.com/repository/pull/684)

- The second line indicates the type of the change. The possible types are:
- `Tax and benefit system evolution`: Calculation improvement, fix, or update. Impacts the users interested in calculations.
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ deps:

install: deps
@# Install OpenFisca-Extension-Template for development.
@# `make install` installs the editable version of OpenFisca-France.
@# `make install` installs the editable version of openfisca-country_template.
@# This allows contributors to test as they code.
pip install -e '.[dev]' --upgrade --use-deprecated=legacy-resolver
MattiSG marked this conversation as resolved.
Show resolved Hide resolved
pip install --editable .[dev] --upgrade --use-deprecated=legacy-resolver

build: clean deps
@# Install OpenFisca-Extension-Template for deployment and publishing.
Expand All @@ -29,13 +29,16 @@ check-syntax-errors:
format-style:
@# Do not analyse .gitignored files.
@# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764.
isort `git ls-files | grep "\.py$$"`
autopep8 `git ls-files | grep "\.py$$"`
pyupgrade --py39-plus `git ls-files | grep "\.py$$"`

check-style:
@# Do not analyse .gitignored files.
@# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764.
flake8 `git ls-files | grep "\.py$$"`
pylint `git ls-files | grep "\.py$$"`
yamllint `git ls-files | grep "\.yaml$$"`

test: clean check-syntax-errors check-style
openfisca test --country-package openfisca_country_template openfisca_country_template/tests
Expand Down
44 changes: 15 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,18 @@ This repository helps you quickly bootstrap and use your own OpenFisca country p

## Bootstrapping your Country Package

This set of instructions will create your own copy of this boilerplate directory and customise it to the country you want to work on. You will need to have [Git](https://git-scm.com) installed.
This set of instructions **only needs to be followed once** and will create your own copy of this boilerplate directory, customising it to the country you want to work on. You will need to have [Git](https://git-scm.com) installed.

1. [Download a copy](https://github.com/openfisca/country-template/archive/master.zip) of this repository, unzip it and `cd` into it in a Terminal window.

2. Create a new repository on your favourite git host (Github, Bitbucket, GitLab, etc) with the name openfisca-your_country_name. For example, `openfisca-france`.
2. Create a new repository on your favourite git host (Github, Bitbucket, GitLab, etc) with the name openfisca-your_country_name. For example, `openfisca-new_zealand` or `openfisca-france`.

3. Set up the two following variables and execute the `bootstrap.sh` script to initialise the git repository and replace all references to `openfisca_country_template` with references to your new country package in the code base:
3. Execute the `bootstrap.sh` script to initialise the git repository. This performs numerous tasks including replacing all references to `openfisca-country_template` with references to the new country package.
- To execute the script run `bash bootstrap.sh` from the command line
- After the `bootstrap.sh` has run both it and these instructions are removed.

```sh
export COUNTRY_NAME=France # set the name of your country here; you should keep all capitals, and replace any spaces in the name by underscores
export REPOSITORY_URL=https://github.com/YOUR_ORGANISATION/OpenFisca-$COUNTRY_NAME # set here the URL of the repository you created in step 2.
./bootstrap.sh
```

4. Push your changes to your git host:

```sh
git push origin master
```
4. Follow the instructions in the new repository's README.md.

That's it, you're all set!

## Writing the Legislation

Expand Down Expand Up @@ -67,8 +58,8 @@ In order to limit dependencies conflicts, we recommend using a [virtual environm
To create a virtual environment, launch a terminal on your computer, `cd` into your directory and follow these instructions:

```sh
python3 -m venv openfisca # create a new venv called “openfisca”
source openfisca/bin/activate # activate the venv
python3 -m venv .venv # create a new virtual environment in the “.venv” folder, which will contain all dependencies
source .venv/bin/activate # activate the venv
```

You can now operate in the venv you just created.
Expand Down Expand Up @@ -104,7 +95,7 @@ pip --version # should print at least 9.0.
Install the Country Package:

```sh
pip install openfisca_country_template
pip install openfisca-country_template
```

:warning: Please beware that installing the Country Package with `pip` is dependent on its maintainers publishing said package.
Expand All @@ -114,7 +105,7 @@ pip install openfisca_country_template
#### Next Steps

- To learn how to use OpenFisca, follow our [tutorials](https://openfisca.org/doc/).
- To serve this Country Package, serve the [OpenFisca web API](#serve-your-country-package-with-the-openFisca-web-api).
- To serve this Country Package, serve the [OpenFisca Web API](#serve-your-country-package-with-the-openFisca-web-api).

Depending on what you want to do with OpenFisca, you may want to install yet other packages in your venv:
- To install extensions or write on top of this Country Package, head to the [Extensions documentation](https://openfisca.org/doc/contribute/extensions.html).
Expand All @@ -139,16 +130,13 @@ Inside your venv, check the prerequisites:
python --version # should print "Python 3.9.xx".
```

```sh
pip --version # should print at least 9.0.
# if not, run "pip install --upgrade pip"
```
Clone this Country Package on your machine:

```sh
git clone https://github.com/openfisca/openfisca-country-template.git
cd openfisca-country-template
pip install --editable .[dev]
git clone https://example.com/repository.git
cd repository_folder
pip install --upgrade pip build twine
pip install --editable .[dev] --upgrade
```

You can make sure that everything is working by running the provided tests with `make test`.
Expand All @@ -169,7 +157,7 @@ If you are considering building a web application, you can use the packaged Open
To serve the Openfisca Web API locally, run:

```sh
openfisca serve --port 5000
openfisca serve --port 5000 --country-package openfisca_country_template
```

Or use the quick-start Make command:
Expand All @@ -192,8 +180,6 @@ This endpoint returns the [Open API specification](https://www.openapis.org/) of

You can test your new Web API by sending it example JSON data located in the `situation_examples` folder.

Substitute your package's country name for `openfisca_country_template` below:

```sh
curl -X POST -H "Content-Type: application/json" \
-d @./openfisca_country_template/situation_examples/couple.json \
Expand Down
Loading
Loading