Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions preprod/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,15 +474,18 @@ def dictionary_project_actions():
r[file_project].append(file_action)
return r

def create_python_virtual_env(python_version_name="python3.11", system_site_packages=False):
def create_python_virtual_env(python_version_name="python3", system_site_packages=False, env_name=None):
"""
Will create a python virtual env in .python_version_name with python_version_name executable
Parameters:
- python_version_name: str: python3.11
- system_site_packages: boolean: False
- env_name: str: None If None uses .python_version_name else directory. Must be a directory name
"""
str_sss="--system-site-packages" if system_site_packages else ""
run_and_check(f"{python_version_name} -m venv {str_sss} .{python_version_name}", description= f"Creating virtual env at .{python_version_name}")
return path.abspath(f".{python_version_name}/bin/python3"), path.abspath(f".{python_version_name}/bin/pip")
env_name=f".{python_version_name}" if env_name is None else env_name
run_and_check(f"{python_version_name} -m venv {str_sss} {env_name}", description= f"Creating virtual env at {env_name}")
return path.abspath(f"{env_name}/bin/python3"), path.abspath(f"{env_name}/bin/pip")

def apache_initd_restart(description=""):
"""
Expand Down
21 changes: 12 additions & 9 deletions preprod/tests/test_commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,19 @@ def create_and_run_action(func_name, code_):

def test_commons_create_python_virtual_env():
tmp_test_path=create_and_run_action(currentframe().f_code.co_name, """
preprod_commons.create_python_virtual_env(python_version_name="python3.11", system_site_packages=False)
preprod_commons.create_python_virtual_env(python_version_name="python3.12", system_site_packages=True)
preprod_commons.create_python_virtual_env(python_version_name="python3", system_site_packages=False)
preprod_commons.create_python_virtual_env(python_version_name="python", system_site_packages=True)
preprod_commons.create_python_virtual_env(python_version_name="python3", system_site_packages=False, env_name="pythonic")
""")
if which("python3.11"):
assert path.exists(f"{tmp_test_path}/.python3.11/bin/python3.11")
assert commons.file_contains_string(f"{tmp_test_path}/.python3.11/pyvenv.cfg", "include-system-site-packages = false")
if which("python3.12"):
assert path.exists(f"{tmp_test_path}/.python3.12/bin/python3.12")
assert commons.file_contains_string(f"{tmp_test_path}/.python3.12/pyvenv.cfg", "include-system-site-packages = true")

assert path.exists(f"{tmp_test_path}/.python3/bin/")
assert commons.file_contains_string(f"{tmp_test_path}/.python3/pyvenv.cfg", "include-system-site-packages = false")

assert path.exists(f"{tmp_test_path}/.python/bin/")
assert commons.file_contains_string(f"{tmp_test_path}/.python/pyvenv.cfg", "include-system-site-packages = true")

assert path.exists(f"{tmp_test_path}/pythonic/bin/")
assert commons.file_contains_string(f"{tmp_test_path}/pythonic/pyvenv.cfg", "include-system-site-packages = false")

def test_commons_rmtree():
tmp_test_path=create_and_run_action(currentframe().f_code.co_name, """
preprod_commons.makedirs("to_delete")
Expand Down