PyXMake Developer Guide 1.0
PyXMake
Loading...
Searching...
No Matches
__install__.py
1# -*- coding: utf-8 -*-
2# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3# % Installation %
4# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5"""
6Development code installation procedure for PyXMake.
7
8@note: PyXMake installation file for development code.
9Created on 22.08.2020
10
11@version: 1.0
12----------------------------------------------------------------------------------------------
13@requires:
14 -
15
16@change:
17 -
18
19@author: garb_ma [DLR-FA,STM Braunschweig]
20----------------------------------------------------------------------------------------------
21"""
22
23## @package PyXMake.__install__
24# Development code installation procedure for PyXMake.
25## @author
26# Marc Garbade
27## @date
28# 22.08.2020
29## @par Notes/Changes
30# - Added documentation // mg 22.08.2020
31
32import os,sys
33import six
34import urllib.request
35import pkg_resources
36import subprocess
37
38__pyx_delimn = " "
39
40def main(): # pragma: no cover
41 # Add directory of current path to system path
42 sys.path.insert(0,os.path.dirname(os.path.abspath(__file__)))
43 # Update PYTHONPATH
44 import __setenv__ #@UnresolvedImport @UnusedImport
45
46 # Identify current dependencies
47 try:
48 from PyXMake.Tools.Utility import GetRequirements
49 data = GetRequirements(os.path.dirname(os.path.abspath(__file__)),["--ignore","cmd,bin","--no-pin"])
50 # URL to latest dependencies.
51 except ImportError:
52 target_url="https://fa-jenkins2:8080/job/STM_Archive/doclinks/1/"
53 data = urllib.request.urlopen(target_url).read().decode('utf-8').replace("\n","").split()
54 finally:
55 # Empty list to store missing dependencies
56 update = []
57 # Fetch updated dependencies from STM archive
58 installed = {pkg.key for pkg in pkg_resources.working_set}
59 required = {x.lower() for x in data}; modules = [x for x in data]
60 missing = required - installed
61
62 # Loop over all identified modules. Try to import all modules which could not been resolved.
63 for x in modules:
64 # Module names are case-sensitive
65 if x.lower() not in missing:
66 continue
67 try:
68 x = __import__(x)
69 except ImportError:
70 # Missing dependency. Add module name to list
71 update.append(x)
72
73 if update:
74 # Unresolved dependencies were found
75 print("==================================")
76 print("Found unresolved dependencies:")
77 print(*update, sep = "\n")
78 print("==================================")
79 print("Starting auto-installation process. Defaults to pip!")
80 print("Continue: [Y/N]; [pip/conda]")
81 # Wait for user input.
82 user_input = [x.strip() for x in six.moves.input().lower().split(";")] #@UndefinedVariable
83 # Check validity of user input.
84 if not user_input or user_input[0] != "y":
85 # Wrong input or rejection.
86 print("Abort installation process")
87 sys.exit()
88 else:
89 try:
90 package_manager = user_input[1]
91 except:
92 package_manager = "pip"
93 # Check if the package manager is correct.
94 if package_manager not in ["pip","conda"]:
95 print("Unknown package manager. Use either pip or conda.")
96 sys.exit()
97 else:
98 print("Attempting installation using %s" % package_manager)
99 try:
100 # Try to install all missing dependencies using the defined package manager
101 subprocess.check_call([os.getenv("pyx_python_exe",sys.executable), '-m', 'pip', 'install', *update], stdout=subprocess.DEVNULL)
102 except subprocess.CalledProcessError:
103 print("Installation aborted. Some packages cannot be installed using default settings")
104
105# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106# % Execute script %
107# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108if __name__ == '__main__' and __debug__: # pragma: no cover
109 main(); sys.exit()
Module of basic functions.
Definition Utility.py:1