31 '\x1b[101mCRITICAL %s\x1b[0m'
33 'Cannot find package "%s".'
38 '\x1b[37mINFO %s\x1b[0m'
40 'Install it using "pip". Then try again.')
53def run(args: argparse.Namespace) -> int:
62 version: str = args.version
64 except AttributeError:
68 log.error(
'Cannot determine the version number of the "pyenv" Python version.')
69 log.info(
'Trying next, set the version number explicitly. See --help.')
73 version = version.strip()
75 props: bool = args.props
77 log.info(
'Creating Python virtual environment in "pyenv":')
78 log.info(f
' * Version: {version} ({realm})')
80 log.info(f
' * Set project properties: {props}')
89 selected_version = os.path.basename(selected_version_dir)
91 envs_dir = os.path.join(selected_version_dir,
'envs')
92 if not os.path.isdir(envs_dir):
96 venv_dir = os.path.join(envs_dir, name)
97 if os.path.isdir(venv_dir):
100 shutil.rmtree(venv_dir)
104 python_exe_path = os.path.join(
105 selected_version_dir,
116 log.info(
'This will take some seconds ...')
120 stdout=subprocess.DEVNULL,
121 stderr=subprocess.DEVNULL,
127 'Unexpectedly cannot create ' +
128 'Python virtual environment.'
130 log.info(
'Check/repair Python and "pyenv". Then try again.')
135 venv_version_dir = os.path.join(
136 os.environ[
'PYENV_ROOT'],
138 f
'{name}-{selected_version}'
143 'Overriding junction "{}" ...'.format(
147 os.remove(venv_version_dir)
150 'Creating junction "{}" ...'.format(
164 stdout=subprocess.DEVNULL,
165 stderr=subprocess.DEVNULL,
171 'Unexpectedly cannot create junction to ' +
172 'Python virtual environment directory.'
175 'Check/repair security properties ' +
176 'of the junction. Then try again.'
184 log.verbose(
'Project properties successfully set.')
186 log.error(
'Cannot set project properties.')
189 f
'Virtual environment "{name}" is installed ' +
190 f
'in "pyenv", depending on "Python {selected_version}".'
218 parser = argparse.ArgumentParser(
220 prog=
'pyenv virtualenv',
221 description=
'Create a version-assigned and named ' +
222 'Python virtual environment in "pyenv".'
228 action=argparse.BooleanOptionalAction,
229 help=
'As project properties, add the files ' +
230 '`.python-version` and `.python-env` to CWD. Default: --no_props.'
235 help=
'Short name of the new Python virtual environment.'
238 return parser.parse_args(), rc
258 parser = argparse.ArgumentParser(
260 prog=
'pyenv virtualenv',
261 description=
'Create a version-assigned and named ' +
262 'Python virtual environment in "pyenv".'
268 action=argparse.BooleanOptionalAction,
269 help=
'As project properties, add the files ' +
270 '`.python-version` and `.python-env` to CWD. Default: --no_props.'
275 help=
'Python version, which must be already installed ' +
281 help=
'Short name of the new Python virtual environment.'
284 return parser.parse_args(), rc
298 os.environ[
'PYENV_ROOT'],
302 'open_doxygen_docs.bat'
311 log.error(f
'Displaying Doxygen documentation failed (RC = {rc}.')
312 log.info(
'Check/reinstall "pyenv-virtualenv". Then try again. ')
326 file_path = os.path.join(
327 os.environ[
'PYENV_ROOT'],
332 if not os.path.isfile(file_path):
333 log.error(
'Cannot display version number.')
334 log.info(f
'Reinstall the missing file "{file_path}".')
337 with open(file_path,
'r')
as f:
338 version = f.read().strip()
340 print(f
'"\x1b[92mpyenv-virtualenv\x1b[0m" for Windows \x1b[96m{version}\x1b[0m (\x1b[93mpython -m venv\x1b[0m).')
378 args_list = sys.argv.copy()
383 help_requested =
False
384 version_requested =
False
385 docs_requested =
False
386 for i
in reversed(range(len(args_list))):
388 if arg
in [
'-h',
'--help']:
389 help_requested =
True
391 elif arg
in [
'-v',
'--version']:
392 version_requested =
True
394 elif arg
in [
'-d',
'--docs']:
395 docs_requested =
True
398 positional_count = len(args_list)
402 elif version_requested:
408 (positional_count
not in [1, 2])
411Usage: pyenv virtualenv [-h] [-v] [-p | --props | --no-props ] [version] [name]
413Create a version-assigned and named Python virtual environment in "pyenv".
415Positional arguments (which can be omitted):
416 [version] Python version, which must be already installed in
417 "pyenv". Default: The global Python version.
418 [name] Short name of the new Python virtual environment.
421 -h, --help Show this help message and exit.
422 -p, --props, --no-props
423 Add the files `.python-version` and `.python-env`
424 as project properties to CWD. Default: --no_props.
425 -v, --version Display the version number of this "pyenv-virtualenv"
426 release and ignore all other arguments.
429 elif positional_count == 1:
432 elif positional_count == 2:
447 except Exception
as exc:
452 '\x1b[91mERROR: Unexpected error "%s".\x1b[0m'
460if __name__ ==
"__main__":
tuple[(str, None), int] selectVersionDir(str ver, str realm, venv_capable=False)
Find the best version, matching the requirements.
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.
str fName(str natural_name)
Convert a natural name into stripped functional name, without spaces, which is lowercase,...
int auditPlatform(str name)
Check if the program in running on the required platform.
(str, str) getPythonVersion()
Get selected global/local Python version in "pyenv".
bool isJunction(str path)
Check if path is a junction, which has been created e.g.
int setProjectProperties(str ver, str env)
Set/override project property files.
notice((str, tuple) msg)
Log notice 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] parseCliArguments2()
Parse CLI arguments for this application.
tuple[(argparse.Namespace, None), int] parseCliArguments1()
Parse CLI arguments for this application.
int displayVersionNumber()
Display the version number and generating procedure for "pyenv-virtualenv" for Windows.
int displayDocumentation()
Display the version number and generating procedure for "pyenv-virtualenv" for Windows.
int main()
Main routine of the application.
int run(argparse.Namespace args)
Sub routine to run the application.