Skip to content

Commit c2498d1

Browse files
authored
Merge pull request #3 from GPLgithub/master
Multi-platform support and publish2 Maya hooks
2 parents 4a284ee + e8608d7 commit c2498d1

File tree

1,617 files changed

+4423
-142602
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,617 files changed

+4423
-142602
lines changed

.gitignore

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
5+
# C extensions
6+
*.so
7+
8+
# Distribution / packaging
9+
.Python
10+
build/
11+
develop-eggs/
12+
dist/
13+
eggs/
14+
parts/
15+
sdist/
16+
*.egg-info/
17+
.installed.cfg
18+
*.egg
19+
*.dist-info
20+
21+
# Installer logs
22+
pip-log.txt
23+
pip-delete-this-directory.txt
24+
25+
# Unit test / coverage reports
26+
htmlcov/
27+
.tox/
28+
.coverage
29+
.cache
30+
nosetests.xml
31+
coverage.xml
32+
test
33+
34+
# Translations
35+
*.mo
36+
37+
# Mr Developer
38+
.mr.developer.cfg
39+
.project
40+
.pydevproject
41+
42+
# Editors
43+
.idea
44+
.vscode
45+
46+
# Rope
47+
.ropeproject
48+
49+
# Django stuff:
50+
*.log
51+
*.pot
52+
53+
# Sphinx documentation
54+
docs/_build/
55+
56+
# Mac stuff
57+
.DS_Store
58+
59+
# Package building
60+
packagevenv*
61+
python/vendors

azure-pipelines.yml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# We want builds to trigger for 3 reasons:
2+
# - The master branch sees new commits
3+
# - Each PR should get rebuilt when commits are added to it.
4+
# - When we tag something
5+
trigger:
6+
branches:
7+
include:
8+
- master
9+
tags:
10+
include:
11+
# Tags must start with "v"
12+
- v*
13+
pr:
14+
branches:
15+
include:
16+
- "*"
17+
18+
# The github_ci_token variable is defined in the Azure Pipeline web page as a
19+
# secret variable and is a github personal token.
20+
21+
jobs:
22+
23+
- job: 'Build'
24+
strategy:
25+
matrix:
26+
# Define all the platform/python version we need
27+
MacPython37:
28+
platform: 'osx' # Short name for us
29+
imageName: 'macOS-10.15'
30+
python.version: '3.7'
31+
WinPython37:
32+
platform: 'win' # Short name for us
33+
imageName: 'windows-2019'
34+
python.version: '3.7'
35+
LinuxPython37:
36+
platform: 'linux' # Short name for us
37+
imageName: 'ubuntu-latest'
38+
python.version: '3.7'
39+
maxParallel: 1
40+
41+
pool:
42+
# Retrieve the value set by the strategy above
43+
vmImage: $(imageName)
44+
45+
steps:
46+
- task: UsePythonVersion@0
47+
inputs:
48+
versionSpec: '$(python.version)'
49+
architecture: 'x64'
50+
51+
- script: |
52+
python -m pip install --upgrade pip
53+
displayName: 'Install dependencies'
54+
55+
# Not needed for Python 3, virtual env are built with python3 -m venv
56+
- script: |
57+
pip install virtualenv
58+
condition: eq( variables['python.version'], '2.7' )
59+
displayName: 'Install virtualenv'
60+
61+
# Couldn't get the script to be found using a bash task.
62+
- script: |
63+
./build_packages.sh -b
64+
workingDirectory: "resources"
65+
displayName: 'Build'
66+
env:
67+
# Pass the variable into the environment
68+
GITHUB_CI_TOKEN: $(github_ci_token)
69+
condition: in( variables['Agent.OS'], 'Darwin', 'Linux' )
70+
71+
# Couldn't get the script to be found using a bash task.
72+
- script: |
73+
bash.exe ./build_packages.sh -b
74+
workingDirectory: resources
75+
displayName: 'Build Windows'
76+
env:
77+
# Pass the variable into the environment
78+
GITHUB_CI_TOKEN: $(github_ci_token)
79+
condition: eq( variables['Agent.OS'], 'Windows_NT' )
80+
81+
# Delete files
82+
# Delete folders, or files matching a pattern
83+
- task: DeleteFiles@1
84+
inputs:
85+
Contents: |
86+
.git
87+
resources/packagevenv_osx_2
88+
resources/packagevenv_osx_3
89+
resources/packagevenv_windows_2
90+
resources/packagevenv_windows_3
91+
resources/packagevenv_linux_2
92+
resources/packagevenv_linux_3
93+
94+
# Archive files
95+
# Compress files into .7z, .tar.gz, or .zip
96+
- task: ArchiveFiles@2
97+
inputs:
98+
rootFolderOrFile: '$(Build.SourcesDirectory)'
99+
includeRootFolder: false
100+
archiveType: 'zip' # Options: zip, 7z, tar, wim
101+
#tarCompression: 'gz' # Optional. Options: gz, bz2, xz, none
102+
# archive name will be something like v2.1.2-py2.7-osx.zip
103+
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.SourceBranchName)-py$(python.version)-$(platform).zip'
104+
replaceExistingArchive: true
105+
verbose: true
106+
#quiet: # Optional
107+
108+
- bash: |
109+
echo Source branch is ${BUILD_SOURCEBRANCHNAME} for ${PLATFORM}
110+
condition: startsWith(variables['build.sourceBranch'], 'refs/tags/')
111+
112+
# Create, edit, or delete a GitHub release
113+
- task: GitHubRelease@0
114+
displayName: 'Create GitHub Release'
115+
inputs:
116+
# Note: the service connection needs to be created manually with curl
117+
# not from the Azure web UI
118+
# https://github.com/microsoft/azure-pipelines-tasks/issues/11558
119+
gitHubConnection: "Github release"
120+
repositoryName: '$(Build.Repository.Name)'
121+
action: 'edit'
122+
target: '$(Build.SourceVersion)' # Required when action == Create || Action == Edit
123+
tagSource: 'auto' # Required when action == Create# Options: auto, manual
124+
assets: '$(Build.ArtifactStagingDirectory)/$(Build.SourceBranchName)-py$(python.version)-$(platform).zip'
125+
assetUploadMode: 'replace' # Optional. Options: delete, replace
126+
tag: '$(Build.SourceBranchName)'
127+
#tagPattern: # Optional
128+
#tag: # Required when action == Edit || Action == Delete || TagSource == Manual
129+
#title: # Optional
130+
#releaseNotesSource: 'file' # Optional. Options: file, input
131+
#releaseNotesFile: # Optional
132+
#releaseNotes: # Optional
133+
#isDraft: false # Optional
134+
#isPreRelease: false # Optional
135+
#addChangeLog: true # Optional
136+
#compareWith: 'lastFullRelease' # Required when addChangeLog == True. Options: lastFullRelease, lastRelease, lastReleaseByTag
137+
#releaseTag: # Required when compareWith == LastReleaseByTag
138+
condition: startsWith(variables['build.sourceBranch'], 'refs/tags/')
139+

framework.py

Lines changed: 109 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,125 @@
99
version of Python, we have to distribute full versions for the engine to function.
1010
"""
1111

12-
import sgtk
13-
import sys
1412
import os
13+
import platform
14+
import re
15+
import site
16+
import sys
17+
18+
import sgtk
19+
1520

1621
class UnrealQtFramework(sgtk.platform.Framework):
1722

1823
##########################################################################################
1924
# init and destroy
2025

2126
def init_framework(self):
27+
"""
28+
This framework ships with additional Python packages and tweak the Python
29+
paths environment to make these packages available to apps and engines.
30+
31+
Something similar to what `virtualenv` does is done when this framework is
32+
loaded by SG TK.
33+
"""
2234
self.log_debug("%s: Initializing UnrealQtFramework..." % self)
23-
24-
# Supporting Windows only for now
25-
pyside_root = None
26-
if sys.platform == "win32":
27-
if sys.version_info[0] >= 3:
28-
pyside_root = os.path.join(self.disk_location, "resources", "pyside2-5.15.2")
35+
36+
# Remap the platform name to our names
37+
pname = self.platform_name()
38+
39+
# Virtual env has different structures on Windows
40+
if pname == "windows":
41+
bin_folder = "Scripts"
42+
else:
43+
bin_folder = "bin"
44+
45+
# Copied over from activate_this.py script which does not exist anymore
46+
# from Python 3.
47+
python_major = sys.version_info[0] # 2 or 3
48+
49+
base_path = os.path.realpath(
50+
os.path.join(
51+
os.path.dirname(__file__),
52+
"python",
53+
"vendors",
54+
"py%d" % python_major,
55+
pname,
56+
)
57+
)
58+
self.logger.debug("Activating custom packages with %s" % base_path)
59+
60+
if pname == "windows":
61+
site_path = os.path.join(base_path, "Lib", "site-packages")
62+
else:
63+
lib_folders = os.listdir(
64+
os.path.join(
65+
base_path,
66+
"lib"
67+
)
68+
)
69+
python_pattern = r"^python%d\.\d$" % python_major
70+
for folder in lib_folders:
71+
if re.match(python_pattern, folder):
72+
break
2973
else:
30-
pyside_root = os.path.join(self.disk_location, "resources", "pyside2-5.9.0a1")
31-
32-
if pyside_root:
33-
# Add PySide2 path to PYTHONPATH
34-
if pyside_root not in sys.path:
35-
sys.path.append(pyside_root)
36-
37-
try:
38-
self.log_debug("Attempting to import PySide2 from %s" % pyside_root)
39-
from PySide2 import QtCore, QtGui, QtWidgets
40-
import PySide2
41-
42-
self.log_debug("Successfully initialized PySide2 '%s' located in %s."
43-
% (PySide2.__version__, PySide2.__file__))
44-
except ImportError as e:
45-
self.log_warning("Error importing PySide2: %s" % e)
46-
except Exception as e:
47-
self.log_warning("Error setting up PySide2. Pyside2-based UI support will not "
48-
"be available: %s" % e)
74+
raise RuntimeError(
75+
"Couldn't find python libraries for Python %s from %s" % (
76+
python_major,
77+
lib_folders
78+
)
79+
)
80+
site_path = os.path.join(
81+
base_path,
82+
"lib",
83+
folder,
84+
"site-packages"
85+
)
86+
87+
os.environ["VIRTUAL_ENV"] = base_path
88+
# Split PATH, prepend our bin_folder and join back using the os path
89+
# separator (":" or ";")
90+
os.environ["PATH"] = os.pathsep.join(
91+
[os.path.join(base_path, bin_folder)] + os.environ.get("PATH", "").split(os.pathsep)
92+
)
93+
94+
# Add the libraries to the host python import mechanism
95+
prev_length = len(sys.path)
96+
site.addsitedir(site_path)
97+
sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]
98+
99+
sys.real_prefix = sys.prefix
100+
sys.prefix = base_path
49101

50102
def destroy_framework(self):
51103
self.log_debug("%s: Destroying UnrealQtFramework..." % self)
104+
105+
@classmethod
106+
def platform_name(cls):
107+
"""
108+
Return a name for the current os that can be used
109+
when building os specific paths
110+
111+
:returns: A name that can be used when building os specific paths.
112+
:raises ValueError: if the current os is not supported.
113+
"""
114+
platform_names = {"Darwin": "osx", "Linux": "linux", "Windows": "windows"}
115+
pname = platform_names.get(platform.system())
116+
117+
if not pname:
118+
raise ValueError("Platform %s is not supported" % platform.system())
119+
return pname
120+
121+
@classmethod
122+
def bin_folder(cls, vendor=None):
123+
"""
124+
Returns the bin folder for the current os
125+
and the given vendor where binaries can be found
126+
127+
:param str vendor: An optional vendor name that will be included in the path.
128+
:returns: Full path to a folder.
129+
"""
130+
pname = cls.platform_name()
131+
if vendor:
132+
return os.path.join(os.path.dirname(__file__), "vendors", vendor, "bin", pname)
133+
return os.path.join(os.path.dirname(__file__), "vendors", "bin", pname)

0 commit comments

Comments
 (0)