From 72e0f1e9fbeedb9804fdf1c2659e88c04a4684f8 Mon Sep 17 00:00:00 2001 From: David Whiteside Date: Wed, 10 Apr 2024 09:16:01 -0600 Subject: [PATCH] added help output and ability to use an argument for selecting the python to execute the virtual environment in --- setup.py | 3 ++- src/tempyenv/cli.py | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 289c7f5..5754386 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,8 @@ url='https://github.com/outbit/tempyenv', license='MIT', install_requires=[ - 'setuptools'], + 'setuptools', + 'venv'], include_package_data=True, package_dir={ '': 'src'}, diff --git a/src/tempyenv/cli.py b/src/tempyenv/cli.py index b40799f..ea39884 100644 --- a/src/tempyenv/cli.py +++ b/src/tempyenv/cli.py @@ -5,9 +5,13 @@ class TemporaryVenvCreator: - def __init__(self): + def __init__(self, python_exec=None): self.temp_dir = None self.venv_path = None + if python_exec is None: + python_exec=sys.executable + else: + self.python_exec = python_exec def create_temporary_directory(self): self.temp_dir = tempfile.TemporaryDirectory() @@ -15,7 +19,7 @@ def create_temporary_directory(self): def create_virtual_environment(self): try: - subprocess.run(['python3', '-m', 'venv', self.venv_path], check=True) + subprocess.run([self.python_exec, '-m', 'venv', self.venv_path], check=True) print(f"Virtual environment created at {self.venv_path}") except subprocess.CalledProcessError as e: print(f"Error creating virtual environment: {e}") @@ -36,8 +40,14 @@ def load_virtual_environment(self): def main(): + import argparse + parser = argparse.ArgumentParser() + parser.add_argument('-p', '--python', help='Specify the Python executable', dest='python_exec', default=sys.executable) + args = parser.parse_args() + python_exec = args.python_exec + print("(tempyenv) is setting up your virtual environment...hold tight") - venv_creator = TemporaryVenvCreator() + venv_creator = TemporaryVenvCreator(python_exec) venv_creator.create_temporary_directory() venv_creator.create_virtual_environment() venv_creator.load_virtual_environment()