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

Auto-fix the code formatting #1060

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ jobs:
nosetests `circleci tests glob "tests/**/*.py" | circleci tests split`
openfisca-run-test `circleci tests glob "tests/**/*.{yaml,yml}" | circleci tests split`

- run:
name: Run linting
command: |
make check-no-prints
make check-syntax-errors

- run:
name: Check version number has been properly updated
command: |
Expand Down Expand Up @@ -120,6 +126,13 @@ jobs:
nosetests `circleci tests glob "tests/**/*.py" | circleci tests split`
openfisca-run-test `circleci tests glob "tests/**/*.{yaml,yml}" | circleci tests split`

- run:
name: Run linting
command: |
make check-no-prints
make check-syntax-errors
make formatting

- run:
name: Check version number has been properly updated
command: |
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

### 22.3.1 [#998](https://github.com/openfisca/openfisca-france/pull/1053)

* Amélioration technique.
* Détails :
- Compatibilité python2 et python3

### 22.3.0 [#998](https://github.com/openfisca/openfisca-france/pull/998)

* Évolution du système socio-fiscal.
Expand Down
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ clean:
rm -rf build dist
find . -name '*.pyc' -exec rm \{\} \;

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

test: check-syntax-errors check-no-prints
@# Launch tests from openfisca_france/tests directory (and not .) because TaxBenefitSystem must be initialized
Expand Down
31 changes: 22 additions & 9 deletions openfisca_france/assets/apl/extract_subcommunes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,36 @@


def main():
parser = argparse.ArgumentParser(description = __doc__)
parser.add_argument('insee_communes_file', help = u"INSEE communes file")
parser.add_argument('-v', '--verbose', action = 'store_true', default = False, help = u"increase output verbosity")
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("insee_communes_file", help=u"INSEE communes file")
parser.add_argument(
"-v",
"--verbose",
action="store_true",
default=False,
help=u"increase output verbosity",
)
args = parser.parse_args()
logging.basicConfig(level = logging.DEBUG if args.verbose else logging.WARNING)
logging.basicConfig(level=logging.DEBUG if args.verbose else logging.WARNING)

commune_depcom_by_subcommune_depcom = {}
with open(args.insee_communes_file) as insee_communes_file:
csv_reader = csv.DictReader(insee_communes_file, delimiter = '\t')
csv_reader = csv.DictReader(insee_communes_file, delimiter="\t")
for row in csv_reader:
# Do not decode row as we read only ASCII.
if row['ACTUAL'] in ('2', '5'):
subcommune_depcom = row['DEP'] + row['COM']
commune_depcom = row['POLE']
if row["ACTUAL"] in ("2", "5"):
subcommune_depcom = row["DEP"] + row["COM"]
commune_depcom = row["POLE"]
commune_depcom_by_subcommune_depcom[subcommune_depcom] = commune_depcom

print json.dumps(commune_depcom_by_subcommune_depcom, encoding = 'utf-8', ensure_ascii = False, indent = 2)
print(
json.dumps(
commune_depcom_by_subcommune_depcom,
encoding="utf-8",
ensure_ascii=False,
indent=2,
)
)
return 0


Expand Down
658 changes: 329 additions & 329 deletions openfisca_france/assets/holidays.py

Large diffs are not rendered by default.

44 changes: 23 additions & 21 deletions openfisca_france/conf/cache_blacklist.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# When using openfisca for a large population, having too many variables in cache make openfisca performances drop.
# The following variables are intermediate results and do not need to be cached in those usecases.

cache_blacklist = set([
'aide_logement_loyer_retenu',
'aide_logement_charges',
'aide_logement_R0',
'aide_logement_taux_famille',
'aide_logement_taux_loyer',
'aide_logement_participation_personnelle',
'aide_logement_loyer_seuil_degressivite',
'aide_logement_loyer_seuil_suppression',
'aide_logement_montant_brut_avant_degressivite',
'aides_logement_primo_accedant',
'aides_logement_primo_accedant_k',
'aides_logement_primo_accedant_nb_part',
'aides_logement_primo_accedant_loyer_minimal',
'aides_logement_primo_accedant_plafond_mensualite',
'aides_logement_primo_accedant_ressources',
'cheque_energie',
'montant_cheque_energie',
'ppa_forfait_logement',
'unites_consommation_cheque_energie',
])
cache_blacklist = set(
[
"aide_logement_loyer_retenu",
"aide_logement_charges",
"aide_logement_R0",
"aide_logement_taux_famille",
"aide_logement_taux_loyer",
"aide_logement_participation_personnelle",
"aide_logement_loyer_seuil_degressivite",
"aide_logement_loyer_seuil_suppression",
"aide_logement_montant_brut_avant_degressivite",
"aides_logement_primo_accedant",
"aides_logement_primo_accedant_k",
"aides_logement_primo_accedant_nb_part",
"aides_logement_primo_accedant_loyer_minimal",
"aides_logement_primo_accedant_plafond_mensualite",
"aides_logement_primo_accedant_ressources",
"cheque_energie",
"montant_cheque_energie",
"ppa_forfait_logement",
"unites_consommation_cheque_energie",
]
)
109 changes: 43 additions & 66 deletions openfisca_france/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,89 +3,66 @@
from openfisca_core.entities import build_entity

Famille = build_entity(
key = "famille",
plural = "familles",
label = u'Famille',
roles = [
key="famille",
plural="familles",
label=u"Famille",
roles=[
{
'key': 'parent',
'plural': 'parents',
'label': u'Parents',
'subroles': ['demandeur', 'conjoint']
},
{
'key': 'enfant',
'plural': 'enfants',
'label': u'Enfants'
}
]
)
"key": "parent",
"plural": "parents",
"label": u"Parents",
"subroles": ["demandeur", "conjoint"],
},
{"key": "enfant", "plural": "enfants", "label": u"Enfants"},
],
)

Individu = build_entity(
key = "individu",
plural = "individus",
label = u'Individu',
is_person = True
)
key="individu", plural="individus", label=u"Individu", is_person=True
)

FoyerFiscal = build_entity(
key = "foyer_fiscal",
plural = "foyers_fiscaux",
label = u'Déclaration d’impôts',
doc = u'''
key="foyer_fiscal",
plural="foyers_fiscaux",
label=u"Déclaration d’impôts",
doc=u"""
Le foyer fiscal désigne l'ensemble des personnes inscrites sur une même déclaration de revenus.
Il peut y avoir plusieurs foyers fiscaux dans un seul ménage : par exemple, un couple non marié où chacun remplit
sa propre déclaration de revenus compte pour deux foyers fiscaux.
Voir https://www.insee.fr/fr/metadonnees/definition/c1735.
''',
roles = [
""",
roles=[
{
'key': 'declarant',
'plural': 'declarants',
'label': u'Déclarants',
'subroles': ['declarant_principal', 'conjoint'],
},
"key": "declarant",
"plural": "declarants",
"label": u"Déclarants",
"subroles": ["declarant_principal", "conjoint"],
},
{
'key': 'personne_a_charge',
'plural': 'personnes_a_charge',
'label': u'Personnes à charge'
},
]
)
"key": "personne_a_charge",
"plural": "personnes_a_charge",
"label": u"Personnes à charge",
},
],
)

Menage = build_entity(
key = "menage",
plural = "menages",
label = u'Logement principal',
doc = u'''
key="menage",
plural="menages",
label=u"Logement principal",
doc=u"""
Un ménage, au sens statistique du terme, désigne l'ensemble des occupants d'un même logement sans que ces personnes
soient nécessairement unies par des liens de parenté (en cas de cohabitation, par exemple).
Un ménage peut être composé d'une seule personne.
Le niveau de vie ainsi que la pauvreté sont calculés au niveau d'un ménage.
Voir https://www.insee.fr/fr/metadonnees/definition/c1879.
''',
roles = [
{
'key': 'personne_de_reference',
'label': u'Personne de référence',
'max': 1
},
{
'key': 'conjoint',
'label': u'Conjoint',
'max': 1
},
{
'key': 'enfant',
'plural': 'enfants',
'label': u'Enfants',
},
{
'key': 'autre',
'plural': 'autres',
'label': u'Autres'
}
]
)
""",
roles=[
{"key": "personne_de_reference", "label": u"Personne de référence", "max": 1},
{"key": "conjoint", "label": u"Conjoint", "max": 1},
{"key": "enfant", "plural": "enfants", "label": u"Enfants"},
{"key": "autre", "plural": "autres", "label": u"Autres"},
],
)

entities = [Individu, Famille, FoyerFiscal, Menage]
65 changes: 53 additions & 12 deletions openfisca_france/france_taxbenefitsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from .entities import entities
from . import decompositions, scenarios

from .model.prelevements_obligatoires.prelevements_sociaux.cotisations_sociales import preprocessing
from .model.prelevements_obligatoires.prelevements_sociaux.cotisations_sociales import (
preprocessing
)
from .conf.cache_blacklist import cache_blacklist as conf_cache_blacklist


Expand All @@ -17,34 +19,73 @@

class FranceTaxBenefitSystem(TaxBenefitSystem):
"""French tax benefit system"""

CURRENCY = u"€"
DATA_SOURCES_DIR = os.path.join(COUNTRY_DIR, 'data', 'sources')
DATA_SOURCES_DIR = os.path.join(COUNTRY_DIR, "data", "sources")
decomposition_file_path = os.path.join(
os.path.dirname(os.path.abspath(decompositions.__file__)), 'decomp.xml')
os.path.dirname(os.path.abspath(decompositions.__file__)), "decomp.xml"
)
preprocess_parameters = staticmethod(preprocessing.preprocess_parameters)

REFORMS_DIR = os.path.join(COUNTRY_DIR, 'reformes')
REFORMS_DIR = os.path.join(COUNTRY_DIR, "reformes")
REV_TYP = None # utils.REV_TYP # Not defined for France
REVENUES_CATEGORIES = {
'brut': ['salaire_brut', 'chomage_brut', 'retraite_brute', 'pensions_alimentaires_percues', 'pensions_alimentaires_versees', 'rev_cap_brut', 'fon'],
'imposable': ['salaire_imposable', 'chomage_imposable', 'retraite_imposable', 'pensions_alimentaires_percues', 'pensions_alimentaires_versees', 'rev_cap_brut', 'fon', 'cotsoc_cap'],
'net': ['salaire_net', 'chomage_net', 'retraite_nette', 'pensions_alimentaires_percues', 'pensions_alimentaires_versees', 'rev_cap_net', 'fon'],
'superbrut': ['salaire_super_brut', 'chomage_brut', 'retraite_brute', 'pensions_alimentaires_percues', 'pensions_alimentaires_versees', 'rev_cap_brut', 'fon'],
}
"brut": [
"salaire_brut",
"chomage_brut",
"retraite_brute",
"pensions_alimentaires_percues",
"pensions_alimentaires_versees",
"rev_cap_brut",
"fon",
],
"imposable": [
"salaire_imposable",
"chomage_imposable",
"retraite_imposable",
"pensions_alimentaires_percues",
"pensions_alimentaires_versees",
"rev_cap_brut",
"fon",
"cotsoc_cap",
],
"net": [
"salaire_net",
"chomage_net",
"retraite_nette",
"pensions_alimentaires_percues",
"pensions_alimentaires_versees",
"rev_cap_net",
"fon",
],
"superbrut": [
"salaire_super_brut",
"chomage_brut",
"retraite_brute",
"pensions_alimentaires_percues",
"pensions_alimentaires_versees",
"rev_cap_brut",
"fon",
],
}

def __init__(self):
TaxBenefitSystem.__init__(self, entities)
self.Scenario = scenarios.Scenario

param_dir = os.path.join(COUNTRY_DIR, 'parameters')
param_dir = os.path.join(COUNTRY_DIR, "parameters")
self.load_parameters(param_dir)

self.add_variables_from_directory(os.path.join(COUNTRY_DIR, 'model'))
self.add_variables_from_directory(os.path.join(COUNTRY_DIR, "model"))
self.cache_blacklist = conf_cache_blacklist

def prefill_cache(self):
# Compute one "zone APL" variable, to pre-load CSV of "code INSEE commune" to "Zone APL".
from .model.prestations import aides_logement

aides_logement.preload_zone_apl()
from .model.prelevements_obligatoires.prelevements_sociaux.contributions_sociales import versement_transport
from .model.prelevements_obligatoires.prelevements_sociaux.contributions_sociales import (
versement_transport
)

versement_transport.preload_taux_versement_transport()
Loading