Skip to content

Commit ffef365

Browse files
committed
run startup code
-this will allow us to use python script to check for e.g. pip folder mismatch/etc
1 parent a047be2 commit ffef365

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

‎Content/Scripts/upyconfig.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"pipDirectoryPath":""
3+
}

‎Content/Scripts/upystartup.py‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import sys
2+
import unreal_engine as ue
3+
import json
4+
import upycmd as cmd
5+
from os import listdir
6+
7+
from upypip import pip
8+
9+
def checkPipDirectory():
10+
#get our python scripts path
11+
configPath = cmd.PythonPluginScriptPath() + '/upyconfig.json'
12+
correctPipPath = cmd.PythonHomeScriptsPath()
13+
14+
#let's test our pip directory path
15+
try:
16+
with open(configPath) as data_file:
17+
configs = json.load(data_file)
18+
19+
#grab currently stored path
20+
storedPipPath = configs['pipDirectoryPath']
21+
22+
print(storedPipPath)
23+
print(tempPath)
24+
25+
#compare paths
26+
if (storedPipPath != correctPipPath):
27+
#if they don't match, remove the pip module and reinstall pip for this module
28+
29+
libPath = cmd.PythonHomePath() + '/Lib/site-packages'
30+
dirs = listdir(libPath)
31+
print(libPath)
32+
print(dirs)
33+
34+
tempPath = None
35+
for directory in dirs:
36+
if ('pip' in directory and
37+
directory.endswith('.dist-info')):
38+
tempPath = libPath + directory
39+
40+
print(tempPath)
41+
#rmdir Li
42+
except:
43+
e = sys.exc_info()[0]
44+
ue.log('upyconfig.json error: ' + str(e))
45+
46+
#add any startup action you wish to perform in python
47+
def startup():
48+
#check that our pip directory matches for pip.exe commands
49+
checkPipDirectory()

‎Source/UnrealEnginePython/Private/UnrealEnginePython.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ void FUnrealEnginePythonModule::StartupModule()
142142
//import upymodule_importer
143143
PyImport_ImportModule("upymodule_importer");
144144

145+
char const* startupCode =
146+
"import upystartup\n"
147+
"upystartup.startup()\n";
148+
PyRun_SimpleString(startupCode);
149+
145150
if (PyImport_ImportModule("ue_site")) {
146151
UE_LOG(LogPython, Log, TEXT("ue_site Python module successfully imported"));
147152
}

0 commit comments

Comments
 (0)