Skip to content

Commit

Permalink
fix: PAN-1971 add env file env variable (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpantos authored Jun 19, 2024
1 parent f9c660f commit 7bd1208
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions pantos/common/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 7bd1208

Please sign in to comment.