Sub routine to run the application.
53def run(args: argparse.Namespace) -> int:
54 rc: int = 0
55 cwd = os.getcwd()
56
57 try:
58 while True:
59
60 version: str = args.version.strip()
61 name: str = args.name.strip()
62
64 version,
65 venv_capable=True,
66 as_paths=True
67 )
68 envs = []
69 for ver in vers:
71 ver,
72 name=name,
73 as_paths=True
74 )
75 for env in ver_envs:
76 envs.append(env)
77
78 if len(envs) == 0:
79 log.warning(f
'"Python {version}" virtual environments "{name}" not found.')
80 log.info(f
'Call "pyenv virtualenvs". Then try "pyenv virtualenvs-delete" again, giving correct arguments.')
81 rc = 0
82 break
83
84 data = [
85 [tbl.HEADER, 'Item', 'Version', 'Name', 'Path'],
86 [tbl.SEPARATOR]
87 ]
88 for i in range(len(envs)):
89 env = envs[i]
91 data.append(
92 [tbl.DATA, i + 1, f'\x1b[92m{version1}\x1b[0m', f'\x1b[91m{name1}\x1b[0m', path1]
93 )
94 data.append([tbl.SEPARATOR])
95
96 plural=''
97 plural1 = 'this'
98 plural2 = 'has'
99 if len(envs) != 1:
100 plural = 's'
101 plural1 = 'these'
102 plural2 = 'have'
103
104 print('')
105 log.notice(f
'Deleting {len(envs)} Python virtual environment{plural} from "pyenv":')
106 log.notice(f
' * Version: \x1b[0m"\x1b[92m{version}\x1b[0m"')
107 log.notice(f
' * Name: \x1b[0m"\x1b[91m{name}\x1b[0m"')
108
110 data=data,
111 headline=f'\x1b[91mSELECTED PYTHON VIRTUAL ENVIRONMENT{plural.upper()} TO DELETE:\x1b[0m'
112 )
113 table.run()
114
115
116 s = input(f'\x1b[94mDo you really want to delete {plural1} item{plural}?\x1b[0m [\x1b[91myes\x1b[0m/\x1b[92mNo\x1b[0m]: ').strip().lower()
117 if (s == '') or (not s.startswith('y')):
118 rc = 130
120 sys.exit(rc)
121
122 for env in envs:
123
125 for junction in junctions:
126 os.remove(junction)
127
128 shutil.rmtree(env)
129
131 f'Matching "{name}", {len(envs)} virtual environment{plural} and its junction{plural} {plural2} been deleted from "pyenv".'
132 )
133
134 break
135
136 except SystemExit:
137 pass
138 except:
140 rc = 1
141 finally:
142 os.chdir(cwd)
143 return rc
144
145
146
147
tuple[str, str, str] parseEnvDir(str env_dir)
Parse virtual environment directory path.
list[str] getEnvs(str ver, str name=' *', bool as_paths=False)
Get list of installed virtual environments for a specific Python version in "pyenv".
list[str] getEnvJunctions(str path)
Scan the Pythons versions in "pyenv" for junctions, which points to a specific virtual environment di...
list[str] getPythonVersions(str version=' *', bool venv_capable=False, bool as_paths=False)
Get list of installed Python version directories in "pyenv".
warning((str, tuple) msg)
Log warning message colored to console only.
notice((str, tuple) msg)
Log notice message colored to console only.
verbose((str, tuple) msg)
Log verbose message colored to console only.
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.