Skip to content

Commit

Permalink
set the actual environment
Browse files Browse the repository at this point in the history
  • Loading branch information
trappitsch committed Mar 4, 2024
1 parent 551d72f commit fc54772
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/box/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ def _set_env(self):
os.environ["PYAPP_PYTHON_VERSION"] = py_version
if value := self.config.optional_dependencies:
os.environ["PYAPP_PIP_OPTIONAL_DEPS"] = value
optional_pyapp_vars = self.config.optional_pyapp_variables
for key, value in optional_pyapp_vars.items():
os.environ[key] = value

# STATIC METHODS #
@staticmethod
Expand Down
9 changes: 8 additions & 1 deletion tests/func/test_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ def test_package_pyapp_cargo_and_move(rye_project, mocker, binary_extensions):


@pytest.mark.parametrize("opt_deps", ["gui", None])
def test_set_env(rye_project, opt_deps, mocker):
@pytest.mark.parametrize("opt_pyapp_vars", ["PYAPP_SOMETHING 2", None])
def test_set_env(rye_project, opt_deps, opt_pyapp_vars, mocker):
"""Set environment for `PyApp` packaging."""
config = PyProjectParser()
exec_spec = config.app_entry
Expand All @@ -245,6 +246,10 @@ def test_set_env(rye_project, opt_deps, mocker):
# write optional deps to the pyproject.toml
if opt_deps:
pyproject_writer("optional_deps", opt_deps)
if opt_pyapp_vars:
tmp_split = opt_pyapp_vars.split()
opt_pyapp_vars = {tmp_split[0]: tmp_split[1]}
pyproject_writer("optional_pyapp_vars", opt_pyapp_vars)

packager = PackageApp()
packager.build()
Expand All @@ -258,6 +263,8 @@ def test_set_env(rye_project, opt_deps, mocker):
assert os.environ["PYAPP_PYTHON_VERSION"] == ut.PYAPP_PYTHON_VERSIONS[-1]
if opt_deps:
assert os.environ["PYAPP_PIP_OPTIONAL_DEPS"] == opt_deps
if opt_pyapp_vars:
assert os.environ["PYAPP_SOMETHING"] == "2"


def test_set_env_delete_existing(rye_project, mocker):
Expand Down

0 comments on commit fc54772

Please sign in to comment.