Wed, 25 Sep 2024 14:48:57 +0200
Moved some functions from 'Globals' to 'EricUtilities'.
10084 | 1 | #!/usr/bin/env python3 |
2 | # -*- coding: utf-8 -*- | |
3 | ||
10439
21c28b0f9e41
Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10303
diff
changeset
|
4 | # Copyright (c) 2023 - 2024 Detlev Offenbach <detlev@die-offenbachs.de> |
10084 | 5 | # |
6 | ||
7 | """ | |
8 | eric pip Packages Manager. | |
9 | ||
10 | This is the main Python script to manage Python packages with 'pip' from | |
11 | outside of the IDE. | |
12 | """ | |
13 | ||
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
14 | import argparse |
10084 | 15 | import os |
16 | import sys | |
17 | ||
18 | from PyQt6.QtGui import QGuiApplication | |
19 | ||
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
20 | |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
21 | def createArgparseNamespace(): |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
22 | """ |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
23 | Function to create an argument parser. |
10084 | 24 | |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
25 | @return created argument parser object |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
26 | @rtype argparse.ArgumentParser |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
27 | """ |
10716
11cdcc824469
Relocated the Version information into a top level '__version__.py' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10683
diff
changeset
|
28 | from eric7.__version__ import Version |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
29 | |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
30 | # 1. create the argument parser |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
31 | parser = argparse.ArgumentParser( |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
32 | description="Graphical tool of the eric tool suite to manage Python packages" |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
33 | " with 'pip'.", |
10439
21c28b0f9e41
Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10303
diff
changeset
|
34 | epilog="Copyright (c) 2023 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>.", |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
35 | ) |
10084 | 36 | |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
37 | # 2. add the arguments |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
38 | parser.add_argument( |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
39 | "-V", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
40 | "--version", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
41 | action="version", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
42 | version="%(prog)s {0}".format(Version), |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
43 | help="show version information and exit", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
44 | ) |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
45 | parser.add_argument( |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
46 | "--config", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
47 | metavar="config_dir", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
48 | help="use the given directory as the one containing the config files", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
49 | ) |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
50 | parser.add_argument( |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
51 | "--settings", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
52 | metavar="settings_dir", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
53 | help="use the given directory to store the settings files", |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
54 | ) |
10084 | 55 | |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
56 | # 3. create the Namespace object by parsing the command line |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
57 | args = parser.parse_args() |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
58 | return args |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
59 | |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
60 | |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
61 | args = createArgparseNamespace() |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
62 | if args.config: |
10926
9ef616cd220d
Moved some functions from 'Globals' to 'EricUtilities'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10716
diff
changeset
|
63 | from eric7 import EricUtilities |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
64 | |
10926
9ef616cd220d
Moved some functions from 'Globals' to 'EricUtilities'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10716
diff
changeset
|
65 | EricUtilities.setConfigDir(args.config) |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
66 | if args.settings: |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
67 | from PyQt6.QtCore import QSettings |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
68 | |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
69 | SettingsDir = os.path.expanduser(args.settings) |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
70 | if not os.path.isdir(SettingsDir): |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
71 | os.makedirs(SettingsDir) |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
72 | QSettings.setPath( |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
73 | QSettings.Format.IniFormat, QSettings.Scope.UserScope, SettingsDir |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
74 | ) |
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
75 | |
10084 | 76 | from eric7.Toolbox import Startup |
77 | ||
78 | ||
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
79 | def createMainWidget(_args): |
10084 | 80 | """ |
81 | Function to create the main widget. | |
82 | ||
10683
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
83 | @param _args namespace object containing the parsed command line parameters |
779cda568acb
Changed the source code and the source code documentation to improve the indication of unused method/function arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
84 | (unused) |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
85 | @type argparse.Namespace |
10084 | 86 | @return reference to the main widget |
87 | @rtype QWidget | |
88 | """ | |
89 | from eric7.PipInterface.PipPackagesWindow import PipPackagesWindow | |
90 | ||
91 | return PipPackagesWindow(None) | |
92 | ||
93 | ||
94 | def main(): | |
95 | """ | |
96 | Main entry point into the application. | |
97 | """ | |
10238
9ea4634a697e
Corrected the filename for 'QGuiApplication.setDesktopFileName()' to not include the '.desktop' extension anymore (as directed by Qt).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10084
diff
changeset
|
98 | QGuiApplication.setDesktopFileName("eric7_pip") |
10084 | 99 | |
10303
ee1aadab1215
Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10238
diff
changeset
|
100 | res = Startup.appStartup(args, createMainWidget) |
10084 | 101 | sys.exit(res) |
102 | ||
103 | ||
104 | if __name__ == "__main__": | |
105 | main() |