-
Notifications
You must be signed in to change notification settings - Fork 9
Multi-platform support #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1301620
5cd9df6
acb67b9
cd0b406
05a94ea
8a65fa0
9769240
149c5e4
181e138
8571cfb
e895390
e8608d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
eggs/ | ||
parts/ | ||
sdist/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
*.dist-info | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
test | ||
|
||
# Translations | ||
*.mo | ||
|
||
# Mr Developer | ||
.mr.developer.cfg | ||
.project | ||
.pydevproject | ||
|
||
# Editors | ||
.idea | ||
.vscode | ||
|
||
# Rope | ||
.ropeproject | ||
|
||
# Django stuff: | ||
*.log | ||
*.pot | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# Mac stuff | ||
.DS_Store | ||
|
||
# Package building | ||
packagevenv* | ||
python/vendors |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# We want builds to trigger for 3 reasons: | ||
# - The master branch sees new commits | ||
# - Each PR should get rebuilt when commits are added to it. | ||
# - When we tag something | ||
trigger: | ||
branches: | ||
include: | ||
- master | ||
tags: | ||
include: | ||
# Tags must start with "v" | ||
- v* | ||
pr: | ||
branches: | ||
include: | ||
- "*" | ||
|
||
# The github_ci_token variable is defined in the Azure Pipeline web page as a | ||
# secret variable and is a github personal token. | ||
|
||
jobs: | ||
|
||
- job: 'Build' | ||
strategy: | ||
matrix: | ||
# Define all the platform/python version we need | ||
MacPython37: | ||
platform: 'osx' # Short name for us | ||
imageName: 'macOS-10.15' | ||
python.version: '3.7' | ||
WinPython37: | ||
platform: 'win' # Short name for us | ||
imageName: 'windows-2019' | ||
python.version: '3.7' | ||
LinuxPython37: | ||
platform: 'linux' # Short name for us | ||
imageName: 'ubuntu-latest' | ||
python.version: '3.7' | ||
maxParallel: 1 | ||
|
||
pool: | ||
# Retrieve the value set by the strategy above | ||
vmImage: $(imageName) | ||
|
||
steps: | ||
- task: UsePythonVersion@0 | ||
inputs: | ||
versionSpec: '$(python.version)' | ||
architecture: 'x64' | ||
|
||
- script: | | ||
python -m pip install --upgrade pip | ||
displayName: 'Install dependencies' | ||
|
||
# Not needed for Python 3, virtual env are built with python3 -m venv | ||
- script: | | ||
pip install virtualenv | ||
condition: eq( variables['python.version'], '2.7' ) | ||
displayName: 'Install virtualenv' | ||
|
||
# Couldn't get the script to be found using a bash task. | ||
- script: | | ||
./build_packages.sh -b | ||
workingDirectory: "resources" | ||
displayName: 'Build' | ||
env: | ||
# Pass the variable into the environment | ||
GITHUB_CI_TOKEN: $(github_ci_token) | ||
condition: in( variables['Agent.OS'], 'Darwin', 'Linux' ) | ||
|
||
# Couldn't get the script to be found using a bash task. | ||
- script: | | ||
bash.exe ./build_packages.sh -b | ||
workingDirectory: resources | ||
displayName: 'Build Windows' | ||
env: | ||
# Pass the variable into the environment | ||
GITHUB_CI_TOKEN: $(github_ci_token) | ||
condition: eq( variables['Agent.OS'], 'Windows_NT' ) | ||
|
||
# Delete files | ||
# Delete folders, or files matching a pattern | ||
- task: DeleteFiles@1 | ||
inputs: | ||
Contents: | | ||
.git | ||
resources/packagevenv_osx_2 | ||
resources/packagevenv_osx_3 | ||
resources/packagevenv_windows_2 | ||
resources/packagevenv_windows_3 | ||
resources/packagevenv_linux_2 | ||
resources/packagevenv_linux_3 | ||
|
||
# Archive files | ||
# Compress files into .7z, .tar.gz, or .zip | ||
- task: ArchiveFiles@2 | ||
inputs: | ||
rootFolderOrFile: '$(Build.SourcesDirectory)' | ||
includeRootFolder: false | ||
archiveType: 'zip' # Options: zip, 7z, tar, wim | ||
#tarCompression: 'gz' # Optional. Options: gz, bz2, xz, none | ||
# archive name will be something like v2.1.2-py2.7-osx.zip | ||
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.SourceBranchName)-py$(python.version)-$(platform).zip' | ||
replaceExistingArchive: true | ||
verbose: true | ||
#quiet: # Optional | ||
|
||
- bash: | | ||
echo Source branch is ${BUILD_SOURCEBRANCHNAME} for ${PLATFORM} | ||
condition: startsWith(variables['build.sourceBranch'], 'refs/tags/') | ||
|
||
# Create, edit, or delete a GitHub release | ||
- task: GitHubRelease@0 | ||
displayName: 'Create GitHub Release' | ||
inputs: | ||
# Note: the service connection needs to be created manually with curl | ||
# not from the Azure web UI | ||
# https://github.com/microsoft/azure-pipelines-tasks/issues/11558 | ||
gitHubConnection: "Github release" | ||
repositoryName: '$(Build.Repository.Name)' | ||
action: 'edit' | ||
target: '$(Build.SourceVersion)' # Required when action == Create || Action == Edit | ||
tagSource: 'auto' # Required when action == Create# Options: auto, manual | ||
assets: '$(Build.ArtifactStagingDirectory)/$(Build.SourceBranchName)-py$(python.version)-$(platform).zip' | ||
assetUploadMode: 'replace' # Optional. Options: delete, replace | ||
tag: '$(Build.SourceBranchName)' | ||
#tagPattern: # Optional | ||
#tag: # Required when action == Edit || Action == Delete || TagSource == Manual | ||
#title: # Optional | ||
#releaseNotesSource: 'file' # Optional. Options: file, input | ||
#releaseNotesFile: # Optional | ||
#releaseNotes: # Optional | ||
#isDraft: false # Optional | ||
#isPreRelease: false # Optional | ||
#addChangeLog: true # Optional | ||
#compareWith: 'lastFullRelease' # Required when addChangeLog == True. Options: lastFullRelease, lastRelease, lastReleaseByTag | ||
#releaseTag: # Required when compareWith == LastReleaseByTag | ||
condition: startsWith(variables['build.sourceBranch'], 'refs/tags/') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,43 +9,125 @@ | |
version of Python, we have to distribute full versions for the engine to function. | ||
""" | ||
|
||
import sgtk | ||
import sys | ||
import os | ||
import platform | ||
import re | ||
import site | ||
import sys | ||
|
||
import sgtk | ||
|
||
|
||
class UnrealQtFramework(sgtk.platform.Framework): | ||
|
||
########################################################################################## | ||
# init and destroy | ||
|
||
def init_framework(self): | ||
""" | ||
This framework ships with additional Python packages and tweak the Python | ||
paths environment to make these packages available to apps and engines. | ||
|
||
Something similar to what `virtualenv` does is done when this framework is | ||
loaded by SG TK. | ||
""" | ||
self.log_debug("%s: Initializing UnrealQtFramework..." % self) | ||
|
||
# Supporting Windows only for now | ||
pyside_root = None | ||
if sys.platform == "win32": | ||
if sys.version_info[0] >= 3: | ||
pyside_root = os.path.join(self.disk_location, "resources", "pyside2-5.15.2") | ||
|
||
# Remap the platform name to our names | ||
pname = self.platform_name() | ||
gplsteph marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Virtual env has different structures on Windows | ||
if pname == "windows": | ||
bin_folder = "Scripts" | ||
else: | ||
bin_folder = "bin" | ||
|
||
# Copied over from activate_this.py script which does not exist anymore | ||
# from Python 3. | ||
python_major = sys.version_info[0] # 2 or 3 | ||
|
||
base_path = os.path.realpath( | ||
os.path.join( | ||
os.path.dirname(__file__), | ||
"python", | ||
"vendors", | ||
"py%d" % python_major, | ||
pname, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to double check, currently there's not python/vendors folder and base_path is the root path of the framework? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, there was only the Windows binaries, that I removed for the CR. |
||
) | ||
) | ||
self.logger.debug("Activating custom packages with %s" % base_path) | ||
|
||
if pname == "windows": | ||
site_path = os.path.join(base_path, "Lib", "site-packages") | ||
else: | ||
lib_folders = os.listdir( | ||
os.path.join( | ||
base_path, | ||
"lib" | ||
) | ||
) | ||
python_pattern = r"^python%d\.\d$" % python_major | ||
for folder in lib_folders: | ||
if re.match(python_pattern, folder): | ||
break | ||
else: | ||
pyside_root = os.path.join(self.disk_location, "resources", "pyside2-5.9.0a1") | ||
|
||
if pyside_root: | ||
# Add PySide2 path to PYTHONPATH | ||
if pyside_root not in sys.path: | ||
sys.path.append(pyside_root) | ||
|
||
try: | ||
self.log_debug("Attempting to import PySide2 from %s" % pyside_root) | ||
from PySide2 import QtCore, QtGui, QtWidgets | ||
import PySide2 | ||
|
||
self.log_debug("Successfully initialized PySide2 '%s' located in %s." | ||
% (PySide2.__version__, PySide2.__file__)) | ||
except ImportError as e: | ||
self.log_warning("Error importing PySide2: %s" % e) | ||
except Exception as e: | ||
self.log_warning("Error setting up PySide2. Pyside2-based UI support will not " | ||
"be available: %s" % e) | ||
raise RuntimeError( | ||
"Couldn't find python libraries for Python %s from %s" % ( | ||
python_major, | ||
lib_folders | ||
) | ||
) | ||
site_path = os.path.join( | ||
base_path, | ||
"lib", | ||
folder, | ||
"site-packages" | ||
) | ||
|
||
os.environ["VIRTUAL_ENV"] = base_path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A friendly request: can you explain a little bit the strategy with virtualenv?. It's not usual in toolkit play with virtualenv specially when distributing components |
||
# Split PATH, prepend our bin_folder and join back using the os path | ||
# separator (":" or ";") | ||
os.environ["PATH"] = os.pathsep.join( | ||
[os.path.join(base_path, bin_folder)] + os.environ.get("PATH", "").split(os.pathsep) | ||
) | ||
|
||
# Add the libraries to the host python import mechanism | ||
prev_length = len(sys.path) | ||
site.addsitedir(site_path) | ||
sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length] | ||
|
||
sys.real_prefix = sys.prefix | ||
sys.prefix = base_path | ||
|
||
def destroy_framework(self): | ||
self.log_debug("%s: Destroying UnrealQtFramework..." % self) | ||
|
||
@classmethod | ||
def platform_name(cls): | ||
""" | ||
Return a name for the current os that can be used | ||
when building os specific paths | ||
|
||
:returns: A name that can be used when building os specific paths. | ||
:raises ValueError: if the current os is not supported. | ||
""" | ||
platform_names = {"Darwin": "osx", "Linux": "linux", "Windows": "windows"} | ||
pname = platform_names.get(platform.system()) | ||
|
||
if not pname: | ||
raise ValueError("Platform %s is not supported" % platform.system()) | ||
return pname | ||
|
||
@classmethod | ||
def bin_folder(cls, vendor=None): | ||
""" | ||
Returns the bin folder for the current os | ||
and the given vendor where binaries can be found | ||
|
||
:param str vendor: An optional vendor name that will be included in the path. | ||
:returns: Full path to a folder. | ||
""" | ||
pname = cls.platform_name() | ||
if vendor: | ||
return os.path.join(os.path.dirname(__file__), "vendors", vendor, "bin", pname) | ||
return os.path.join(os.path.dirname(__file__), "vendors", "bin", pname) |
Uh oh!
There was an error while loading. Please reload this page.