-
Notifications
You must be signed in to change notification settings - Fork 101
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
Adapte à Python 3 #980
Adapte à Python 3 #980
Conversation
circle.yml
Outdated
@@ -9,7 +9,7 @@ dependencies: | |||
override: | |||
- pip install --upgrade pip twine wheel # pip >= 8.0 needed to be compatible with "manylinux" wheels, used by numpy >= 1.11 | |||
# Uncomment and adapt the next line to use a particular feature branch of OpenFisca-Core to run Circle CI tests | |||
# - pip install --editable git+https://github.com/openfisca/openfisca-core.git@BRANCH_NAME#egg=OpenFisca-Core | |||
- pip install --editable git+https://github.com/openfisca/openfisca-core.git@python3#egg=OpenFisca-Core |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be reverted before merging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Est-ce que tous les tests passent en python3 avec ces modifications ? Certains des tests ?
Je pense qu'il serait interessant d'ajouter les tests en Python3 au circle pour eviter les regressions.
CHANGELOG.md
Outdated
@@ -1,5 +1,11 @@ | |||
# Changelog | |||
|
|||
## 21.1.0 [#980](https://github.com/openfisca/openfisca-france/pull/980) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Si c'est une amélioration technique, pourquoi ne pas avoir 21.9.10 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avant, je ne pouvais pas utiliser OpenFisca France en Python 3.
Maintenant, je peux.
C'est une nouvelle feature :).
Il n'y a pas a priori de lien direct entre la nature du changement et le type de version bump. Certaines évolutions de la législation sont juste des bug fix (telle formule donnait un mauvais résultat), certains changement techniques, comme celui-ci, apportent de nouvelles features.
@@ -288,6 +288,7 @@ def formula(individu, period, parameters): | |||
agirc_salarie = individu('agirc_salarie', period) | |||
assiette_cotisations_sociales = individu('assiette_cotisations_sociales', period) | |||
categorie_salarie = individu('categorie_salarie', period) | |||
plafond_securite_sociale = individu('plafond_securite_sociale', period) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌 Great catch ! 🙌
Comment est-ce que les tests arrivaient à passer avant ?
Comment as-tu identifié l'erreur ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avant, plafond_securite_sociale
n'étant pas défini dans la formule, c'est la classe plafond_securite_sociale
, définie dans le même fichier, qui était utilisée.
Or Python 2 ne lançait pas d'erreur quand on lui demandait de comparer une class
à un float
. Il devait sans doute renvoyer un résultat non pertinent, mais faute de test unitaire, ça n'a pas dû être détecté.
Python 3 n'accepte pas cette comparaison (et tant mieux!), donc je suis tombé sur une erreur bizarre en essayant de faire passer les tests.
openfisca_france/__init__.py
Outdated
@@ -1,5 +1,5 @@ | |||
# -*- coding: utf-8 -*- | |||
|
|||
from france_taxbenefitsystem import FranceTaxBenefitSystem | |||
from .france_taxbenefitsystem import FranceTaxBenefitSystem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On avait statué sur les absolute import
dans core il me semble. Pourquoi ne pas faire la même chose ici ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L'enthousiasme de faire passer les tests en utilisant le moins de touches de clavier possible ?
Good catch 👍
Tous les tests nose, pas encore vérifié pour les tests YAML. |
Je dirait qu'il faudrait passer à circle2 en copiant grossièrement ce qui a été fait avec openfisca-core. Tu te sens de te lancer ? |
openfisca_france/scenarios.py
Outdated
|
||
from model.base import * | ||
from .model.base import * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolute imports :)
@@ -4,7 +4,7 @@ | |||
|
|||
import datetime | |||
|
|||
from cache import tax_benefit_system | |||
from .cache import tax_benefit_system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolute imports :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test
package is not under openfisca_france
, so I don't see how I can use an absolute import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests.cache
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would actually look a lot like a now forbidden implicit relative import!
The idea behind forbidding implicit relatives imports was that:
- Either you use an explicit relative import. And the reader can see right way that you are using a local file.
- Either you use an unambiguous absolute import. And the reader now that you use a package installed by pip.
tests
is a super ambiguous absolute import! It actually only works for obscure non-deterministic reasons, and could totally fail if any package you installed contained a tests
module...
@@ -6,7 +6,8 @@ | |||
import os | |||
|
|||
from openfisca_core import decompositions | |||
from cache import tax_benefit_system | |||
from openfisca_core.commons import to_unicode | |||
from .cache import tax_benefit_system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolute imports :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test
package is not under openfisca_france
, so I don't see how I can use an absolute import.
@@ -6,7 +6,7 @@ | |||
|
|||
from openfisca_core import conv, decompositions, decompositionsxml | |||
|
|||
from cache import tax_benefit_system | |||
from .cache import tax_benefit_system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolute imports :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
@@ -3,7 +3,7 @@ | |||
import datetime | |||
import json | |||
|
|||
from cache import tax_benefit_system | |||
from .cache import tax_benefit_system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolute imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
@@ -5,7 +5,7 @@ | |||
|
|||
from nose.tools import assert_equal | |||
|
|||
from cache import tax_benefit_system | |||
from .cache import tax_benefit_system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolute imports
@@ -5,7 +5,7 @@ | |||
|
|||
from nose.tools import assert_equal | |||
|
|||
from cache import tax_benefit_system | |||
from .cache import tax_benefit_system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolute imports
@@ -1,7 +1,7 @@ | |||
# -*- coding: utf-8 -*- | |||
|
|||
from openfisca_core.rates import average_rate, marginal_rate | |||
from cache import tax_benefit_system | |||
from .cache import tax_benefit_system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolute imports :)
@@ -6,7 +6,7 @@ | |||
from openfisca_core.tools import assert_near | |||
from nose.tools import nottest | |||
|
|||
from cache import tax_benefit_system | |||
from .cache import tax_benefit_system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolute imports :)
af71fa8
to
67c9f34
Compare
Tests are passing 🎉 |
817e5bf
to
03a3ff1
Compare
|
||
- run: | ||
name: Run tests | ||
command: | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part differ from the common CircleCI configuration, as we use parallelism.
|
||
- run: | ||
name: Run tests | ||
command: | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part differ from the common CircleCI configuration, as we use parallelism.
CircleCI conf adapted to fit the new consensus from OpenFisca-Country-Template. PR ready for review :) |
# CircleCI 2.0 configuration file. See <https://circleci.com/docs/2.0/language-python/>. | ||
version: 2 | ||
jobs: | ||
build_python2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make it clearer to developpers if that section was called "test_python_2" ?
It seams to me that it would be more descriptive of what the script is doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think build
is a quite standard term for what we are doing here (installing the dependencies and running the tests).
.circleci/config.yml
Outdated
version: 2 | ||
jobs: | ||
build_python2: | ||
parallelism: 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 3
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless things have changed, we can use only 4 containers with the CircleCI free plan.
3 allows to speed up the tests in France, while still allowing fast non-parallel builds from core or country template to pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a comment :)
name: Create a virtualenv | ||
command: | | ||
mkdir -p /tmp/venv/openfisca_france | ||
virtualenv /tmp/venv/openfisca_france |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why create a virtualenv ? In my mental model, OpenFisca-France will be the only thing running in this Docker Instance. I'm curious of why we are going through the virtualenv steps ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short answer: whenever you are using python, virtualenvs tend to save you trouble.
In that particular case, Matti tried an implem without virtualenv. This implied chown-ing some repositories, which is much less standard than using a virtualenv.
- build_python3 | ||
filters: | ||
branches: | ||
only: master |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
command: | | ||
mkdir -p /tmp/venv/openfisca_france | ||
python -m venv /tmp/venv/openfisca_france | ||
echo "source /tmp/venv/openfisca_france/bin/activate" >> $BASH_ENV |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I understant is that we are creating a $BASH_ENV
environment variable.
I don't see where it is used...
I might be mistaken ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually writing this command in a file which path is provided by the $BASH_ENV
environment variable.
Assignment in bash would be BASH_ENV="some stuff"
|
||
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'` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a comment explaining what this if is doing might be useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
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 git diff-index --quiet origin/master CHANGELOG.md | ||
if ! $(dirname "$BASH_SOURCE")/detect-functional-changes.sh | grep --quiet CHANGELOG.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is strange to me that ! detect-functional-changes.sh
means that changed were actually detected, as I read !
as "not"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the grep --quiet CHANGELOG.md
applied in the git diff-index --name-only
in detect-functional-changes.sh
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command on the left of |
returns the list of files that have changed.
The grep checks if the Changelog is among them.
The !
is here to because we want to raise an error if the changelog has not been updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then shouldn't it be named detect-no-functional-changes.sh
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -4,7 +4,7 @@ | |||
|
|||
import datetime | |||
|
|||
from cache import tax_benefit_system | |||
from .cache import tax_benefit_system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests.cache
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like a bit more info on the circleci2 config before giving a go :)
Relates to openfisca/openfisca-core#630