Merge branch 'master' into aides_logement_outre_mer

This commit is contained in:
Denis Merigoux 2023-03-17 09:18:27 +01:00
commit 4fcdd005e0
No known key found for this signature in database
GPG Key ID: EE99DCFA365C3EE3
11 changed files with 7702 additions and 126824 deletions

View File

@ -72,11 +72,10 @@ Next, install all the packages that Catala depends on with
make dependencies
This should ensure everything is set up for developing on the Catala compiler!
The Python dependencies are installed inside a local virtual environment
(`venv`). The Makefile rules will use it automatically when building the syntax
cheat-sheet, for example, but if you need to otherwise colorise Catala code, or
use generated Python code, you should run the following command once in every
new shell session:
(`venv`). To use it, for example to run Python code generated by Catala, you
should run the following command once in every new shell session:
. _python_venv/bin/activate

View File

@ -52,9 +52,6 @@ $(PY_VENV_DIR)/stamp: \
-e syntax_highlighting/pl/pygments
touch $@
# Run sub-make within the Python venv
MAKEP = $(PY_VENV_ACTIVATE) $(MAKE)
dependencies-python: $(PY_VENV_DIR)
#> dependencies : Install the Catala OCaml, JS and Git dependencies
@ -171,7 +168,7 @@ vscode: vscode_fr vscode_en
##########################################
syntax:
$(MAKEP) -C doc/syntax
$(MAKE) -C doc/syntax
##########################################
# Literate programming and examples
@ -187,32 +184,32 @@ TUTORIEL_FR_DIR=$(EXAMPLES_DIR)/tutoriel_fr
POLISH_TAXES_DIR=$(EXAMPLES_DIR)/polish_taxes
literate_aides_logement: build $(PY_VENV_DIR)
$(MAKEP) -C $(AIDES_LOGEMENT_DIR) aides_logement.tex
$(MAKEP) -C $(AIDES_LOGEMENT_DIR) aides_logement.html
$(MAKE) -C $(AIDES_LOGEMENT_DIR) aides_logement.tex
$(MAKE) -C $(AIDES_LOGEMENT_DIR) aides_logement.html
literate_allocations_familiales: build
$(MAKEP) -C $(ALLOCATIONS_FAMILIALES_DIR) allocations_familiales.tex
$(MAKEP) -C $(ALLOCATIONS_FAMILIALES_DIR) allocations_familiales.html
$(MAKE) -C $(ALLOCATIONS_FAMILIALES_DIR) allocations_familiales.tex
$(MAKE) -C $(ALLOCATIONS_FAMILIALES_DIR) allocations_familiales.html
literate_code_general_impots: build
$(MAKEP) -C $(CODE_GENERAL_IMPOTS_DIR) code_general_impots.tex
$(MAKEP) -C $(CODE_GENERAL_IMPOTS_DIR) code_general_impots.html
$(MAKE) -C $(CODE_GENERAL_IMPOTS_DIR) code_general_impots.tex
$(MAKE) -C $(CODE_GENERAL_IMPOTS_DIR) code_general_impots.html
literate_us_tax_code: build
$(MAKEP) -C $(US_TAX_CODE_DIR) us_tax_code.tex
$(MAKEP) -C $(US_TAX_CODE_DIR) us_tax_code.html
$(MAKE) -C $(US_TAX_CODE_DIR) us_tax_code.tex
$(MAKE) -C $(US_TAX_CODE_DIR) us_tax_code.html
literate_tutorial_en: build
$(MAKEP) -C $(TUTORIAL_EN_DIR) tutorial_en.tex
$(MAKEP) -C $(TUTORIAL_EN_DIR) tutorial_en.html
$(MAKE) -C $(TUTORIAL_EN_DIR) tutorial_en.tex
$(MAKE) -C $(TUTORIAL_EN_DIR) tutorial_en.html
literate_tutoriel_fr: build
$(MAKEP) -C $(TUTORIEL_FR_DIR) tutoriel_fr.tex
$(MAKEP) -C $(TUTORIEL_FR_DIR) tutoriel_fr.html
$(MAKE) -C $(TUTORIEL_FR_DIR) tutoriel_fr.tex
$(MAKE) -C $(TUTORIEL_FR_DIR) tutoriel_fr.html
literate_polish_taxes: build
$(MAKEP) -C $(POLISH_TAXES_DIR) polish_taxes.tex
$(MAKEP) -C $(POLISH_TAXES_DIR) polish_taxes.html
$(MAKE) -C $(POLISH_TAXES_DIR) polish_taxes.tex
$(MAKE) -C $(POLISH_TAXES_DIR) polish_taxes.html
#> literate_examples : Builds the .tex and .html versions of the examples code. Needs pygments to be installed and patched with Catala.
literate_examples: literate_allocations_familiales literate_code_general_impots \
@ -246,7 +243,7 @@ build_french_law_library_ocaml:
dune build $(FRENCH_LAW_OCAML_LIB_DIR)/api.a
run_french_law_library_benchmark_ocaml:
dune exec --profile release $(FRENCH_LAW_OCAML_LIB_DIR)/bench.exe
dune exec $(FRENCH_LAW_OCAML_LIB_DIR)/bench.exe
run_french_law_library_ocaml_tests:
dune exec $(FRENCH_LAW_OCAML_LIB_DIR)/law_source/unit_tests/run_tests.exe
@ -301,10 +298,10 @@ generate_french_law_library_python:
#> type_french_law_library_python : Types the French law library Python sources with mypy
type_french_law_library_python: $(PY_VENV_DIR) generate_french_law_library_python
$(MAKEP) -C $(FRENCH_LAW_PYTHON_LIB_DIR) type
$(PY_VENV_ACTIVATE) $(MAKE) -C $(FRENCH_LAW_PYTHON_LIB_DIR) type
run_french_law_library_benchmark_python: $(PY_ENV_DIR) type_french_law_library_python
$(MAKEP) -C $(FRENCH_LAW_PYTHON_LIB_DIR) bench
$(PY_VENV_ACTIVATE) $(MAKE) -C $(FRENCH_LAW_PYTHON_LIB_DIR) bench
##########################################
# High-level test and benchmarks commands
@ -356,10 +353,13 @@ WEBSITE_ASSETS = grammar.html catala.html clerk.html catala_legifrance.html
$(addprefix _build/default/,$(WEBSITE_ASSETS)):
dune build $@
#> website-assets : Builds all the assets necessary for the Catala website
website-assets: build_french_law_library_web_api doc literate_examples build
website-assets-base: build_french_law_library_web_api doc literate_examples build
dune build $(WEBSITE_ASSETS)
#> website-assets : Builds all the assets necessary for the Catala website
website-assets:
$(MAKE) DUNE_PROFILE=release website-assets-base
##########################################
# Misceallenous
##########################################
@ -376,7 +376,7 @@ all: \
bench_js \
generate_french_law_library_python type_french_law_library_python \
bench_python \
website-assets
website-assets-base
#> clean : Clean build artifacts
@ -417,4 +417,5 @@ help_catala_legifrance:
run_french_law_library_benchmark_python \
run_french_law_library_benchmark_js run_french_law_library_ocaml_tests \
build_french_law_library_js build_french_law_library_web_api \
build_french_law_library_ocaml
build_french_law_library_ocaml \
website-assets website-assets-base

View File

@ -378,6 +378,10 @@ let info =
"Prints a debugging verbatim of the statement calculus intermediate \
representation of the Catala program. Use the $(b,-s) option to \
restrict the output to a particular scope." );
`I
( "$(b,pygmentize)",
"This special command is a wrapper around the $(b,pygmentize) \
command that enables support for colorising Catala code." );
`S Manpage.s_authors;
`P "The authors are listed by alphabetical order.";
`P "Nicolas Chataing <nicolas.chataing@ens.fr>";

View File

@ -403,6 +403,10 @@ let driver source_file (options : Cli.options) : int =
-1
let main () =
if
Array.length Sys.argv >= 2
&& String.lowercase_ascii Sys.argv.(1) = "pygmentize"
then Literate.Pygmentize.exec ();
let return_code =
Cmdliner.Cmd.eval'
(Cmdliner.Cmd.v Cli.info (Cli.catala_t (fun f -> driver (FileName f))))

View File

@ -125,6 +125,16 @@ let check_exceeding_lines
"%s"
String.(sub s max_len (len_s - max_len)))))
let with_pygmentize_lexer lang f =
let lexer_py =
let lexer_fname = "lexer_" ^ Cli.language_code lang ^ ".py" in
match Pygment_lexers.read lexer_fname with
| None -> failwith "Pygments lexer not found for this language"
| Some lexer -> lexer
in
File.with_temp_file "pygments_lexer_" ".py" ~contents:lexer_py
@@ fun pyg_lexer -> f ["-l"; pyg_lexer; "-x"]
let call_pygmentize ?lang args =
let cmd = "pygmentize" in
let check_exit n =
@ -137,12 +147,5 @@ let call_pygmentize ?lang args =
match lang with
| None -> File.process_out ~check_exit cmd args
| Some lang ->
let lexer_py =
let lexer_fname = "lexer_" ^ Cli.language_code lang ^ ".py" in
match Pygment_lexers.read lexer_fname with
| None -> failwith "Pygments lexer not found for this language"
| Some lexer -> lexer
in
File.with_temp_file "pygments_lexer_" ".py" ~contents:lexer_py
@@ fun pyg_lexer ->
File.process_out ~check_exit cmd ("-l" :: pyg_lexer :: "-x" :: args)
with_pygmentize_lexer lang
@@ fun lex_args -> File.process_out ~check_exit cmd (lex_args @ args)

View File

@ -51,3 +51,7 @@ val call_pygmentize : ?lang:Cli.backend_lang -> string list -> string
(** Calls the [pygmentize] command with the given arguments, and returns the
results as a string. If [lang] is specified, the proper arguments for the
Catala lexer are already passed. *)
val with_pygmentize_lexer : Cli.backend_lang -> (string list -> 'a) -> 'a
(** Creates the required lexer file and returns the corresponding [pygmentize]
command-line arguments *)

View File

@ -0,0 +1,54 @@
(* This file is part of the Catala compiler, a specification language for tax
and social benefits computation rules. Copyright (C) 2020 Inria, contributor:
Louis Gesbert <louis.gesbert@inria.fr>
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License. *)
open Catala_utils
open Literate_common
let lang_of_ext s =
if String.starts_with ~prefix:"catala_" s then
match s with
| "catala_en" -> Some Cli.En
| "catala_fr" -> Some Cli.Fr
| "catala_pl" -> Some Cli.Pl
| _ -> failwith "Unknown Catala dialect"
else None
let exec () =
let args = List.tl (Array.to_list Sys.argv) in
let rec find_lang acc = function
| "-l" :: lang :: r -> Some lang, List.rev_append acc r
| x :: r -> find_lang (x :: acc) r
| [] -> None, List.rev acc
in
let lang, args = find_lang [] args in
let catala_lang =
match lang with
| Some l -> lang_of_ext l
| None ->
List.find_map
(fun s ->
match Filename.extension s with
| "" -> None
| e -> lang_of_ext (String.sub e 1 (String.length e - 1)))
args
in
match catala_lang with
| None -> Unix.execvp "pygmentize" (Array.of_list args)
| Some lang ->
with_pygmentize_lexer lang
@@ fun lex_args ->
Unix.execvp "pygmentize"
(Array.of_list (("pygmentize" :: lex_args) @ List.tl args))

View File

@ -0,0 +1,19 @@
(* This file is part of the Catala compiler, a specification language for tax
and social benefits computation rules. Copyright (C) 2020 Inria, contributor:
Louis Gesbert <louis.gesbert@inria.fr>
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License. *)
val exec : unit -> unit
(** Wrapper around the [pygmentize] binary with support for Catala. Reads the
arguments directly from Sys.argv *)

View File

@ -26,6 +26,8 @@
\setlist[itemize]{noitemsep, topsep=0pt}
\renewcommand{\MintedPygmentize}{../../_build/default/compiler/catala.exe pygmentize}
% backquote dejavu fix
\makeatletter
\chardef\straightquote@code=\catcode`'

View File

@ -26,6 +26,8 @@
\setlist[itemize]{noitemsep, topsep=0pt}
\renewcommand{\MintedPygmentize}{../../_build/default/compiler/catala.exe pygmentize}
% backquote dejavu fix
\makeatletter
\chardef\straightquote@code=\catcode`'

134358
french_law/js/french_law.js generated

File diff suppressed because one or more lines are too long