scripts/install.py

branch
eric7
changeset 10300
60e8f2175b3b
parent 10264
f06151820839
child 10331
c1a2ff7e3575
equal deleted inserted replaced
10299:079e5caf6ca6 10300:60e8f2175b3b
7 7
8 """ 8 """
9 Installation script for the eric IDE and all eric related tools. 9 Installation script for the eric IDE and all eric related tools.
10 """ 10 """
11 11
12 import argparse
12 import compileall 13 import compileall
13 import contextlib 14 import contextlib
14 import datetime 15 import datetime
15 import fnmatch 16 import fnmatch
16 import getopt
17 import getpass 17 import getpass
18 import glob 18 import glob
19 import importlib 19 import importlib
20 import io 20 import io
21 import json 21 import json
30 import time 30 import time
31 31
32 from functools import partial 32 from functools import partial
33 33
34 # Define the globals. 34 # Define the globals.
35 progName = None
36 currDir = os.getcwd() 35 currDir = os.getcwd()
37 modDir = None 36 modDir = None
38 pyModDir = None 37 pyModDir = None
39 platBinDir = None 38 platBinDir = None
40 distDir = None 39 distDir = None
109 input("Press enter to continue...") # secok 108 input("Press enter to continue...") # secok
110 109
111 os.chdir(currDir) 110 os.chdir(currDir)
112 111
113 sys.exit(rcode) 112 sys.exit(rcode)
114
115
116 def usage(rcode=2):
117 """
118 Display a usage message and exit.
119
120 @param rcode the return code passed back to the calling process.
121 """
122 global progName, modDir, distDir, apisDir
123 global macAppBundleName, macAppBundlePath, macPythonExe
124
125 print()
126 print("Usage:")
127 if sys.platform == "darwin":
128 print(
129 " {0} [-chvxz] [-a dir] [-b dir] [-d dir] [-f file] [-i dir]"
130 " [-m name] [-n path] [-p python] [--help] [--no-apis]"
131 " [--no-info] [--with-tools] [--verbose] [--yes]".format(progName)
132 )
133 elif sys.platform.startswith(("win", "cygwin")):
134 print(
135 " {0} [-chvxz] [-a dir] [-b dir] [-d dir] [-f file]"
136 " [--clean-desktop] [--help] [--no-apis] [--no-info]"
137 " [--with-tools] [--verbose] [--yes]".format(progName)
138 )
139 else:
140 print(
141 " {0} [-chvxz] [-a dir] [-b dir] [-d dir] [-f file] [-i dir]"
142 " [--help] [--no-apis] [--no-info] [--with-tools] [--verbose]"
143 " [--yes]".format(progName)
144 )
145 print("where:")
146 print(" -h, --help display this help message")
147 print(" -a dir where the API files will be installed")
148 if apisDir:
149 print(" (default: {0})".format(apisDir))
150 else:
151 print(" (no default value)")
152 print(" --no-apis don't install API files")
153 print(" -b dir where the binaries will be installed")
154 print(" (default: {0})".format(platBinDir))
155 print(" -d dir where eric python files will be installed")
156 print(" (default: {0})".format(modDir))
157 print(" -f file configuration file naming the various installation paths")
158 if not sys.platform.startswith(("win", "cygwin")):
159 print(" -i dir temporary install prefix")
160 print(" (default: {0})".format(distDir))
161 if sys.platform == "darwin":
162 print(" -m name name of the Mac app bundle")
163 print(" (default: {0})".format(macAppBundleName))
164 print(" -n path path of the directory the Mac app bundle will")
165 print(" be created in")
166 print(" (default: {0})".format(macAppBundlePath))
167 print(" -p python path of the python executable")
168 print(" (default: {0})".format(macPythonExe))
169 print(" -c don't cleanup old installation first")
170 print(" -v, --verbose print some more information")
171 print(" -x don't perform dependency checks (use on your own risk)")
172 print(" -z don't compile the installed python files")
173 print(" --yes answer 'yes' to all questions")
174 print()
175 if sys.platform.startswith(("win", "cygwin")):
176 print(" --clean-desktop delete desktop links before installation")
177 print(" --no-info don't create the install info file")
178 print(" --with-tools install qt6-applications")
179 print()
180 print("The file given to the -f option must be valid Python code defining a")
181 print(
182 "dictionary called 'cfg' with the keys 'ericDir', 'ericPixDir',"
183 " 'ericIconDir',"
184 )
185 print("'ericDTDDir', 'ericCSSDir', 'ericStylesDir', 'ericThemesDir',")
186 print(" 'ericDocDir', ericExamplesDir',")
187 print("'ericTranslationsDir', 'ericTemplatesDir', 'ericCodeTemplatesDir',")
188 print("'ericOthersDir','bindir', 'mdir' and 'apidir.")
189 print(
190 "These define the directories for the installation of the various"
191 " parts of eric."
192 )
193
194 exit(rcode)
195 113
196 114
197 def initGlobals(): 115 def initGlobals():
198 """ 116 """
199 Module function to set the values of globals that need more than a 117 Module function to set the values of globals that need more than a
675 try: 593 try:
676 macAppBundlePath = getConfig("macAppBundlePath") 594 macAppBundlePath = getConfig("macAppBundlePath")
677 macAppBundleName = getConfig("macAppBundleName") 595 macAppBundleName = getConfig("macAppBundleName")
678 except AttributeError: 596 except AttributeError:
679 macAppBundlePath = ( 597 macAppBundlePath = (
680 defaultMacAppBundlePath 598 defaultMacAppBundlePath if os.getpid() == 0 else defaultMacUserAppBundlePath
681 if os.getpid() == 0
682 else defaultMacUserAppBundlePath
683 ) 599 )
684 macAppBundleName = defaultMacAppBundleName 600 macAppBundleName = defaultMacAppBundleName
685 for bundlePath in [ 601 for bundlePath in [
686 os.path.join(defaultMacAppBundlePath, macAppBundleName), 602 os.path.join(defaultMacAppBundlePath, macAppBundleName),
687 os.path.join(defaultMacUserAppBundlePath, macAppBundleName), 603 os.path.join(defaultMacUserAppBundlePath, macAppBundleName),
2180 """ 2096 """
2181 majorVersion, minorVersion = sys.version_info[:2] 2097 majorVersion, minorVersion = sys.version_info[:2]
2182 return "eric7 (Python {0}.{1})".format(majorVersion, minorVersion) 2098 return "eric7 (Python {0}.{1})".format(majorVersion, minorVersion)
2183 2099
2184 2100
2101 def createArgumentParser():
2102 """
2103 Function to create an argument parser.
2104
2105 @return created argument parser object
2106 @rtype argparse.ArgumentParser
2107 """
2108 parser = argparse.ArgumentParser(
2109 description="Install eric7 from the source code tree.",
2110 epilog="The file given to the -f option must be valid Python code defining a"
2111 "dictionary called 'cfg' with the keys 'ericDir', 'ericPixDir', ericIconDir',"
2112 " 'ericDTDDir', 'ericCSSDir', 'ericStylesDir', 'ericThemesDir', ericDocDir',"
2113 " ericExamplesDir', ericTranslationsDir', 'ericTemplatesDir',"
2114 " 'ericCodeTemplatesDir', ericOthersDir','bindir', 'mdir' and 'apidir."
2115 "These define the directories for the installation of the various parts of"
2116 " eric.",
2117 )
2118
2119 parser.add_argument(
2120 "-a",
2121 metavar="dir",
2122 default=apisDir if apisDir else None,
2123 help="directory where the API files will be installed ({0})".format(
2124 "default: {0}".format(apisDir) if apisDir else "no default value"
2125 ),
2126 )
2127 parser.add_argument(
2128 "--no-apis",
2129 action="store_true",
2130 help="don't install API files",
2131 )
2132 parser.add_argument(
2133 "-b",
2134 metavar="dir",
2135 default=platBinDir,
2136 help="directory where the binaries will be installed (default: {0})".format(
2137 platBinDir
2138 ),
2139 )
2140 parser.add_argument(
2141 "-d",
2142 metavar="dir",
2143 default=modDir,
2144 help="directory where eric Python files will be installed"
2145 " (default: {0})".format(modDir),
2146 )
2147 parser.add_argument(
2148 "-f",
2149 metavar="file",
2150 help="configuration file naming the various installation paths",
2151 )
2152 if not sys.platform.startswith(("win", "cygwin")):
2153 parser.add_argument(
2154 "-i",
2155 metavar="dir",
2156 default=distDir,
2157 help="temporary install prefix (default: {0})".format(distDir),
2158 )
2159 if sys.platform == "darwin":
2160 parser.add_argument(
2161 "-m",
2162 metavar="name",
2163 default=macAppBundleName,
2164 help="name of the Mac app bundle (default: {0})".format(macAppBundleName),
2165 )
2166 parser.add_argument(
2167 "-n",
2168 metavar="path",
2169 default=macAppBundlePath,
2170 help="path of the directory the Mac app bundle will be created in"
2171 " (default: {0})".format(macAppBundlePath),
2172 )
2173 parser.add_argument(
2174 "-p",
2175 metavar="python",
2176 default=macPythonExe,
2177 help="path of the python executable (default: {0})".format(macPythonExe),
2178 )
2179 parser.add_argument(
2180 "-c",
2181 action="store_false",
2182 help="don't cleanup old installation first",
2183 )
2184 parser.add_argument(
2185 "-v",
2186 "--verbose",
2187 action="store_true",
2188 help="print some more information",
2189 )
2190 parser.add_argument(
2191 "-x",
2192 action="store_false",
2193 help="don't perform dependency checks (use on your own risk)",
2194 )
2195 parser.add_argument(
2196 "-z",
2197 action="store_false",
2198 help="don't compile the installed python files",
2199 )
2200 parser.add_argument(
2201 "--yes",
2202 action="store_true",
2203 help="answer 'yes' to all questions",
2204 )
2205 if sys.platform.startswith(("win", "cygwin")):
2206 parser.add_argument(
2207 "--clean-desktop",
2208 action="store_true",
2209 help="delete desktop links before installation",
2210 )
2211 parser.add_argument(
2212 "--no-info",
2213 action="store_true",
2214 help="don't create the install info file",
2215 )
2216 parser.add_argument(
2217 "--with-tools",
2218 action="store_true",
2219 help="install the 'qt6-applications' package",
2220 )
2221
2222 return parser
2223
2224
2185 def main(argv): 2225 def main(argv):
2186 """ 2226 """
2187 The main function of the script. 2227 The main function of the script.
2188 2228
2189 @param argv list of command line arguments 2229 @param argv list of command line arguments
2190 @type list of str 2230 @type list of str
2191 """ 2231 """
2192 # Parse the command line. 2232 global modDir, doCleanup, doCompile, distDir, cfg, apisDir
2193 global progName, modDir, doCleanup, doCompile, distDir, cfg, apisDir 2233 global sourceDir, eric7SourceDir, configName, platBinDir
2194 global sourceDir, eric7SourceDir, configName
2195 global macAppBundlePath, macAppBundleName, macPythonExe 2234 global macAppBundlePath, macAppBundleName, macPythonExe
2196 global installApis, doCleanDesktopLinks, yes2All 2235 global installApis, doCleanDesktopLinks, yes2All
2197 global createInstallInfoFile, installCwd 2236 global createInstallInfoFile, installCwd
2198 global withPyqt6Tools 2237 global withPyqt6Tools
2199 global verbose 2238 global verbose
2200 2239
2201 if sys.version_info < (3, 8, 0) or sys.version_info > (3, 99, 99): 2240 if sys.version_info < (3, 8, 0) or sys.version_info > (3, 99, 99):
2202 print("Sorry, eric requires at least Python 3.8 for running.") 2241 print("Sorry, eric requires at least Python 3.8 for running.")
2203 exit(5) 2242 exit(5)
2204 2243
2205 progName = os.path.basename(argv[0])
2206
2207 installCwd = os.getcwd() 2244 installCwd = os.getcwd()
2208 2245
2209 if os.path.dirname(argv[0]): 2246 if os.path.dirname(argv[0]):
2210 os.chdir(os.path.dirname(argv[0])) 2247 os.chdir(os.path.dirname(argv[0]))
2211 2248
2212 initGlobals() 2249 initGlobals()
2213 2250
2214 try: 2251 parser = createArgumentParser()
2215 if sys.platform.startswith(("win", "cygwin")): 2252 args = parser.parse_args()
2216 optlist, args = getopt.getopt( 2253
2217 argv[1:], 2254 apisDir = args.a
2218 "chvxza:b:d:f:", 2255 platBinDir = args.b
2219 [ 2256 modDir = args.d
2220 "clean-desktop", 2257 depChecks = args.x
2221 "help", 2258 doCleanup = args.c
2222 "no-apis", 2259 doCompile = args.z
2223 "no-info", 2260 installApis = not args.no_apis
2224 "verbose", 2261 yes2All = args.yes
2225 "with-tools", 2262 withPyqt6Tools = args.with_tools
2226 "yes", 2263 createInstallInfoFile = not args.no_info
2227 ], 2264 verbose = args.verbose
2228 ) 2265 if sys.platform == "darwin":
2229 elif sys.platform == "darwin": 2266 macAppBundleName = args.m
2230 optlist, args = getopt.getopt( 2267 macAppBundlePath = args.n
2231 argv[1:], 2268 macPythonExe = args.p
2232 "chvxza:b:d:f:i:m:n:p:", 2269 if sys.platform.startswith(("win", "cygwin")):
2233 ["help", "no-apis", "no-info", "with-tools", "verbose", "yes"], 2270 doCleanDesktopLinks = args.clean_desktop
2234 ) 2271 else:
2235 else: 2272 if args.i:
2236 optlist, args = getopt.getopt( 2273 distDir = os.path.normpath(args.i)
2237 argv[1:], 2274 if args.f:
2238 "chvxza:b:d:f:i:", 2275 with open(args.f) as f:
2239 ["help", "no-apis", "no-info", "with-tools", "verbose", "yes"], 2276 try:
2240 ) 2277 exec(compile(f.read(), args.f, "exec"), globals())
2241 except getopt.GetoptError as err: 2278 # secok
2242 print(err) 2279 if len(cfg) != configLength:
2243 usage()
2244
2245 global platBinDir
2246
2247 depChecks = True
2248
2249 for opt, arg in optlist:
2250 if opt in ["-h", "--help"]:
2251 usage(0)
2252 elif opt == "-a":
2253 apisDir = arg
2254 elif opt == "-b":
2255 platBinDir = arg
2256 elif opt == "-d":
2257 modDir = arg
2258 elif opt == "-i":
2259 distDir = os.path.normpath(arg)
2260 elif opt == "-x":
2261 depChecks = False
2262 elif opt == "-c":
2263 doCleanup = False
2264 elif opt == "-z":
2265 doCompile = False
2266 elif opt == "-f":
2267 with open(arg) as f:
2268 try:
2269 exec(compile(f.read(), arg, "exec"), globals())
2270 # secok
2271 if len(cfg) != configLength:
2272 print(
2273 "The configuration dictionary in '{0}' is"
2274 " incorrect. Aborting".format(arg)
2275 )
2276 exit(6)
2277 except Exception as exc:
2278 print( 2280 print(
2279 "The configuration file '{0}' is not valid Python source." 2281 "The configuration dictionary in '{0}' is"
2280 " It will be ignored. Installation will be performed with" 2282 " incorrect. Aborting".format(args.f)
2281 " defaults.".format(arg)
2282 ) 2283 )
2283 print("ERROR: {0}".format(str(exc))) 2284 exit(6)
2284 cfg = {} 2285 except Exception as exc:
2285 elif opt == "-m" and sys.platform == "darwin": 2286 print(
2286 macAppBundleName = arg 2287 "The configuration file '{0}' is not valid Python source."
2287 elif opt == "-n" and sys.platform == "darwin": 2288 " It will be ignored. Installation will be performed with"
2288 macAppBundlePath = arg 2289 " defaults.".format(args.f)
2289 elif opt == "-p" and sys.platform == "darwin": 2290 )
2290 macPythonExe = arg 2291 print("ERROR: {0}".format(str(exc)))
2291 elif opt == "--no-apis": 2292 cfg = {}
2292 installApis = False
2293 elif opt == "--clean-desktop":
2294 doCleanDesktopLinks = True
2295 elif opt == "--yes":
2296 yes2All = True
2297 elif opt == "--with-tools":
2298 withPyqt6Tools = True
2299 elif opt == "--no-info":
2300 createInstallInfoFile = False
2301 elif opt in ["-v", "--verbose"]:
2302 verbose = True
2303 2293
2304 infoName = "" 2294 infoName = ""
2305 installFromSource = not os.path.isdir(sourceDir) 2295 installFromSource = not os.path.isdir(sourceDir)
2306 2296
2307 # check dependencies 2297 # check dependencies

eric ide

mercurial