PyXMake Developer Guide 1.0
PyXMake
Loading...
Searching...
No Matches
__setenv__.py
1# -*- coding: utf-8 -*-
2# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3# % Environment %
4# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5"""
6Set up environment for PyXMake when executing scripts directly from command line.
7
8@note: PyXMake environment file.
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.__setenv__
24# Initialize PyXMake environment for Python scripts executed directly from the command line.
25## @author
26# Marc Garbade
27## @date
28# 22.08.2020
29## @par Notes/Changes
30# - Added documentation // mg 22.08.2020
31
32import sys, os
33import subprocess
34
35__pyx_delimn = " "
36__pyx_args = __pyx_delimn.join(sys.argv[1:])
37__pyx_exepath = os.path.dirname(os.path.abspath(os.getenv("pyx_python_exe",sys.executable)))
38__pyx_pythonpath = os.pathsep.join([os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
39 os.path.join(__pyx_exepath,"DLLs"), os.path.join(__pyx_exepath,"lib"), __pyx_exepath,
40 os.path.join(__pyx_exepath,"Library","bin"), os.path.join(__pyx_exepath,"lib","site-packages"),
41 os.getenv("PYTHONPATH","")])
42
43# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44# % CONDA Environment %
45# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46if os.path.exists(os.path.join(sys.prefix,"conda-meta")):
47 os.environ["PATH"] = os.pathsep.join(list(dict.fromkeys(os.path.join(sys.prefix,x) for x in next(os.walk(sys.prefix))[1])) +
48 list(dict.fromkeys(os.getenv("PATH","").split(os.pathsep))))
49
50# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51# % VIRTUAL Environment %
52# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53# Verify that base libraries always take a higher precedence than user-defined 3rd party packages
54sys.path = [x for x in sorted(set(sys.path + __pyx_pythonpath.split(os.pathsep)), key=lambda x: 'site-packages' in x)]
55
56# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57# % PYTHONPATH %
58# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59# Set environment variable in the process.
60os.environ["PYTHONPATH"] = os.pathsep.join(sys.path)
61
62# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63# % Execute script %
64# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65if __name__ == '__main__':
66 p = subprocess.Popen(__pyx_delimn.join([os.getenv("pyx_python_exe",sys.executable),__pyx_args]).split())
67 _, _ = p.communicate()