9 |
9 |
10 This is the main Python script to manage Python Virtual Environments from |
10 This is the main Python script to manage Python Virtual Environments from |
11 outside of the IDE. |
11 outside of the IDE. |
12 """ |
12 """ |
13 |
13 |
|
14 import argparse |
14 import os |
15 import os |
15 import sys |
16 import sys |
16 |
17 |
17 from PyQt6.QtGui import QGuiApplication |
18 from PyQt6.QtGui import QGuiApplication |
18 |
19 |
19 for arg in sys.argv[:]: |
|
20 if arg.startswith("--config="): |
|
21 from eric7 import Globals |
|
22 |
20 |
23 configDir = arg.replace("--config=", "") |
21 def createArgparseNamespace(): |
24 Globals.setConfigDir(configDir) |
22 """ |
25 sys.argv.remove(arg) |
23 Function to create an argument parser. |
26 elif arg.startswith("--settings="): |
|
27 from PyQt6.QtCore import QSettings |
|
28 |
24 |
29 settingsDir = os.path.expanduser(arg.replace("--settings=", "")) |
25 @return created argument parser object |
30 if not os.path.isdir(settingsDir): |
26 @rtype argparse.ArgumentParser |
31 os.makedirs(settingsDir) |
27 """ |
32 QSettings.setPath( |
28 from eric7.UI.Info import Version |
33 QSettings.Format.IniFormat, QSettings.Scope.UserScope, settingsDir |
|
34 ) |
|
35 sys.argv.remove(arg) |
|
36 |
29 |
37 from eric7.Globals import AppInfo |
30 # 1. create the argument parser |
|
31 parser = argparse.ArgumentParser( |
|
32 description="Graphical tool of the eric tool suite to manage Python Virtual" |
|
33 " Environments.", |
|
34 epilog="Copyright (c) 2021 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>.", |
|
35 ) |
|
36 |
|
37 # 2. add the arguments |
|
38 parser.add_argument( |
|
39 "-V", |
|
40 "--version", |
|
41 action="version", |
|
42 version="%(prog)s {0}".format(Version), |
|
43 help="show version information and exit", |
|
44 ) |
|
45 parser.add_argument( |
|
46 "--config", |
|
47 metavar="config_dir", |
|
48 help="use the given directory as the one containing the config files", |
|
49 ) |
|
50 parser.add_argument( |
|
51 "--settings", |
|
52 metavar="settings_dir", |
|
53 help="use the given directory to store the settings files", |
|
54 ) |
|
55 |
|
56 # 3. create the Namespace object by parsing the command line |
|
57 args = parser.parse_args() |
|
58 return args |
|
59 |
|
60 |
|
61 args = createArgparseNamespace() |
|
62 if args.config: |
|
63 from eric7 import Globals |
|
64 |
|
65 Globals.setConfigDir(args.config) |
|
66 if args.settings: |
|
67 from PyQt6.QtCore import QSettings |
|
68 |
|
69 SettingsDir = os.path.expanduser(args.settings) |
|
70 if not os.path.isdir(SettingsDir): |
|
71 os.makedirs(SettingsDir) |
|
72 QSettings.setPath( |
|
73 QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir |
|
74 ) |
|
75 |
38 from eric7.Toolbox import Startup |
76 from eric7.Toolbox import Startup |
39 |
77 |
40 |
78 |
41 def createMainWidget(argv): # noqa: U100 |
79 def createMainWidget(args): # noqa: U100 |
42 """ |
80 """ |
43 Function to create the main widget. |
81 Function to create the main widget. |
44 |
82 |
45 @param argv list of commandline parameters |
83 @param args namespace object containing the parsed command line parameters |
46 @type list of str |
84 @type argparse.Namespace |
47 @return reference to the main widget |
85 @return reference to the main widget |
48 @rtype QWidget |
86 @rtype QWidget |
49 """ |
87 """ |
50 from eric7.VirtualEnv.VirtualenvManagerWidgets import VirtualenvManagerWindow |
88 from eric7.VirtualEnv.VirtualenvManagerWidgets import VirtualenvManagerWindow |
51 |
89 |
56 """ |
94 """ |
57 Main entry point into the application. |
95 Main entry point into the application. |
58 """ |
96 """ |
59 QGuiApplication.setDesktopFileName("eric7_virtualenv") |
97 QGuiApplication.setDesktopFileName("eric7_virtualenv") |
60 |
98 |
61 options = [ |
99 res = Startup.appStartup(args, createMainWidget) |
62 ( |
|
63 "--config=configDir", |
|
64 "use the given directory as the one containing the config files", |
|
65 ), |
|
66 ( |
|
67 "--settings=settingsDir", |
|
68 "use the given directory to store the settings files", |
|
69 ), |
|
70 ] |
|
71 appinfo = AppInfo.makeAppInfo( |
|
72 sys.argv, |
|
73 "eric Virtualenv Manager", |
|
74 "", |
|
75 "Utility to manage Python Virtual Environments.", |
|
76 options, |
|
77 ) |
|
78 res = Startup.simpleAppStartup(sys.argv, appinfo, createMainWidget) |
|
79 sys.exit(res) |
100 sys.exit(res) |
80 |
101 |
81 |
102 |
82 if __name__ == "__main__": |
103 if __name__ == "__main__": |
83 main() |
104 main() |