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(
'"Python {}" virtual environments "{}" not found.'.format(version, name))
80 log.info(
'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 [
93 tbl.DATA,
94 i + 1,
95 '\x1b[92m{}\x1b[0m'.format(version1),
96 '\x1b[91m{}\x1b[0m'.format(name1),
97 path1
98 ]
99 )
100 data.append([tbl.SEPARATOR])
101
102 plural=''
103 plural1 = 'this'
104 plural2 = 'has'
105 if len(envs) != 1:
106 plural = 's'
107 plural1 = 'these'
108 plural2 = 'have'
109
110 print('')
111 log.notice(
'Deleting {} Python virtual environment{} from "pyenv":'.format(len(envs), plural))
112 log.notice(
' * Version: \x1b[0m"\x1b[92m{}\x1b[0m"'.format(version))
113 log.notice(
' * Name: \x1b[0m"\x1b[91m{}\x1b[0m"'.format(name))
114
116 data=data,
117 headline='\x1b[91mSELECTED PYTHON VIRTUAL ENVIRONMENT{} TO DELETE:\x1b[0m'.format(plural.upper())
118 )
119 table.run()
120
121
122 s = input('\x1b[94mDo you really want to delete {} item{}?\x1b[0m [\x1b[91myes\x1b[0m/\x1b[92mNo\x1b[0m]: '.format(plural1, plural)).strip().lower()
123 if (s == '') or (not s.startswith('y')):
124 rc = 130
126 sys.exit(rc)
127
128 for env in envs:
129
131 for junction in junctions:
132 os.remove(junction)
133
134 shutil.rmtree(env)
135
137 'Matching "{}", {} virtual environment{} and its junction{} {} been deleted from "pyenv".'.format(
138 name,
139 len(envs),
140 plural,
141 plural,
142 plural2
143 )
144 )
145
146 break
147
148 except SystemExit:
149 pass
150 except:
152 rc = 1
153 finally:
154 os.chdir(cwd)
155 return rc
156
157
158
159
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.