Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit cdeda03

Browse files
committed
2 parents 02327ae + edbfbe4 commit cdeda03

File tree

5 files changed

+47
-14
lines changed

5 files changed

+47
-14
lines changed

Content/Scripts/upycmd.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def NormalizePaths():
1515
#replace '/' to '\\'
1616
for i in range(len(sys.path)):
1717
currentPath = sys.path[i]
18-
sys.path[i] = currentPath.replace('/','\\')
18+
sys.path[i] = currentPath.replace('\\','/')
1919

2020
#find additional problem paths such as engine bin
2121
currentPath = sys.path[i]
@@ -30,32 +30,32 @@ def NormalizePaths():
3030
#define some convenience paths
3131
def PythonHomePath():
3232
for path in sys.path:
33-
normalizedPath = path.replace('/','\\')
33+
normalizedPath = AsAbsPath(path)
3434
if ('UnrealEnginePython' in normalizedPath and
35-
normalizedPath.endswith('Binaries\\Win64')):
35+
normalizedPath.endswith('Binaries/Win64')):
3636
return path
3737

3838
#return sys.path[1]
3939
return "not found"
4040

4141
def PythonHomeScriptsPath():
42-
return PythonHomePath() + "/Scripts"
42+
return AsAbsPath(PythonHomePath() + "/Scripts")
4343

4444
def PythonPluginScriptPath():
4545
for path in sys.path:
46-
normalizedPath = path.replace('/','\\')
46+
normalizedPath = AsAbsPath(path)
4747
if ('UnrealEnginePython' in normalizedPath and
48-
normalizedPath.endswith('Content\\Scripts')):
48+
normalizedPath.endswith('Content/Scripts')):
4949
return path
5050

5151
return "not found"
5252

5353
def PythonProjectScriptPath():
5454
relativePath = PythonPluginScriptPath() + "/../../../../Content/Scripts";
55-
return os.path.abspath(relativePath);
55+
return AsAbsPath(relativePath);
5656

5757
def AsAbsPath(path):
58-
return os.path.abspath(path)
58+
return os.path.abspath(path).replace('\\','/')
5959

6060
_PythonHomePath = PythonHomePath()
6161

Content/Scripts/upymodule_importer.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ def parseJson(packagePath):
3434
ue.log("upymodule_importer::" + module + " " + version + " installed? " + str(pip.isInstalled(module)))
3535
if not pip.isInstalled(module, version):
3636
ue.log('upymodule_importer::Dependency not installed, fetching via pip...')
37-
pip.install(module + '==' + version)
37+
if version == 'latest':
38+
pip.install(module)
39+
else:
40+
pip.install(module + '==' + version)
3841

3942
dependencyNoun = 'dependencies'
4043
if len(pythonModules) == 1:
@@ -45,3 +48,10 @@ def parseJson(packagePath):
4548
e = sys.exc_info()[0]
4649
ue.log('upymodule_importer::upymodule.json error: ' + str(e))
4750

51+
def containsModuleFile(packagePath):
52+
try:
53+
with open(packagePath) as data_file:
54+
return True
55+
except:
56+
return False
57+

Content/Scripts/upypip.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ def __init__(self):
1212
return None
1313

1414
#blocking actions, should be run on off-thread
15-
def pipModuleAction(self, command, args, verbose=True):
16-
return cmd.run('pip ' + command + ' ' + args, cmd.PythonHomeScriptsPath(), verbose)
15+
def pipModuleAction(self, command, args=None, verbose=True):
16+
if args:
17+
return cmd.run('pip ' + command + ' ' + args, cmd.PythonHomeScriptsPath(), verbose)
18+
else:
19+
return cmd.run('pip ' + command, cmd.PythonHomeScriptsPath(), verbose)
1720

1821
#use this if you need to work on the resulting list to query current dependencies
1922
def listDict(self, verbose=True):
@@ -37,6 +40,8 @@ def isDesiredVersionSufficient(self, desired, current):
3740
return LooseVersion(desired) <= LooseVersion(current)
3841

3942
def isInstalled(self, module, desiredVersion=None):
43+
if desiredVersion == 'latest':
44+
desiredVersion = None
4045
if PipInstall.modules == None:
4146
PipInstall.modules = self.listDict(False)
4247
if module in PipInstall.modules:
@@ -68,6 +73,11 @@ def list(self):
6873
t = Thread(target=action)
6974
t.start()
7075

76+
def action(self, command):
77+
action = self.pipModuleAction
78+
t = Thread(target=action, args=(command,))
79+
t.start()
80+
7181
def uninstallAll(self):
7282
PipInstall.modules = None #our cache is no longer valid
7383
action = self.pipModuleAction
@@ -83,4 +93,5 @@ def uninstallAll(self):
8393
uninstall = _inst.uninstall
8494
uninstallAll = _inst.uninstallAll
8595
pipModuleAction = _inst.pipModuleAction
86-
listDict = _inst.listDict
96+
listDict = _inst.listDict
97+
action = _inst.action

Content/Scripts/upystartup.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
from os import path as ospath
88
import imp
99
import site
10+
import upymodule_importer as upymod
1011

1112
import upypip as pip
1213

1314
def checkPipDirectory():
1415
#get our python scripts path
15-
configPath = cmd.PythonPluginScriptPath() + '/upyconfig.json'
16+
configPath = cmd.AsAbsPath(cmd.PythonPluginScriptPath() + '/upyconfig.json')
1617
correctPipPath = cmd.PythonHomeScriptsPath()
1718

1819
#check that we have a config file, if not make an empty one
@@ -89,7 +90,18 @@ def checkPipDirectory():
8990
print('upystartup::system paths normalized.')
9091
cmd.NormalizePaths();
9192

93+
def checkProjectModuleFile():
94+
path = cmd.PythonProjectScriptPath() + '/upymodule.json'
95+
if upymod.containsModuleFile(path):
96+
upymod.parseJson(path)
97+
print("upystartup::project upymodule.json file parsed.")
98+
else:
99+
print("upystartup::project doesn't use a upymodule.json file.")
100+
92101
#add any startup action you wish to perform in python
93102
def startup():
94103
#check that our pip directory matches for pip.exe commands
95104
checkPipDirectory()
105+
106+
#import any project specific modules
107+
checkProjectModuleFile()

UnrealEnginePython.uplugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"FileVersion": 3,
33
"Version": 1,
4-
"VersionName": "1.4.2",
4+
"VersionName": "1.4.3",
55
"FriendlyName": "UnrealEnginePython",
66
"Description": "Embed a Python VM in your project",
77
"Category": "Scripting Languages",

0 commit comments

Comments
 (0)