From 60ae54c0a9b93b2456155bee52dfda2b6028ed3c Mon Sep 17 00:00:00 2001 From: Lucas de Brito Silva Date: Thu, 24 Oct 2024 15:14:00 -0300 Subject: [PATCH] Update `interactive_setup.py` to improve virtual environment creation and installation process * **Virtual Environment:** - Replace `subprocess.run` with `venv.create` for creating virtual environments - Return the activation script path after creating the virtual environment * **Dependency Installation:** - Use `sys.executable` to run `pip` for installing dependencies * **Global Installation:** - Rename `global_install` to `global_installation` - Use `sys.executable` to run `pip` for global installation * **Docker Setup:** - Use consistent single quotes for `subprocess.run` commands --- interactive_setup.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/interactive_setup.py b/interactive_setup.py index 1c02aea..dda95d2 100644 --- a/interactive_setup.py +++ b/interactive_setup.py @@ -1,22 +1,24 @@ +import os import subprocess import questionary +import sys +import venv -def create_virtualenv(): - subprocess.run(["python3", "-m", "venv", "env"], check=True) - print("Virtual environment created successfully.") +def create_virtual_environment(): + venv_dir = os.path.join(os.getcwd(), 'venv') + venv.create(venv_dir, with_pip=True) + activate_script = os.path.join(venv_dir, 'bin', 'activate') + return activate_script def install_dependencies(): - subprocess.run(["env/bin/pip", "install", "-r", "requirements.txt"], check=True) - print("Dependencies installed successfully.") + subprocess.run([sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt'], check=True) -def global_install(): - subprocess.run(["pip", "install", "."], check=True) - print("Package installed globally.") +def global_installation(): + subprocess.run([sys.executable, '-m', 'pip', 'install', '.'], check=True) def docker_setup(): - subprocess.run(["docker", "build", "-t", "strava-to-trainingpeaks", "."], check=True) - subprocess.run(["docker", "run", "-it", "--rm", "strava-to-trainingpeaks"], check=True) - print("Docker container setup and running.") + subprocess.run(['docker', 'build', '-t', 'strava-to-trainingpeaks', '.'], check=True) + subprocess.run(['docker', 'run', '-it', '--rm', 'strava-to-trainingpeaks'], check=True) def main(): setup_method = questionary.select( @@ -25,10 +27,11 @@ def main(): ).ask() if setup_method == "Global installation": - global_install() + global_installation() elif setup_method == "Virtual environment": - create_virtualenv() + activate_script = create_virtual_environment() install_dependencies() + print(f"Virtual environment created. Activate it using 'source {activate_script}'") elif setup_method == "Docker": docker_setup() else: