2021-06-25 11:50:49 +03:00
|
|
|
# Python French Law Library
|
|
|
|
|
|
|
|
This folder contains a ready-to-use Python library featuring French public
|
|
|
|
algorithms coded up in Catala.
|
|
|
|
|
2023-03-02 13:47:51 +03:00
|
|
|
The Python version expected to run the Python code is above 3.6. For the
|
|
|
|
commands noted below to run, you are expected to setup a virtual Python
|
|
|
|
environment: run `make dependencies-python` from the root of the Catala
|
|
|
|
repository.
|
|
|
|
|
|
|
|
Then activate the environment (needs to be done every time you open a new shell
|
|
|
|
session). From the root of the Catala repository, run the following command:
|
|
|
|
|
|
|
|
```
|
|
|
|
. _python_venv/bin/activate
|
|
|
|
```
|
2021-06-25 11:50:49 +03:00
|
|
|
|
|
|
|
## Organization
|
|
|
|
|
|
|
|
### Law source
|
|
|
|
|
|
|
|
The `src/` folder contains the Python files generated by the Catala compiler.
|
|
|
|
To update them from the Catala sources, invoke this command from the root
|
|
|
|
of the repository:
|
|
|
|
|
|
|
|
```
|
|
|
|
make generate_french_law_library_python
|
|
|
|
```
|
|
|
|
|
2022-08-09 15:39:43 +03:00
|
|
|
The Python files generated by the Catala compiler depends on the `catala.runtime`
|
|
|
|
package, whose source doe can be found in `runtimes/python/catala` from the
|
|
|
|
root of the Catala repository.
|
2021-06-25 11:50:49 +03:00
|
|
|
|
|
|
|
All theses Python files feature type annotations which can be checked against
|
2021-06-26 19:04:36 +03:00
|
|
|
using the following command inside this directory (`french_law/python`):
|
2021-06-25 11:50:49 +03:00
|
|
|
|
|
|
|
```
|
2021-06-26 18:09:47 +03:00
|
|
|
make type
|
2021-06-25 11:50:49 +03:00
|
|
|
```
|
|
|
|
|
2021-06-26 18:09:47 +03:00
|
|
|
### API
|
2021-06-25 11:50:49 +03:00
|
|
|
|
2021-06-26 19:04:36 +03:00
|
|
|
To use the algorithms of this library, you can take a look at the example provided in
|
|
|
|
`main.py`. All the algorithms are centralized with wrappers in `api.py`, as it is
|
|
|
|
very important internally to wrap all of the input parameters using `src/catala.py`
|
|
|
|
conversion functions.
|
2021-06-25 11:50:49 +03:00
|
|
|
|
2021-06-26 18:09:47 +03:00
|
|
|
You can benchmark the computation using the following command inside this
|
2021-06-26 19:04:36 +03:00
|
|
|
directory (`french_law/python`):
|
2021-06-25 11:50:49 +03:00
|
|
|
|
|
|
|
```
|
2021-06-26 18:09:47 +03:00
|
|
|
make bench
|
2021-06-25 11:50:49 +03:00
|
|
|
```
|
2021-06-26 19:04:36 +03:00
|
|
|
|
|
|
|
### Logging
|
|
|
|
|
|
|
|
The generated Catala code also features a logging feature that let you inspect
|
|
|
|
each step of the computation, as well as the values flowing through it. You can
|
|
|
|
directly retrieve a list of log events just after using a Catala-generated
|
|
|
|
function, and display this list as you wish. An example of such a display can
|
|
|
|
be showcases by using the following command inside this directory (`french_law/python`):
|
|
|
|
|
|
|
|
```
|
|
|
|
make show_log
|
|
|
|
```
|