Commit 526f40a4 authored by Christophe Benz's avatar Christophe Benz

First commit

parents
calculateur_impots.egg-info
# Calculateur Impôts en Python
## Utilisation
Exemple :
```
$ python3 calculateur_impots/scripts/calculate.py PPE_SALAVDEFV
```
# -*- coding: utf-8 -*-
from . import __definitions__, __formulas__
VARIABLE_SAISIE_DEFAULT_VALUE = 0
def find_definition(variable_name):
assert variable_name in __definitions__.variable_definition_by_name, \
'Definition not found for variable "{}"'.format(variable_name)
return __definitions__.variable_definition_by_name[variable_name]
def find_formula(variable_name):
assert variable_name in __formulas__.__dict__, 'Formula not found for variable "{}"'.format(variable_name)
return __formulas__.__dict__[variable_name]
class Simulation(object):
def __init__(self, value_by_variable_name=None):
self.value_by_variable_name = {} if value_by_variable_name is None else value_by_variable_name
def calculate(self, variable_name):
variable_definition = find_definition(variable_name)
if variable_definition['type'] == 'variable_calculee':
if variable_name not in self.value_by_variable_name:
formula = find_formula(variable_name)
self.value_by_variable_name[variable_name] = formula(self)
value = self.value_by_variable_name[variable_name]
elif variable_definition['type'] == 'variable_saisie':
value = self.value_by_variable_name.get(variable_name, VARIABLE_SAISIE_DEFAULT_VALUE)
else:
raise NotImplementedError(variable_definition)
return value
# __call__ = calculate
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import logging
import os
import sys
from calculateur_impots import core
# Globals
args = None
script_name = os.path.splitext(os.path.basename(__file__))[0]
log = logging.getLogger(script_name)
script_dir_name = os.path.dirname(os.path.abspath(__file__))
def iter_name_and_value(variables):
for variable in variables:
if '=' in variable:
variable_name, value = variable.split('=')
try:
value = float(value)
except ValueError:
raise ValueError('Invalid value "{}" provided for variable "{}"'.format(value, variable_name))
else:
variable_name = variable
value = None
yield variable_name, value
def iter_variables_calculees(variables):
for variable_name, value in iter_name_and_value(variables):
if value is None:
variable_definition = core.find_definition(variable_name)
assert variable_definition['type'] == 'variable_calculee', \
'Calculation requested for variable "{}" but type != "variable_calculee"'.format(variable_name)
yield variable_name
def iter_variables_saisies(variables):
for variable_name, value in iter_name_and_value(variables):
if value is not None:
variable_definition = core.find_definition(variable_name)
assert variable_definition['type'] == 'variable_saisie', \
'Value provided for variable "{}" but type != "variable_saisie"'.format(variable_name)
yield variable_name, value
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Increase output verbosity')
parser.add_argument('-d', '--debug', action='store_true', default=False, help='Display debug messages')
parser.add_argument('variables', metavar='variable or variable=value', nargs='+',
help='Variables (to calculate or input)')
global args
args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG if args.verbose or args.debug else logging.WARNING, stream=sys.stdout)
variables_saisies = {variable_name: value for variable_name, value in iter_variables_saisies(args.variables)}
simulation = core.Simulation(value_by_variable_name=variables_saisies)
variables_calculees = [variable_name for variable_name in iter_variables_calculees(args.variables)]
result = {
variable_name: simulation.calculate(variable_name)
for variable_name in variables_calculees
}
print(result)
return 0
if __name__ == '__main__':
sys.exit(main())
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
setup(
name='calculateur_impots',
version='0.0.0.dev0',
author='Christophe Benz',
author_email='christophe.benz@data.gouv.fr',
classifiers=[
'Development Status :: 2 - Pre-Alpha',
# 'License :: OSI Approved :: GNU Affero General Public License v3',
'Operating System :: POSIX',
'Programming Language :: Python',
'Topic :: Scientific/Engineering :: Information Analysis',
],
description='Calculateur des impôts compilé en Python',
keywords='calculateur impôts tax',
# license='http://www.fsf.org/licensing/licenses/agpl-3.0.html',
# url='',
# install_requires=[],
packages=find_packages(),
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment