Skip to content

Commit

Permalink
added help output and ability to use an argument for selecting the py…
Browse files Browse the repository at this point in the history
…thon to execute the virtual environment in
  • Loading branch information
thedavidwhiteside committed Apr 10, 2024
1 parent bf0639e commit 72e0f1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
url='https://github.com/outbit/tempyenv',
license='MIT',
install_requires=[
'setuptools'],
'setuptools',
'venv'],
include_package_data=True,
package_dir={
'': 'src'},
Expand Down
16 changes: 13 additions & 3 deletions src/tempyenv/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@


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()
self.venv_path = os.path.join(self.temp_dir.name, 'venv')

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}")
Expand All @@ -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()
Expand Down

0 comments on commit 72e0f1e

Please sign in to comment.