Skip to content

Commit

Permalink
Update interactive_setup.py to improve virtual environment creation…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
Lucs1590 committed Oct 24, 2024
1 parent eff4861 commit 60ae54c
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions interactive_setup.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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:
Expand Down

0 comments on commit 60ae54c

Please sign in to comment.