From 468d514949874e28414eaaff26fae9b37df90135 Mon Sep 17 00:00:00 2001 From: turulomio Date: Tue, 10 Jun 2025 05:21:09 +0200 Subject: [PATCH] Now you can create a env name setting env directory name --- preprod/commons.py | 9 ++++++--- preprod/tests/test_commons.py | 21 ++++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/preprod/commons.py b/preprod/commons.py index cd0416a..623390e 100644 --- a/preprod/commons.py +++ b/preprod/commons.py @@ -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=""): """ diff --git a/preprod/tests/test_commons.py b/preprod/tests/test_commons.py index 08f060b..6562c59 100644 --- a/preprod/tests/test_commons.py +++ b/preprod/tests/test_commons.py @@ -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")