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

Adapte à Python 3 #980

Merged
merged 17 commits into from
May 23, 2018
Merged

Adapte à Python 3 #980

merged 17 commits into from
May 23, 2018

Conversation

fpagnoux
Copy link
Member

@fpagnoux fpagnoux commented May 12, 2018

@fpagnoux fpagnoux requested review from Anna-Livia and sandcha May 12, 2018 23:48
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
Copy link
Member Author

@fpagnoux fpagnoux May 12, 2018

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

Copy link
Contributor

@Anna-Livia Anna-Livia left a 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)
Copy link
Contributor

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 ?

Copy link
Member Author

@fpagnoux fpagnoux May 14, 2018

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)
Copy link
Contributor

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 ?

Copy link
Member Author

@fpagnoux fpagnoux May 14, 2018

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.

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

from france_taxbenefitsystem import FranceTaxBenefitSystem
from .france_taxbenefitsystem import FranceTaxBenefitSystem
Copy link
Contributor

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 ?

Copy link
Member Author

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 👍

@fpagnoux
Copy link
Member Author

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 éviter les regressions.

Tous les tests nose, pas encore vérifié pour les tests YAML.
Oui, il faudrait ajouter à Circle. Est-ce que quelqu'un sait comment faire et veut s'y coller 🙂 ?

@Anna-Livia
Copy link
Contributor

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 ?


from model.base import *
from .model.base import *
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Absolute imports :)

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

tests.cache ?

Copy link
Member Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Absolute imports :)

Copy link
Member Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Absolute imports :)

Copy link
Member Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Absolute imports

Copy link
Member Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Absolute imports :)

@fpagnoux fpagnoux force-pushed the python3 branch 4 times, most recently from af71fa8 to 67c9f34 Compare May 15, 2018 17:26
@fpagnoux fpagnoux requested a review from Anna-Livia May 15, 2018 17:36
@fpagnoux
Copy link
Member Author

Tests are passing 🎉

@fpagnoux fpagnoux force-pushed the python3 branch 4 times, most recently from 817e5bf to 03a3ff1 Compare May 22, 2018 03:32

- run:
name: Run tests
command: |
Copy link
Member Author

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: |
Copy link
Member Author

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.

@fpagnoux
Copy link
Member Author

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:
Copy link
Contributor

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.

Copy link
Member Author

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).

version: 2
jobs:
build_python2:
parallelism: 3
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 3 ?

Copy link
Member Author

@fpagnoux fpagnoux May 22, 2018

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.

Copy link
Member Author

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
Copy link
Contributor

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 ...

Copy link
Member Author

@fpagnoux fpagnoux May 22, 2018

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
Copy link
Contributor

Choose a reason for hiding this comment

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

When I look at the workflow on circle ci, it seems that only

 - build_python2
 - build_python3

are running and not

- deploy_python2
 - deploy_python3

capture d ecran 2018-05-22 a 17 17 44

I don't thing it is due to the branch filtering because we had that in previous versions and the deployement phases did appear.

Copy link
Member Author

Choose a reason for hiding this comment

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

Pretty sure it's due to branch filtering. See here and here for Core examples.

command: |
mkdir -p /tmp/venv/openfisca_france
python -m venv /tmp/venv/openfisca_france
echo "source /tmp/venv/openfisca_france/bin/activate" >> $BASH_ENV
Copy link
Contributor

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 ...

Copy link
Member Author

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'`
Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Contributor

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"

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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 ?

Copy link
Member Author

@fpagnoux fpagnoux May 23, 2018

Choose a reason for hiding this comment

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

So this line doesn't really care about the exit code of detect-functional-changes.sh. It's the grep exit code that is negated with !.

But I agree with you that that line and that line do not read well. Fixing that for all repos.

@@ -4,7 +4,7 @@

import datetime

from cache import tax_benefit_system
from .cache import tax_benefit_system
Copy link
Contributor

Choose a reason for hiding this comment

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

tests.cache ?

Copy link
Contributor

@Anna-Livia Anna-Livia left a 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 :)

@fpagnoux fpagnoux requested a review from Anna-Livia May 22, 2018 16:39
@fpagnoux fpagnoux merged commit ee86059 into master May 23, 2018
@fpagnoux fpagnoux deleted the python3 branch May 23, 2018 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants