pax_global_header00006660000000000000000000000064150106616350014515gustar00rootroot0000000000000052 comment=8f43568693ebd7fcad5c3b79ef6ce0072225914f pyyaml-env-tag-1.1/000077500000000000000000000000001501066163500142305ustar00rootroot00000000000000pyyaml-env-tag-1.1/.codecov.yml000066400000000000000000000002731501066163500164550ustar00rootroot00000000000000codecov: require_ci_to_pass: yes notify: after_n_builds: 15 # 5 python versions x 3 platforms = 15 comment: false coverage: precision: 2 round: down range: "90...100" pyyaml-env-tag-1.1/.github/000077500000000000000000000000001501066163500155705ustar00rootroot00000000000000pyyaml-env-tag-1.1/.github/workflows/000077500000000000000000000000001501066163500176255ustar00rootroot00000000000000pyyaml-env-tag-1.1/.github/workflows/ci.yml000066400000000000000000000026221501066163500207450ustar00rootroot00000000000000name: CI on: push: branches: - master tags: - '**' pull_request: branches: - '**' jobs: test: strategy: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', 'pypy-3.10'] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: Setup Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip coverage pyyaml - name: Install library run: | python -m pip install . - name: Run tests run: | coverage run --source=yaml_env_tag tests/test_yaml_env_tag.py - name: Generate coverage report if: success() run: | coverage xml coverage report --show-missing - name: Upload Results if: success() uses: codecov/codecov-action@v1 with: file: ./coverage.xml flags: unittests name: ${{ matrix.os }}/Python ${{ matrix.python-version }} fail_ci_if_error: false flake8: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: TrueBrain/actions-flake8@master if: github.event_name == 'pull_request' with: max_line_length: 118 pyyaml-env-tag-1.1/.github/workflows/deploy.yml000066400000000000000000000023651501066163500216520ustar00rootroot00000000000000name: deploy # See https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ on: push: tags: - '*' jobs: build: name: Build distribution runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: persist-credentials: false - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.x" - name: Install pypa/build run: python3 -m pip install build --user - name: Build a binary wheel and a source tarball run: python3 -m build - name: Store the distribution packages uses: actions/upload-artifact@v4 with: name: python-package-distributions path: dist/ pypi: name: Publish to PyPI needs: - build runs-on: ubuntu-latest environment: name: pypi url: https://pypi.org/p/pyyaml-env-tag permissions: id-token: write # IMPORTANT: mandatory for trusted publishing steps: - name: Download all the dists uses: actions/download-artifact@v4 with: name: python-package-distributions path: dist/ - name: Publish distribution to PyPI uses: pypa/gh-action-pypi-publish@release/v1 pyyaml-env-tag-1.1/.gitignore000066400000000000000000000037631501066163500162310ustar00rootroot00000000000000# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ share/python-wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover *.py,cover .hypothesis/ .pytest_cache/ cover/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py db.sqlite3 db.sqlite3-journal # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder .pybuilder/ target/ # Jupyter Notebook .ipynb_checkpoints # IPython profile_default/ ipython_config.py # pyenv # For a library or package, you might want to ignore these files since the code is # intended to run in multiple environments; otherwise, check them in: # .python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. # However, in case of collaboration, if having platform-specific dependencies or dependencies # having no cross-platform support, pipenv may install dependencies that don't work, or not # install all needed dependencies. #Pipfile.lock # PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff celerybeat-schedule celerybeat.pid # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ .dmypy.json dmypy.json # Pyre type checker .pyre/ # pytype static type analyzer .pytype/ # Cython debug symbols cython_debug/ pyyaml-env-tag-1.1/LICENSE000066400000000000000000000020561501066163500152400ustar00rootroot00000000000000MIT License Copyright (c) 2020 Waylan Limberg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.pyyaml-env-tag-1.1/README.md000066400000000000000000000105051501066163500155100ustar00rootroot00000000000000# pyyaml_env_tag A custom YAML tag for referencing environment variables in YAML files. [![PyPI Version][pypi-image]][pypi-link] [![Build Status][GHAction-image]][GHAction-link] [![Coverage Status][codecov-image]][codecov-link] [pypi-image]: https://img.shields.io/pypi/v/pyyaml-env-tag.svg [pypi-link]: https://pypi.org/project/pyyaml-env-tag/ [GHAction-image]: https://github.com/waylan/pyyaml-env-tag/workflows/CI/badge.svg?branch=master&event=push [GHAction-link]: https://github.com/waylan/pyyaml-env-tag/actions?query=event%3Apush+branch%3Amaster [codecov-image]: https://codecov.io/github/waylan/pyyaml-env-tag/coverage.svg?branch=master [codecov-link]: https://codecov.io/github/waylan/pyyaml-env-tag?branch=master ## Installation Install the `pyyaml_env_tag` package with pip: ```bash pip install pyyaml_env_tag ``` ### Enabling the tag To enable the tag, pass your loader of choice into the `add_env_tag` function, which will return the loader with the construstor added to it. ```python import yaml from yaml_env_tag import add_env_tag myLoader = add_env_tag(yaml.Loader) ``` Then you may use the loader as per usual. For example: ```python yaml.load(data, Loader=myLoader) ``` The `add_env_tag` is a high level helper function. If you need lower level access, you may add the constructor (`yaml_env_tag.construct_env_tag`) to the loader directly using the `add_constructor` method of the loader. Note that this requires that the tag (`!ENV`) be defined as well. ```python from yaml_env_tag import construct_env_tag Loader.add_constructor('!ENV', construct_env_tag) ``` ## Using the tag Include the tag `!ENV` followed by the name of an environment variable in a YAML file and the value of the environment variable will be used in its place. ```yaml key: !ENV SOME_VARIABLE ``` If `SOME_VARIABLE` is set to `A string!`, then the above YAML would result in the following Python object: ```python {'key': 'A string!'} ``` The content of the variable is parsed using YAML's implicit scalar types, such as string, bool, integer, float, datestamp and null. More complex types are not recognized and simply passed through as a string. For example, if `SOME_VARIABLE` was set to the string `true`, then the above YAML would result in the following: ```python {'key': True} ``` If the variable specified is not set, then a `null` value is assigned as a default. You may define your own default as the last item in a sequence. ```yaml key: !ENV [SOME_VARIABLE, default] ``` In the above example, if `SOME_VARIABLE` is not defined, the string `default` would be used instead, as follows: ```python {'key': 'default'} ``` You may list multiple variables as fallbacks. The first variable which is set is used. In any sequance with more than one item, the last item must always be a default value and will not be resolved as an environment variable. ```yaml key: !ENV [SOME_VARIABLE, FALLBACK, default] ``` As with variable contents, the default is resolved to a Python object of the implied type (string, bool, integer, float, datestamp and null). When `SOME_VARIABLE` is not set, all four of the following items will resolve to the same value (`None`): ```yaml - !ENV SOME_VARIABLE - !ENV [SOME_VARIABLE] - !ENV [SOME_VARIABLE, ~] - !ENV [SOME_VARIABLE, null] ``` ## Related pyyaml_env_tag was inspired by the Ruby package [yaml-env-tag]. An alternate method of referencing environment variables in YAML files is implemented by [pyyaml-tags] and [python_yaml_environment_variables]. Each of those libraries use a template string and replace the template tag with the content of the variable. While this allows a single value to reference multiple variables and to contain additional content, it restricts all values to strings only and does not provide a way to define defaults. [yaml-env-tag]: https://github.com/jirutka/yaml-env-tag [pyyaml-tags]: https://github.com/meiblorn/pyyaml-tags [python_yaml_environment_variables]: https://gist.github.com/mkaranasou/ba83e25c835a8f7629e34dd7ede01931 ## License pyyaml_env_tag is licensed under the [MIT License] as defined in `LICENSE`. [MIT License]: https://opensource.org/licenses/MIT ## Changelog ### [1.1] - 2025-05-13 - Ensure tests get included with distribution (#9). ### [1.0] - 2025-05-09 - Add the `add_env_tag` helper function as a higher level way of modifying the loader. ### [0.1] - 2020-11-11 The initial release. pyyaml-env-tag-1.1/pyproject.toml000066400000000000000000000024341501066163500171470ustar00rootroot00000000000000[build-system] requires = ['setuptools>=77.0'] build-backend = 'setuptools.build_meta' [project] name = 'pyyaml_env_tag' dynamic = ['version'] description = 'A custom YAML tag for referencing environment variables in YAML files.' readme = {file = 'README.md', content-type='text/markdown'} authors = [{name = 'Waylan Limberg', email = 'waylan.limberg@icloud.com'}] requires-python = '>=3.9' dependencies = ['pyyaml'] license = 'MIT' license-files = ['LICENSE'] classifiers = [ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'Operating System :: OS Independent', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', 'Programming Language :: Python :: 3.12', 'Programming Language :: Python :: 3.13', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Text Processing :: Markup', ] [project.urls] Homepage = 'https://github.com/waylan/pyyaml-env-tag' Repository = 'https://github.com/waylan/pyyaml-env-tag' 'Bug Tracker' = 'https://github.com/waylan/pyyaml-env-tag/issues' [tool.setuptools] py-modules = ['yaml_env_tag'] [tool.setuptools.dynamic] version = {attr = 'yaml_env_tag.__version__'} pyyaml-env-tag-1.1/tests/000077500000000000000000000000001501066163500153725ustar00rootroot00000000000000pyyaml-env-tag-1.1/tests/test_yaml_env_tag.py000066400000000000000000000166151501066163500214610ustar00rootroot00000000000000import os import yaml import datetime import unittest from unittest import mock from yaml_env_tag import add_env_tag def mockenv(**kwargs): ''' Decorator to mock os.environ with provided variables. ''' return mock.patch.dict(os.environ, kwargs) class TestYamlEnvTag(unittest.TestCase): def assertYamlLoad(self, data, expected, loader=yaml.Loader): self.assertEqual(expected, yaml.load(data, Loader=add_env_tag(loader))) @mockenv(VAR='foo') def test_scalar(self): self.assertYamlLoad( '!ENV VAR', 'foo' ) def test_scalar_undefined(self): self.assertYamlLoad( '!ENV VAR', None ) @mockenv(VAR='foo') def test_safe_loader(self): self.assertYamlLoad( '!ENV VAR', 'foo', yaml.SafeLoader ) @mockenv(VAR='foo') def test_scalar_in_squence(self): self.assertYamlLoad( '- !ENV VAR', ['foo'] ) @mockenv(VAR='foo') def test_scalar_in_mapping(self): self.assertYamlLoad( 'key: !ENV VAR', {'key': 'foo'} ) @mockenv(VAR='foo') def test_sequence_1(self): self.assertYamlLoad( '!ENV [VAR]', 'foo' ) def test_sequence_1_undefined(self): self.assertYamlLoad( '!ENV [VAR]', None ) @mockenv(VAR='foo') def test_sequence_2(self): self.assertYamlLoad( '!ENV [VAR, default]', 'foo' ) def test_sequence_2_undefined(self): self.assertYamlLoad( '!ENV [VAR, default]', 'default' ) @mockenv(VAR1='foo', VAR2='bar') def test_sequence_3(self): self.assertYamlLoad( '!ENV [VAR1, VAR2, default]', 'foo' ) @mockenv(VAR2='bar') def test_sequence_3_1_undefined(self): self.assertYamlLoad( '!ENV [VAR1, VAR2, default]', 'bar' ) def test_sequence_3_undefined(self): self.assertYamlLoad( '!ENV [VAR1, VAR2, default]', 'default' ) def test_default_type_null(self): self.assertYamlLoad( '!ENV [VAR, null]', None ) def test_default_type_tilde(self): self.assertYamlLoad( '!ENV [VAR, ~]', None ) def test_default_type_bool_false(self): self.assertYamlLoad( '!ENV [VAR, false]', False ) def test_default_type_bool_true(self): self.assertYamlLoad( '!ENV [VAR, true]', True ) def test_default_type_str(self): self.assertYamlLoad( '!ENV [VAR, "a string"]', 'a string' ) def test_default_type_int(self): self.assertYamlLoad( '!ENV [VAR, 42]', 42 ) def test_default_type_float(self): self.assertYamlLoad( '!ENV [VAR, 3.14]', 3.14 ) def test_default_type_date(self): self.assertYamlLoad( '!ENV [VAR, 2020-11-11]', datetime.date(2020, 11, 11) ) def test_default_type_sequence(self): self.assertYamlLoad( '!ENV [VAR, [foo, bar]]', ['foo', 'bar'] ) def test_default_type_mapping(self): self.assertYamlLoad( '!ENV [VAR, foo: bar]', {'foo': 'bar'} ) @mockenv(VAR='null') def test_env_value_type_null(self): self.assertYamlLoad( '!ENV [VAR, default]', None ) @mockenv(VAR='~') def test_env_value_type_tilde(self): self.assertYamlLoad( '!ENV [VAR, default]', None ) @mockenv(VAR='false') def test_env_value_type_bool_false(self): self.assertYamlLoad( '!ENV VAR', False ) @mockenv(VAR='true') def test_env_value_type_bool_true(self): self.assertYamlLoad( '!ENV VAR', True ) @mockenv(VAR='a string') def test_env_value_type_str(self): self.assertYamlLoad( '!ENV VAR', 'a string' ) @mockenv(VAR='42') def test_env_value_type_int(self): self.assertYamlLoad( '!ENV VAR', 42 ) @mockenv(VAR='3.14') def test_env_value_type_float(self): self.assertYamlLoad( '!ENV VAR', 3.14 ) @mockenv(VAR='2020-11-11') def test_env_value_type_date(self): self.assertYamlLoad( '!ENV VAR', datetime.date(2020, 11, 11) ) @mockenv(VAR='[foo, bar]') def test_env_value_type_sequence(self): self.assertYamlLoad( '!ENV VAR', '[foo, bar]' ) @mockenv(VAR='foo: bar') def test_env_value_type_mapping(self): self.assertYamlLoad( '!ENV VAR', 'foo: bar' ) @mockenv(UPPERCASE='foo') def test_env_name_uppercase(self): self.assertYamlLoad( '!ENV UPPERCASE', 'foo' ) @mockenv(lowercase='foo') def test_env_name_lowercase(self): self.assertYamlLoad( '!ENV lowercase', 'foo' ) @mockenv(CamelCase='foo') def test_env_name_CamelCase(self): self.assertYamlLoad( '!ENV CamelCase', 'foo' ) @mockenv(snake_case='foo') def test_env_name_snake_case(self): self.assertYamlLoad( '!ENV snake_case', 'foo' ) # WARNING! The Environment Variable names in the following tests are # probably a bad idea in use. In fact, it may not even be possable to # set them in most OSs. We are testing that they don't get converted # to native Python types, ensuring expected results in edge cases. @mockenv(null='foo') def test_env_name_null(self): self.assertYamlLoad( '!ENV null', 'foo' ) @mockenv(**{'~': 'foo'}) def test_env_name_tilde(self): self.assertYamlLoad( '!ENV ~', 'foo' ) @mockenv(**{'true': 'foo'}) def test_env_name_true(self): self.assertYamlLoad( '!ENV true', 'foo' ) @mockenv(**{'false': 'foo'}) def test_env_name_false(self): self.assertYamlLoad( '!ENV false', 'foo' ) @mockenv(**{'42': 'foo'}) def test_env_name_int(self): self.assertYamlLoad( '!ENV 42', 'foo' ) @mockenv(**{'3.14': 'foo'}) def test_env_name_float(self): self.assertYamlLoad( '!ENV 3.14', 'foo' ) @mockenv(**{'2020-11-11': 'foo'}) def test_env_name_date(self): self.assertYamlLoad( '!ENV 2020-11-11', 'foo' ) def test_env_name_sequance(self): self.assertRaises( yaml.constructor.ConstructorError, yaml.load, '!ENV [[foo]]', Loader=add_env_tag(yaml.Loader) ) def test_env_name_mapping(self): self.assertRaises( yaml.constructor.ConstructorError, yaml.load, '!ENV {key: value}', Loader=add_env_tag(yaml.Loader) ) if __name__ == '__main__': unittest.main() pyyaml-env-tag-1.1/uv.lock000066400000000000000000000312021501066163500155320ustar00rootroot00000000000000version = 1 revision = 1 requires-python = ">=3.9" [[package]] name = "pyyaml" version = "6.0.2" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/54/ed/79a089b6be93607fa5cdaedf301d7dfb23af5f25c398d5ead2525b063e17/pyyaml-6.0.2.tar.gz", hash = "sha256:d584d9ec91ad65861cc08d42e834324ef890a082e591037abe114850ff7bbc3e", size = 130631 } wheels = [ { url = "https://files.pythonhosted.org/packages/9b/95/a3fac87cb7158e231b5a6012e438c647e1a87f09f8e0d123acec8ab8bf71/PyYAML-6.0.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:0a9a2848a5b7feac301353437eb7d5957887edbf81d56e903999a75a3d743086", size = 184199 }, { url = "https://files.pythonhosted.org/packages/c7/7a/68bd47624dab8fd4afbfd3c48e3b79efe09098ae941de5b58abcbadff5cb/PyYAML-6.0.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:29717114e51c84ddfba879543fb232a6ed60086602313ca38cce623c1d62cfbf", size = 171758 }, { url = "https://files.pythonhosted.org/packages/49/ee/14c54df452143b9ee9f0f29074d7ca5516a36edb0b4cc40c3f280131656f/PyYAML-6.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8824b5a04a04a047e72eea5cec3bc266db09e35de6bdfe34c9436ac5ee27d237", size = 718463 }, { url = "https://files.pythonhosted.org/packages/4d/61/de363a97476e766574650d742205be468921a7b532aa2499fcd886b62530/PyYAML-6.0.2-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7c36280e6fb8385e520936c3cb3b8042851904eba0e58d277dca80a5cfed590b", size = 719280 }, { url = "https://files.pythonhosted.org/packages/6b/4e/1523cb902fd98355e2e9ea5e5eb237cbc5f3ad5f3075fa65087aa0ecb669/PyYAML-6.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ec031d5d2feb36d1d1a24380e4db6d43695f3748343d99434e6f5f9156aaa2ed", size = 751239 }, { url = "https://files.pythonhosted.org/packages/b7/33/5504b3a9a4464893c32f118a9cc045190a91637b119a9c881da1cf6b7a72/PyYAML-6.0.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:936d68689298c36b53b29f23c6dbb74de12b4ac12ca6cfe0e047bedceea56180", size = 695802 }, { url = "https://files.pythonhosted.org/packages/5c/20/8347dcabd41ef3a3cdc4f7b7a2aff3d06598c8779faa189cdbf878b626a4/PyYAML-6.0.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:23502f431948090f597378482b4812b0caae32c22213aecf3b55325e049a6c68", size = 720527 }, { url = "https://files.pythonhosted.org/packages/be/aa/5afe99233fb360d0ff37377145a949ae258aaab831bde4792b32650a4378/PyYAML-6.0.2-cp310-cp310-win32.whl", hash = "sha256:2e99c6826ffa974fe6e27cdb5ed0021786b03fc98e5ee3c5bfe1fd5015f42b99", size = 144052 }, { url = "https://files.pythonhosted.org/packages/b5/84/0fa4b06f6d6c958d207620fc60005e241ecedceee58931bb20138e1e5776/PyYAML-6.0.2-cp310-cp310-win_amd64.whl", hash = "sha256:a4d3091415f010369ae4ed1fc6b79def9416358877534caf6a0fdd2146c87a3e", size = 161774 }, { url = "https://files.pythonhosted.org/packages/f8/aa/7af4e81f7acba21a4c6be026da38fd2b872ca46226673c89a758ebdc4fd2/PyYAML-6.0.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:cc1c1159b3d456576af7a3e4d1ba7e6924cb39de8f67111c735f6fc832082774", size = 184612 }, { url = "https://files.pythonhosted.org/packages/8b/62/b9faa998fd185f65c1371643678e4d58254add437edb764a08c5a98fb986/PyYAML-6.0.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:1e2120ef853f59c7419231f3bf4e7021f1b936f6ebd222406c3b60212205d2ee", size = 172040 }, { url = "https://files.pythonhosted.org/packages/ad/0c/c804f5f922a9a6563bab712d8dcc70251e8af811fce4524d57c2c0fd49a4/PyYAML-6.0.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5d225db5a45f21e78dd9358e58a98702a0302f2659a3c6cd320564b75b86f47c", size = 736829 }, { url = "https://files.pythonhosted.org/packages/51/16/6af8d6a6b210c8e54f1406a6b9481febf9c64a3109c541567e35a49aa2e7/PyYAML-6.0.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:5ac9328ec4831237bec75defaf839f7d4564be1e6b25ac710bd1a96321cc8317", size = 764167 }, { url = "https://files.pythonhosted.org/packages/75/e4/2c27590dfc9992f73aabbeb9241ae20220bd9452df27483b6e56d3975cc5/PyYAML-6.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3ad2a3decf9aaba3d29c8f537ac4b243e36bef957511b4766cb0057d32b0be85", size = 762952 }, { url = "https://files.pythonhosted.org/packages/9b/97/ecc1abf4a823f5ac61941a9c00fe501b02ac3ab0e373c3857f7d4b83e2b6/PyYAML-6.0.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:ff3824dc5261f50c9b0dfb3be22b4567a6f938ccce4587b38952d85fd9e9afe4", size = 735301 }, { url = "https://files.pythonhosted.org/packages/45/73/0f49dacd6e82c9430e46f4a027baa4ca205e8b0a9dce1397f44edc23559d/PyYAML-6.0.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:797b4f722ffa07cc8d62053e4cff1486fa6dc094105d13fea7b1de7d8bf71c9e", size = 756638 }, { url = "https://files.pythonhosted.org/packages/22/5f/956f0f9fc65223a58fbc14459bf34b4cc48dec52e00535c79b8db361aabd/PyYAML-6.0.2-cp311-cp311-win32.whl", hash = "sha256:11d8f3dd2b9c1207dcaf2ee0bbbfd5991f571186ec9cc78427ba5bd32afae4b5", size = 143850 }, { url = "https://files.pythonhosted.org/packages/ed/23/8da0bbe2ab9dcdd11f4f4557ccaf95c10b9811b13ecced089d43ce59c3c8/PyYAML-6.0.2-cp311-cp311-win_amd64.whl", hash = "sha256:e10ce637b18caea04431ce14fabcf5c64a1c61ec9c56b071a4b7ca131ca52d44", size = 161980 }, { url = "https://files.pythonhosted.org/packages/86/0c/c581167fc46d6d6d7ddcfb8c843a4de25bdd27e4466938109ca68492292c/PyYAML-6.0.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:c70c95198c015b85feafc136515252a261a84561b7b1d51e3384e0655ddf25ab", size = 183873 }, { url = "https://files.pythonhosted.org/packages/a8/0c/38374f5bb272c051e2a69281d71cba6fdb983413e6758b84482905e29a5d/PyYAML-6.0.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:ce826d6ef20b1bc864f0a68340c8b3287705cae2f8b4b1d932177dcc76721725", size = 173302 }, { url = "https://files.pythonhosted.org/packages/c3/93/9916574aa8c00aa06bbac729972eb1071d002b8e158bd0e83a3b9a20a1f7/PyYAML-6.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1f71ea527786de97d1a0cc0eacd1defc0985dcf6b3f17bb77dcfc8c34bec4dc5", size = 739154 }, { url = "https://files.pythonhosted.org/packages/95/0f/b8938f1cbd09739c6da569d172531567dbcc9789e0029aa070856f123984/PyYAML-6.0.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9b22676e8097e9e22e36d6b7bda33190d0d400f345f23d4065d48f4ca7ae0425", size = 766223 }, { url = "https://files.pythonhosted.org/packages/b9/2b/614b4752f2e127db5cc206abc23a8c19678e92b23c3db30fc86ab731d3bd/PyYAML-6.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:80bab7bfc629882493af4aa31a4cfa43a4c57c83813253626916b8c7ada83476", size = 767542 }, { url = "https://files.pythonhosted.org/packages/d4/00/dd137d5bcc7efea1836d6264f049359861cf548469d18da90cd8216cf05f/PyYAML-6.0.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:0833f8694549e586547b576dcfaba4a6b55b9e96098b36cdc7ebefe667dfed48", size = 731164 }, { url = "https://files.pythonhosted.org/packages/c9/1f/4f998c900485e5c0ef43838363ba4a9723ac0ad73a9dc42068b12aaba4e4/PyYAML-6.0.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8b9c7197f7cb2738065c481a0461e50ad02f18c78cd75775628afb4d7137fb3b", size = 756611 }, { url = "https://files.pythonhosted.org/packages/df/d1/f5a275fdb252768b7a11ec63585bc38d0e87c9e05668a139fea92b80634c/PyYAML-6.0.2-cp312-cp312-win32.whl", hash = "sha256:ef6107725bd54b262d6dedcc2af448a266975032bc85ef0172c5f059da6325b4", size = 140591 }, { url = "https://files.pythonhosted.org/packages/0c/e8/4f648c598b17c3d06e8753d7d13d57542b30d56e6c2dedf9c331ae56312e/PyYAML-6.0.2-cp312-cp312-win_amd64.whl", hash = "sha256:7e7401d0de89a9a855c839bc697c079a4af81cf878373abd7dc625847d25cbd8", size = 156338 }, { url = "https://files.pythonhosted.org/packages/ef/e3/3af305b830494fa85d95f6d95ef7fa73f2ee1cc8ef5b495c7c3269fb835f/PyYAML-6.0.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:efdca5630322a10774e8e98e1af481aad470dd62c3170801852d752aa7a783ba", size = 181309 }, { url = "https://files.pythonhosted.org/packages/45/9f/3b1c20a0b7a3200524eb0076cc027a970d320bd3a6592873c85c92a08731/PyYAML-6.0.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:50187695423ffe49e2deacb8cd10510bc361faac997de9efef88badc3bb9e2d1", size = 171679 }, { url = "https://files.pythonhosted.org/packages/7c/9a/337322f27005c33bcb656c655fa78325b730324c78620e8328ae28b64d0c/PyYAML-6.0.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0ffe8360bab4910ef1b9e87fb812d8bc0a308b0d0eef8c8f44e0254ab3b07133", size = 733428 }, { url = "https://files.pythonhosted.org/packages/a3/69/864fbe19e6c18ea3cc196cbe5d392175b4cf3d5d0ac1403ec3f2d237ebb5/PyYAML-6.0.2-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:17e311b6c678207928d649faa7cb0d7b4c26a0ba73d41e99c4fff6b6c3276484", size = 763361 }, { url = "https://files.pythonhosted.org/packages/04/24/b7721e4845c2f162d26f50521b825fb061bc0a5afcf9a386840f23ea19fa/PyYAML-6.0.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:70b189594dbe54f75ab3a1acec5f1e3faa7e8cf2f1e08d9b561cb41b845f69d5", size = 759523 }, { url = "https://files.pythonhosted.org/packages/2b/b2/e3234f59ba06559c6ff63c4e10baea10e5e7df868092bf9ab40e5b9c56b6/PyYAML-6.0.2-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:41e4e3953a79407c794916fa277a82531dd93aad34e29c2a514c2c0c5fe971cc", size = 726660 }, { url = "https://files.pythonhosted.org/packages/fe/0f/25911a9f080464c59fab9027482f822b86bf0608957a5fcc6eaac85aa515/PyYAML-6.0.2-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:68ccc6023a3400877818152ad9a1033e3db8625d899c72eacb5a668902e4d652", size = 751597 }, { url = "https://files.pythonhosted.org/packages/14/0d/e2c3b43bbce3cf6bd97c840b46088a3031085179e596d4929729d8d68270/PyYAML-6.0.2-cp313-cp313-win32.whl", hash = "sha256:bc2fa7c6b47d6bc618dd7fb02ef6fdedb1090ec036abab80d4681424b84c1183", size = 140527 }, { url = "https://files.pythonhosted.org/packages/fa/de/02b54f42487e3d3c6efb3f89428677074ca7bf43aae402517bc7cca949f3/PyYAML-6.0.2-cp313-cp313-win_amd64.whl", hash = "sha256:8388ee1976c416731879ac16da0aff3f63b286ffdd57cdeb95f3f2e085687563", size = 156446 }, { url = "https://files.pythonhosted.org/packages/65/d8/b7a1db13636d7fb7d4ff431593c510c8b8fca920ade06ca8ef20015493c5/PyYAML-6.0.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:688ba32a1cffef67fd2e9398a2efebaea461578b0923624778664cc1c914db5d", size = 184777 }, { url = "https://files.pythonhosted.org/packages/0a/02/6ec546cd45143fdf9840b2c6be8d875116a64076218b61d68e12548e5839/PyYAML-6.0.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:a8786accb172bd8afb8be14490a16625cbc387036876ab6ba70912730faf8e1f", size = 172318 }, { url = "https://files.pythonhosted.org/packages/0e/9a/8cc68be846c972bda34f6c2a93abb644fb2476f4dcc924d52175786932c9/PyYAML-6.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d8e03406cac8513435335dbab54c0d385e4a49e4945d2909a581c83647ca0290", size = 720891 }, { url = "https://files.pythonhosted.org/packages/e9/6c/6e1b7f40181bc4805e2e07f4abc10a88ce4648e7e95ff1abe4ae4014a9b2/PyYAML-6.0.2-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f753120cb8181e736c57ef7636e83f31b9c0d1722c516f7e86cf15b7aa57ff12", size = 722614 }, { url = "https://files.pythonhosted.org/packages/3d/32/e7bd8535d22ea2874cef6a81021ba019474ace0d13a4819c2a4bce79bd6a/PyYAML-6.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3b1fdb9dc17f5a7677423d508ab4f243a726dea51fa5e70992e59a7411c89d19", size = 737360 }, { url = "https://files.pythonhosted.org/packages/d7/12/7322c1e30b9be969670b672573d45479edef72c9a0deac3bb2868f5d7469/PyYAML-6.0.2-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:0b69e4ce7a131fe56b7e4d770c67429700908fc0752af059838b1cfb41960e4e", size = 699006 }, { url = "https://files.pythonhosted.org/packages/82/72/04fcad41ca56491995076630c3ec1e834be241664c0c09a64c9a2589b507/PyYAML-6.0.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:a9f8c2e67970f13b16084e04f134610fd1d374bf477b17ec1599185cf611d725", size = 723577 }, { url = "https://files.pythonhosted.org/packages/ed/5e/46168b1f2757f1fcd442bc3029cd8767d88a98c9c05770d8b420948743bb/PyYAML-6.0.2-cp39-cp39-win32.whl", hash = "sha256:6395c297d42274772abc367baaa79683958044e5d3835486c16da75d2a694631", size = 144593 }, { url = "https://files.pythonhosted.org/packages/19/87/5124b1c1f2412bb95c59ec481eaf936cd32f0fe2a7b16b97b81c4c017a6a/PyYAML-6.0.2-cp39-cp39-win_amd64.whl", hash = "sha256:39693e1f8320ae4f43943590b49779ffb98acb81f788220ea932a6b6c51004d8", size = 162312 }, ] [[package]] name = "pyyaml-env-tag" source = { editable = "." } dependencies = [ { name = "pyyaml" }, ] [package.metadata] requires-dist = [{ name = "pyyaml" }] pyyaml-env-tag-1.1/yaml_env_tag.py000066400000000000000000000030111501066163500172420ustar00rootroot00000000000000""" A custom YAML tag for referencing environment variables in YAML files. """ __version__ = '1.1' import os import yaml from typing import Any def construct_env_tag(loader: yaml.Loader, node: yaml.Node) -> Any: """Assign value of ENV variable referenced at node.""" default = None if isinstance(node, yaml.nodes.ScalarNode): vars = [loader.construct_scalar(node)] elif isinstance(node, yaml.nodes.SequenceNode): child_nodes = node.value if len(child_nodes) > 1: # default is resolved using YAML's (implicit) types. default = loader.construct_object(child_nodes[-1]) child_nodes = child_nodes[:-1] # Env Vars are resolved as string values, ignoring (implicit) types. vars = [loader.construct_scalar(child) for child in child_nodes] else: raise yaml.constructor.ConstructorError( None, None, f'expected a scalar or sequence node, but found {node.id}', node.start_mark ) for var in vars: if var in os.environ: value = os.environ[var] # Resolve value to Python type using YAML's implicit resolvers tag = loader.resolve(yaml.nodes.ScalarNode, value, (True, False)) return loader.construct_object(yaml.nodes.ScalarNode(tag, value)) return default def add_env_tag(loader: yaml.Loader) -> yaml.Loader: """ Modify and return Loader with env tag support. """ loader.add_constructor('!ENV', construct_env_tag) return loader