30 '\x1b[101mCRITICAL %s\x1b[0m'
32 'Cannot find package "%s".'
37 '\x1b[37mINFO %s\x1b[0m'
39 'Install it using "pip". Then try again.')
56def run(args: argparse.Namespace) -> int:
61 corrected: bool =
False
62 log.info(
'Checking operation environment.')
66 if not 'PYENV_ROOT' in os.environ:
67 log.error(
'Cannot find "PYENV_ROOT" in the environment variables.')
68 log.info(
'Possibly "pyenv" for Windows has been uninstalled or damaged.')
69 log.info(
'Possibly you need to install the newest versions of "pyenv" and "pyenv-virtualenv" for Windows.')
71 log.verbose(
'"PYENV_ROOT" environment variable exists.')
72 pyenv_root_dir = os.environ[
'PYENV_ROOT'].strip()
73 log.verbose(f
'Checking existence of directory "{pyenv_root_dir}" ...')
74 if not os.path.isdir(pyenv_root_dir):
75 log.error(f
'Cannot find directory "{pyenv_root_dir}".')
76 log.info(
'Possibly "pyenv" for Windows has been uninstalled or damaged.')
77 log.info(
'Possibly you need to install the newest versions of "pyenv" and "pyenv-virtualenv" for Windows.')
79 log.verbose(f
'Directory "{pyenv_root_dir}" exists.')
81 pve_path1 = os.path.join(
89 paths = os.environ[
'PATH'].split(
';')
90 pev_path1 = os.path.join(
94 pev_path2 = os.path.join(
100 for i
in range(len(paths)):
103 if not os.path.isdir(path):
104 log.warning(f
'Directory "{path}" in PATH is not available.')
105 log.info(f
'Please manually correct this deviation afterward, if necessary.')
106 if path == pve_path1:
108 pve_paths.append(path)
109 if path == pev_path1:
111 pev_paths.append(path)
112 if path == pev_path2:
114 pev_paths.append(path)
116 if len(pev_index) == 0:
117 log.error(
'Cannot recognize "pyenv" in PATH.')
118 log.info(
'Possibly "pyenv" for Windows has been uninstalled or damaged.')
119 log.info(
'Possibly you need to install the newest versions of "pyenv" and "pyenv-virtualenv" for Windows.')
121 if len(pve_paths) > 1:
125 for j
in reversed(range(len(pve_index[1:]))):
126 removal_index = pve_index[j]
127 path = paths.pop(removal_index)
128 log.warning(f
'Obsolete clone of path "{path}" found in PATH.')
129 log.info(f
'This entry has been automatically removed.')
132 for k
in range(len(pev_index)):
134 if index < removal_index:
139 pve_index = pve_index[0:1]
141 min_pev_index = min(pev_index)
142 if len(pve_paths) == 0:
148 '{};{}'.format(pve_path1, os.environ[
'PATH']),
158 log.error(f
'Cannot permanently prepend "{pve_path1}" to the PATH environment variable. (RC = {rc}.')
159 log.info(
'Open new console terminal as "Administrator", in which you want to try again.')
161 elif min_pev_index < pve_index[0]:
164 paths.pop(pve_index[0])
170 '{};{}'.format(pve_path1, os.environ[
'PATH']),
180 log.error(f
'Cannot permanently prepend "{pve_path1}" to the PATH environment variable. (RC = {rc}.')
181 log.info(
'Open new console terminal as "Administrator", in which you want to try again.')
187 log.success(f
'Operation environment checked and corrected.')
190 log.success(f
'"pyenv-virtualenv" should work as expected.')
215 parser = argparse.ArgumentParser(
217 prog=
'pyenv virtualenv-init',
218 description=
'Initialize the terminal shell to work on Python virtual environment in "pyenv".'
226 help=
'Command string to call a shell command or batch in the shell like you would prefer. Default: "%%COMSPEC%% /K" = Windows CMD.'
229 return parser.parse_args(), rc
275 except Exception
as exc:
280 '\x1b[91mERROR: Unexpected error "%s".\x1b[0m'
288if __name__ ==
"__main__":
int auditPyEnv(str min_ver)
Check if "pyenv" version is greater or equal the given minimal version.
int auditGlobalPythonVersion(str min_ver)
Check if Python version is greater or equal the given minimal version.
int auditPlatform(str name)
Check if the program in running on the required platform.
warning((str, tuple) msg)
Log warning message colored to console only.
verbose((str, tuple) msg)
Log verbose message colored to console only.
initLogging()
Initialize the logging.
success((str, tuple) msg)
Log success message colored to console only.
info((str, tuple) msg)
Log info message colored to console only.
error((str, tuple) msg)
Log error message colored to console only.
tuple[(argparse.Namespace, None), int] parseCliArguments()
Parse CLI arguments for this application.
int main()
Main routine of the application.
int run(argparse.Namespace args)
Sub routine to run the application.