pyenv-virtualenv for Windows 1.2
A 'pyenv' plugin to manage Python virtual environments, depending on different Python versions, for various Python projects.
Loading...
Searching...
No Matches
pyenv-virtualenv-props Namespace Reference

Functions

int run (argparse.Namespace args)
 Sub routine to run the application.
 
tuple[(argparse.Namespace, None), int] parseCliArguments ()
 Parse CLI arguments for this application.
 
int main ()
 Main routine of the application.
 

Function Documentation

◆ run()

int pyenv-virtualenv-props.run ( argparse.Namespace args)

Sub routine to run the application.

Parameters
argsParsed command line arguments of this application.
Returns
RC = 0 or other values in case of error.

Definition at line 52 of file pyenv-virtualenv-props.py.

52def run(args: argparse.Namespace) -> int:
53 rc: int = 0
54 cwd = os.getcwd()
55 # noinspection PyBroadException
56 try:
57 while True:
58 if args.__contains__('select_set'):
59 log.verbose('Setting project properties ...')
60 rc = hlp.setProjectProperties(args.version, args.name)
61 if rc == 0:
62 log.verbose('Project properties successfully set.')
63 else:
64 log.error('Cannot set project properties.')
65 elif args.__contains__('select_unset'):
66 log.verbose('Unsetting project properties ...')
68 if rc == 0:
69 log.verbose('Project properties successfully unset.')
70 else:
71 log.error('Cannot unset project properties.')
72 elif args.__contains__('select_list'):
73 log.verbose('Showing list of project properties ...')
74 rc = hlp.listProjectProperties(show_tree=args.tree)
75 if rc == 0:
77 'Project properties list successfully shown.'
78 )
79 else:
80 log.error('Cannot show project properties.')
81 # End if
82 log.verbose('Done (RC = {}).'.format(rc))
83 # Go on
84 break
85 # End while
86 except:
87 log.error(sys.exc_info())
88 rc = 1
89 finally:
90 os.chdir(cwd)
91 return rc
92
93
94# --- MAIN --------------------------------------------------------------
95
int listProjectProperties(bool show_tree=False)
Display the table, which shows a list about project properties.
Definition hlp.py:868
int unsetProjectProperties()
Set project property files.
Definition hlp.py:831
int setProjectProperties(str ver, str env)
Set/override project property files.
Definition hlp.py:611
verbose((str, tuple) msg)
Log verbose message colored to console only.
Definition log.py:209
error((str, tuple) msg)
Log error message colored to console only.
Definition log.py:179

◆ parseCliArguments()

tuple[(argparse.Namespace, None), int] pyenv-virtualenv-props.parseCliArguments ( )

Parse CLI arguments for this application.



Implement this as required, but don't touch the interface definition for input and output.

Returns
A tuple of:
  • Namespace to read arguments in "dot" notation or None in case of help or error.
  • RC = 0 or another value in case of error.

Definition at line 105 of file pyenv-virtualenv-props.py.

105def parseCliArguments() -> tuple[(argparse.Namespace, None), int]:
106 rc: int = 0
107 # noinspection PyBroadException
108 try:
109 # Create main parser
110 parser = argparse.ArgumentParser(
111# --- BEGIN CHANGE -----------------------------------------------------
112 prog='pyenv virtualenv-props',
113 description='Manage virtual environment-related project ' +
114 'properties.'
115 )
116 # Create subparsers collection
117 subparsers = parser.add_subparsers(help='subcommand help')
118 # Add 1st subparser
119 parser_set = subparsers.add_parser(
120 'set',
121 aliases=['s'],
122 description='Set project properties inside CWD = project folder.'
123 )
124 # Add positional str argument to SET subparser
125 parser_set.add_argument(
126 'version',
127 help='Number of Python version, already installed in "pyenv".'
128 )
129 # Add positional str argument to SET subparser
130 parser_set.add_argument(
131 'name',
132 help='Short name of required Python virtual environment.'
133 )
134 # Add hidden flag
135 parser_set.add_argument(
136 'select_set',
137 action='store_true',
138 help=argparse.SUPPRESS # Don't show in --help
139 )
140 # Add 2nd subparser
141 parser_unset = subparsers.add_parser(
142 'unset',
143 aliases=['u', 'unset', 'unlink', 'd', 'del', 'delete', 'r', 'rm', 'remove'],
144 description='Unset project properties inside CWD = project folder.'
145 )
146 # Add hidden flag
147 parser_unset.add_argument(
148 'select_unset',
149 action='store_true',
150 help=argparse.SUPPRESS # Don't show in --help
151 )
152 # Add 3rd subparser
153 parser_list = subparsers.add_parser(
154 'list',
155 aliases=['l', 'ls'],
156 description='Read and list local project properties.',
157 help='Read and list local project properties.'
158 )
159 # Add flag
160 parser_list.add_argument(
161 'select_list',
162 action='store_true',
163 help=argparse.SUPPRESS # Don't show in --help
164 )
165 # Add flag
166 parser_list.add_argument(
167 '-t', '--tree',
168 dest='tree',
169 action=argparse.BooleanOptionalAction,
170 help='Display project properties in local folder tree view.'
171 )
172# --- END CHANGE -------------------------------------------------------
173 return parser.parse_args(), rc
174 except SystemExit:
175 return None, 0 # -h, --help
176 except:
177 log.error(sys.exc_info())
178 return None, 1
179

◆ main()

int pyenv-virtualenv-props.main ( )

Main routine of the application.

Returns
RC = 0 or other values in case of error.

Definition at line 183 of file pyenv-virtualenv-props.py.

183def main() -> int:
184 # noinspection PyBroadException
185 try:
186 while True:
187 # Audit the operating system platform
188 rc = hlp.auditPlatform('Windows')
189 if rc != 0:
190 # Deviation: Reject unsupported platform
191 break
192 # Audit the global Python version number
194 if rc != 0:
195 # Deviation: Reject unsupported Python version
196 break
197 # Initialize the colored logging to console
199 # Audit the "pyenv" version number
200 rc = hlp.auditPyEnv('3')
201 if rc != 0:
202 # Deviation: Reject unsupported "pyenv" version
203 break
204 # Parse arguments
205 log.verbose('Parsing arguments ...')
206 args, rc = parseCliArguments()
207 if rc != 0:
208 break
209 if args is None: # -h, --help
210 break
211 log.debug('Arguments: {}'.format(args))
212 # Run this application
213 log.verbose('Running application ...')
214 rc = run(args)
215 if rc != 0:
216 break
217 # Go on
218 break
219 # End while
220 except Exception as exc:
222 log.error(sys.exc_info())
223 else:
224 print(
225 '\x1b[91mERROR: Unexpected error "%s".\x1b[0m'
226 %
227 str(exc)
228 )
229 rc = 1
230 return rc
231
232
int auditPyEnv(str min_ver)
Check if "pyenv" version is greater or equal the given minimal version.
Definition hlp.py:213
int auditGlobalPythonVersion(str min_ver)
Check if Python version is greater or equal the given minimal version.
Definition hlp.py:148
int auditPlatform(str name)
Check if the program in running on the required platform.
Definition hlp.py:85
debug((str, tuple) msg)
Log debug message colored to console only.
Definition log.py:215
initLogging()
Initialize the logging.
Definition log.py:71
bool isInitialized()
Definition log.py:90