Skip to content

Commit

Permalink
Fake Python environment
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzymadness authored and hroncok committed Dec 13, 2022
1 parent c5281c6 commit 70a344a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/tox_current_env/hooks4.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import argparse
import os
import platform
import sys
import sysconfig
import tempfile
import warnings
from pathlib import Path
from typing import Set
Expand Down Expand Up @@ -146,7 +148,19 @@ def _get_python(self, base_python):
)

def create_python_env(self):
return None
# Fake Python environment just to make sure all possible
# commands like python or python3 works.
self.tempdir = tempfile.TemporaryDirectory()
for suffix in (
"",
f"{sys.version_info.major}",
f"{sys.version_info.major}.{sys.version_info.minor}",
):
os.symlink(sys.executable, Path(self.tempdir.name) / f"python{suffix}")
os.environ["PATH"] = ":".join((os.environ["PATH"], str(self.tempdir.name)))

def _teardown(self):
del self.tempdir

def env_bin_dir(self):
return Path(sysconfig.get_path("scripts"))
Expand Down

0 comments on commit 70a344a

Please sign in to comment.