From 7bd120804c92f71e0213f290d35acd454eaf3564 Mon Sep 17 00:00:00 2001 From: jpantos <150924733+jpantos@users.noreply.github.com> Date: Wed, 19 Jun 2024 13:28:59 +0200 Subject: [PATCH] fix: PAN-1971 add env file env variable (#34) --- .github/workflows/release.yaml | 2 +- README.md | 18 +++++++++++++++++- pantos/common/configuration.py | 4 ++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a8df85f..0a5e5d0 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -81,7 +81,7 @@ jobs: runs-on: ubuntu-latest environment: name: pypi - url: https://pypi.org/p/pantos-common/${{ needs.define-environment.outputs.version }} + url: https://pypi.org/project/pantos-common/${{ needs.define-environment.outputs.version }} permissions: id-token: write # IMPORTANT: this permission is mandatory for trusted publishing steps: diff --git a/README.md b/README.md index 188f29e..429c25f 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,22 @@ $ poetry install --no-root The Pantos Common project should be used as a utility library, for example as a submodule in an upstream project. After those steps, the modules can be imported directly from the Common library. -### 3.1 Examples +### 3.1 Configuration + +The Pantos Common library allows its configuration to be loaded from multiple predefined folders. This normally involves an environment file and a base YAML configuration file, which can be located in the following predefined paths: + +``` + $PWD + $HOME + ~/.config + /etc/pantos + /etc +``` + +Each service defines a default file name under which this file is searched. The service then expects the environment file to be present in the same location with the same name but with a different .env extension. + +Alternatively one can define the location of such files by using the `PANTOS_CONFIG` and `PANTOS_ENV_FILE` environment variables. + +### 3.2 Examples https://github.com/pantos-io/client-library/blob/main/pantos/client/library/blockchains/base.py diff --git a/pantos/common/configuration.py b/pantos/common/configuration.py index a966396..a90a06e 100644 --- a/pantos/common/configuration.py +++ b/pantos/common/configuration.py @@ -175,6 +175,10 @@ def __parse_file(self, path: pathlib.Path) -> dict[str, typing.Any]: pathlib.Path(path.as_posix() + '.env'), pathlib.Path(path.with_suffix('.env').as_posix()) ] + if os.environ.get('PANTOS_ENV_FILE'): + _logger.info('loading env variables from environment defined file ' + 'PANTOS_ENV_FILE') + env_files.insert(0, pathlib.Path(os.environ['PANTOS_ENV_FILE'])) # Iterate over the potential .env file paths for env_file in env_files: if env_file.is_file():