diff --git a/.github/workflows/gempyor-ci.yml b/.github/workflows/gempyor-ci.yml index d70d19071..451235d8d 100644 --- a/.github/workflows/gempyor-ci.yml +++ b/.github/workflows/gempyor-ci.yml @@ -43,6 +43,7 @@ jobs: shell: bash - name: Run gempyor tests run: | + export FLEPI_PATH=$(pwd) cd flepimop/gempyor_pkg pytest --exitfirst shell: bash diff --git a/.gitignore b/.gitignore index 6eb84927e..1e9726360 100644 --- a/.gitignore +++ b/.gitignore @@ -78,3 +78,6 @@ flepimop/gempyor_pkg/.coverage # Environment variables .env + +# info/ directory +info/**/*.json diff --git a/flepimop/gempyor_pkg/pyproject.toml b/flepimop/gempyor_pkg/pyproject.toml index 6f90e1053..dfb6b28bd 100644 --- a/flepimop/gempyor_pkg/pyproject.toml +++ b/flepimop/gempyor_pkg/pyproject.toml @@ -20,11 +20,13 @@ dependencies = [ "emcee", "graphviz", "h5py", + "Jinja2", "matplotlib", "numba>=0.53.1", "numpy", "pandas", "pyarrow", + "pydantic", "scipy", "seaborn", "sympy", @@ -51,7 +53,8 @@ gempyor-simulate = "gempyor.simulate:_deprecated_simulate" [tool.setuptools] package-dir = {"" = "src"} -include-package-data = false +include-package-data = true +package-data = { "gempyor" = ["templates/*.j2"] } [tool.setuptools.packages.find] where = ["src"] diff --git a/flepimop/gempyor_pkg/src/gempyor/_jinja.py b/flepimop/gempyor_pkg/src/gempyor/_jinja.py new file mode 100644 index 000000000..bae0e9aae --- /dev/null +++ b/flepimop/gempyor_pkg/src/gempyor/_jinja.py @@ -0,0 +1,120 @@ +""" +Internal Jinja2 template rendering utilities. + +This module contains utilities for finding and rendering Jinja2 templates. This module +is tightly coupled to the organization of the package and not intended for external use. +""" + +# Exports +__all__ = [] + + +# Imports +from os.path import dirname +from pathlib import Path +from tempfile import mkstemp +from typing import Any + +from jinja2 import Environment, FileSystemLoader, PackageLoader, Template + + +# Globals +try: + _jinja_environment = Environment( + loader=FileSystemLoader(dirname(__file__).replace("\\", "/") + "/templates") + ) +except ValueError: + _jinja_environment = Environment(loader=PackageLoader("gempyor")) + + +# Functions +def _get_template(name: str) -> Template: + """ + Get a jinja template by name. + + Args: + name: The name of the template to pull. + + Returns: + A jinja template object corresponding to `name`. + + Examples: + >>> _get_template("test_template.j2") +