1
0
mirror of https://github.com/fedora-python/tox-current-env.git synced 2025-06-29 22:24:51 +02:00

Fake Python environment

This commit is contained in:
Lumir Balhar 2021-12-14 23:24:00 +01:00 committed by Miro Hrončok
parent c5281c6243
commit 70a344a8f9

View File

@ -1,7 +1,9 @@
import argparse import argparse
import os
import platform import platform
import sys import sys
import sysconfig import sysconfig
import tempfile
import warnings import warnings
from pathlib import Path from pathlib import Path
from typing import Set from typing import Set
@ -146,7 +148,19 @@ class CurrentEnv(PythonRun):
) )
def create_python_env(self): 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): def env_bin_dir(self):
return Path(sysconfig.get_path("scripts")) return Path(sysconfig.get_path("scripts"))