Skip to content

Commit

Permalink
Fix: allow passing of env-vars from one step into a later stage exec …
Browse files Browse the repository at this point in the history
…step

Add title and version to help usage output
Update and move readthedocs config file
Rename readthedocs config file to suit RTD
  • Loading branch information
ndejong committed Sep 23, 2024
1 parent 20c0a0c commit 46b6cbd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/env_alias/lib/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def generate(self) -> None:

if value is not None: # NB: not just "if value" because value could be a valid empty string
self.values_generated[definition.name] = value
os.environ[definition.name] = str(value) # exists at this process and sub-process only

if definition._is_internal_only is True:
logger.debug(
f"Definition for {definition.name!r} defines a 'null' name for env-alias internal "
Expand Down
5 changes: 3 additions & 2 deletions src/env_alias/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ def handle_args(args: List[str]) -> Tuple[str, str]:

def usage_help(exit_code: Union[int, None] = None) -> None:
print()
print("Usage: env-alias [<alias>] [--debug] <definitions.[yml|yaml]>")
print(f"{__title__} v{__version__}")
print()
print("Docs: https://env-alias.readthedocs.io/en/latest/")
print("Usage: env-alias [<alias>] [--debug] <definitions.[yml|yaml]>")
print("Docs: https://env-alias.readthedocs.io")
print()
if exit_code:
exit(exit_code)
22 changes: 22 additions & 0 deletions tests/test_exec_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ def test_sample_bad_exec_01(capsys):
assert "unknown-command-JHKJKHGJKHG: not found" in str(e_info)


def test_sample_exec_env_to_exec_01(capsys):
test_value = "".join(random.choice(string.ascii_lowercase) for _ in range(8))

yaml = """
env_to_exec_step01:
name: RANDOM_VALUE
value: '{test_value}'
TEST_VALUE:
exec: >
echo "> ${{RANDOM_VALUE}} <"
""".format(
test_value=test_value
)

config_file = __generate_config_file(yaml)
EnvAliasGenerator(config_file=config_file).generate()
os.unlink(config_file)

captured = capsys.readouterr().out.rstrip()
assert f' export "TEST_VALUE"="> {test_value} <"' in captured


def __generate_config_file(yaml_config) -> Path:
config = "env-alias:" + yaml_config
filename = os.path.join(tempfile.gettempdir(), "".join(random.choice(string.ascii_lowercase) for i in range(8)))
Expand Down

0 comments on commit 46b6cbd

Please sign in to comment.