Skip to content

Commit 91653a1

Browse files
authored
6646 osx support (#1)
Added flake8 stuff and fixed reported problems. Added basic support for Osx so at least the Unreal Engine app can be found.
1 parent 6863ca4 commit 91653a1

File tree

15 files changed

+392
-260
lines changed

15 files changed

+392
-260
lines changed

.flake8

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Flake 8 PEP and lint configuration - https://gitlab.com/pycqa/flake8
2+
#
3+
# This defines the official lint and PEP8 rules for this repository
4+
#
5+
# You can run this locally by running 'pip install flake8' and then
6+
# >flake8 .
7+
8+
[flake8]
9+
10+
# Things we don't want to lint
11+
exclude =
12+
.tox,
13+
.git,
14+
.flake8,
15+
.gitignore,
16+
.travis.yml,
17+
.cache,
18+
.eggs,
19+
*.rst,
20+
*.yml,
21+
*.pyc,
22+
*.pyo,
23+
*.egg-info,
24+
__pycache__,
25+
# Those are our third parties, do not lint them
26+
vendors,
27+
# Skip __init__.py files, to not have a lot of 'xxx' imported but unused
28+
python/__init__.py,
29+
python/*/__init__.py,
30+
# Skip the auto-generated ui file.
31+
python/*/ui,
32+
venv
33+
winenv
34+
35+
# Ignore some errors
36+
#
37+
# E402 module level import not at top of file
38+
# E501 line too long (112 > 79 characters)
39+
# N802 Variables should be lower case. (clashes with Qt naming conventions)
40+
# N806 Variables should be lower case. (clashes with Qt naming conventions)
41+
# W503 line break before binary operator (it breaks before, not after)
42+
43+
ignore = E501, E402, N802, N806, W503
44+

azure-pipelines.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Python package
2+
# Create and test a Python package on multiple Python versions.
3+
# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more:
4+
# https://docs.microsoft.com/azure/devops/pipelines/languages/python
5+
6+
# The github_ci_token variable is defined in the Azure Pipeline web page as a
7+
# secret variable and is a github personal token.
8+
9+
jobs:
10+
- job: 'Flake8'
11+
pool:
12+
vmImage: 'Ubuntu 16.04'
13+
14+
steps:
15+
- task: UsePythonVersion@0
16+
inputs:
17+
versionSpec: 2.7
18+
architecture: 'x64'
19+
20+
- script: |
21+
python -m pip install --upgrade pip setuptools wheel
22+
displayName: 'Install prerequisites'
23+
24+
- script: |
25+
python -m pip install flake8
26+
flake8 .
27+
displayName: 'Run flake8'

engine.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file is based on templates provided and copyrighted by Autodesk, Inc.
2-
# This file has been modified by Epic Games, Inc. and is subject to the license
2+
# This file has been modified by Epic Games, Inc. and is subject to the license
33
# file included in this repository.
44

55
"""
@@ -27,21 +27,10 @@
2727
class UnrealEditorEngine(Engine):
2828
"""
2929
Toolkit engine for Unreal.
30-
31-
All the methods that are present are either stubs or example of the expected functionality.
32-
33-
Note that when the engine starts up a log file is created at
34-
35-
Windows: %APPDATA%\Shotgun\logs\tk-unreal.log
36-
macOS: ~/Library/Logs/Shotgun/tk-unreal.log
37-
Linux: ~/.shotgun/logs/tk-unreal.log
38-
39-
and that all logging calls to Toolkit logging methods will be forwarded there.
40-
It all uses the Python's logger under the hood.
4130
"""
4231

4332
metadata_tag_prefix = "SG."
44-
33+
4534
def __init__(self, *args, **kwargs):
4635
"""
4736
Engine Constructor
@@ -119,7 +108,7 @@ def init_qt_app(self):
119108
self.logger.debug("%s: Initializing QtApp for Unreal", self)
120109

121110
from sgtk.platform.qt5 import QtWidgets
122-
111+
123112
if not QtWidgets.QApplication.instance():
124113
self._qt_app = QtWidgets.QApplication(sys.argv)
125114
self._qt_app.setQuitOnLastWindowClosed(False)
@@ -129,7 +118,7 @@ def init_qt_app(self):
129118

130119
# Make the QApplication use the dark theme. Must be called after the QApplication is instantiated
131120
self._initialize_dark_look_and_feel()
132-
121+
133122
def post_app_init(self):
134123
"""
135124
Called when all apps have initialized
@@ -214,10 +203,10 @@ def destroy_engine(self):
214203
"""
215204
self.logger.debug("%s: Destroying tk-unreal engine...", self)
216205

217-
# Close all Shotgun app dialogs that are still opened since
206+
# Close all Shotgun app dialogs that are still opened since
218207
# some apps do threads cleanup in their onClose event handler
219208
# Note that this function is called when the engine is restarted (through "Reload Engine and Apps")
220-
209+
221210
# Important: Copy the list of dialogs still opened since the call to close() will modify created_qt_dialogs
222211
dialogs_still_opened = self.created_qt_dialogs[:]
223212

@@ -229,7 +218,7 @@ def get_metadata_tag(self, tag):
229218
Returns the given tag with the metadata tag prefix defined for this engine
230219
"""
231220
return UnrealEditorEngine.metadata_tag_prefix + tag
232-
221+
233222
def _get_dialog_parent(self):
234223
"""
235224
Get the QWidget parent for all dialogs created through
@@ -259,17 +248,17 @@ def _create_dialog(self, title, bundle, widget, parent):
259248
Function override to set the window icon
260249
"""
261250
dialog = sgtk.platform.Engine._create_dialog(self, title, bundle, widget, parent)
262-
251+
263252
from sgtk.platform.qt import QtGui
264253

265254
unreal_icon = os.path.realpath(os.path.join(
266255
os.path.dirname(__file__),
267256
"icon_256.png"))
268-
257+
269258
dialog.setWindowIcon(QtGui.QIcon(unreal_icon))
270259

271260
return dialog
272-
261+
273262
def _define_qt_base(self):
274263
"""
275264
This will be called at initialisation time and will allow

hooks/tk-multi-loader2/tk-unreal_actions.py

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# This file is based on templates provided and copyrighted by Autodesk, Inc.
2-
# This file has been modified by Epic Games, Inc. and is subject to the license
2+
# This file has been modified by Epic Games, Inc. and is subject to the license
33
# file included in this repository.
44

55
"""
66
Hook that loads defines all the available actions, broken down by publish type.
77
"""
88

9-
import pprint
109
import os
1110
import sgtk
1211
import unreal
@@ -68,7 +67,7 @@ def generate_actions(self, sg_publish_data, actions, ui_area):
6867
"params": None,
6968
"caption": "Import into Content Browser",
7069
"description": "This will import the asset into the Unreal Editor Content Browser."})
71-
70+
7271
return action_instances
7372

7473
def execute_multiple_actions(self, actions):
@@ -135,24 +134,24 @@ def _import_to_content_browser(self, path, sg_publish_data):
135134
:param path: Path to file.
136135
:param sg_publish_data: Shotgun data dictionary with all the standard publish fields.
137136
"""
138-
137+
139138
unreal.log("File to import: {}".format(path))
140139

141140
if not os.path.exists(path):
142141
raise Exception("File not found on disk - '%s'" % path)
143142

144143
destination_path, destination_name = self._get_destination_path_and_name(sg_publish_data)
145-
144+
146145
asset_path = _unreal_import_fbx_asset(path, destination_path, destination_name)
147-
146+
148147
if asset_path:
149148
self._set_asset_metadata(asset_path, sg_publish_data)
150-
149+
151150
# Focus the Unreal Content Browser on the imported asset
152151
asset_paths = []
153152
asset_paths.append(asset_path)
154153
unreal.EditorAssetLibrary.sync_browser_to_objects(asset_paths)
155-
154+
156155
def _set_asset_metadata(self, asset_path, sg_publish_data):
157156
"""
158157
Set needed metadata on the given asset
@@ -161,9 +160,9 @@ def _set_asset_metadata(self, asset_path, sg_publish_data):
161160

162161
if not asset:
163162
return
164-
163+
165164
engine = sgtk.platform.current_engine()
166-
165+
167166
# Add a metadata tag for "created_by"
168167
if "created_by" in sg_publish_data:
169168
createdby_dict = sg_publish_data["created_by"]
@@ -172,12 +171,12 @@ def _set_asset_metadata(self, asset_path, sg_publish_data):
172171
name = createdby_dict["name"]
173172
elif "id" in createdby_dict:
174173
name = createdby_dict["id"]
175-
174+
176175
tag = engine.get_metadata_tag("created_by")
177176
unreal.EditorAssetLibrary.set_metadata_tag(asset, tag, name)
178177

179178
# Add a metadata tag for the Shotgun URL
180-
# Construct the PublishedFile URL from the publish data type and id since
179+
# Construct the PublishedFile URL from the publish data type and id since
181180
# the context of a PublishedFile is the Project context
182181
shotgun_site = self.sgtk.shotgun_url
183182
type = sg_publish_data["type"]
@@ -191,24 +190,24 @@ def _set_asset_metadata(self, asset_path, sg_publish_data):
191190
entity_dict = sg_publish_data["entity"]
192191
context = self.sgtk.context_from_entity_dictionary(entity_dict)
193192
url = context.shotgun_url
194-
193+
195194
if entity_dict["type"] == "Project":
196-
# As a last resort, construct the PublishedFile URL from the publish data type and id since
195+
# As a last resort, construct the PublishedFile URL from the publish data type and id since
197196
# the context of a PublishedFile is the Project context
198197
shotgun_site = self.sgtk.shotgun_url
199198
type = sg_publish_data["type"]
200199
id = sg_publish_data["id"]
201200
url = shotgun_site + "/detail/" + type + "/" + str(id)
202201
"""
203-
202+
204203
tag = engine.get_metadata_tag("url")
205204
unreal.EditorAssetLibrary.set_metadata_tag(asset, tag, url)
206205

207206
unreal.EditorAssetLibrary.save_loaded_asset(asset)
208-
207+
209208
##############################################################################################################
210209
# helper methods which can be subclassed in custom hooks to fine tune the behaviour of things
211-
210+
212211
def _get_destination_path_and_name(self, sg_publish_data):
213212
"""
214213
Get the destination path and name from the publish data and the templates
@@ -247,14 +246,14 @@ def _get_destination_path_and_name(self, sg_publish_data):
247246

248247
# Add the name field from the publish data
249248
fields["name"] = name
250-
249+
251250
# Get destination path by applying fields to destination template
252251
# Fall back to the root level if unsuccessful
253252
try:
254253
destination_path = destination_template.apply_fields(fields)
255254
except Exception:
256255
destination_path = "/Game/Assets/"
257-
256+
258257
# Query the fields needed for the name template from the context
259258
name_fields = context.as_template_fields(destination_name_template)
260259

@@ -269,18 +268,21 @@ def _get_destination_path_and_name(self, sg_publish_data):
269268
destination_name = _sanitize_name(sg_publish_data["code"])
270269

271270
return destination_path, destination_name
272-
271+
272+
273273
"""
274274
Functions to import FBX into Unreal
275275
"""
276276

277+
277278
def _sanitize_name(name):
278279
# Remove the default Shotgun versioning number if found (of the form '.v001')
279280
name_no_version = re.sub(r'.v[0-9]{3}', '', name)
280-
281+
281282
# Replace any remaining '.' with '_' since they are not allowed in Unreal asset names
282283
return name_no_version.replace('.', '_')
283284

285+
284286
def _unreal_import_fbx_asset(input_path, destination_path, destination_name):
285287
"""
286288
Import an FBX into Unreal Content Browser
@@ -291,11 +293,11 @@ def _unreal_import_fbx_asset(input_path, destination_path, destination_name):
291293
"""
292294
tasks = []
293295
tasks.append(_generate_fbx_import_task(input_path, destination_path, destination_name))
294-
296+
295297
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(tasks)
296298

297299
first_imported_object = None
298-
300+
299301
for task in tasks:
300302
unreal.log("Import Task for: {}".format(task.filename))
301303
for object_path in task.imported_object_paths:
@@ -304,10 +306,19 @@ def _unreal_import_fbx_asset(input_path, destination_path, destination_name):
304306
first_imported_object = object_path
305307

306308
return first_imported_object
307-
308-
def _generate_fbx_import_task(filename, destination_path, destination_name=None, replace_existing=True,
309-
automated=True, save=True, materials=True,
310-
textures=True, as_skeletal=False):
309+
310+
311+
def _generate_fbx_import_task(
312+
filename,
313+
destination_path,
314+
destination_name=None,
315+
replace_existing=True,
316+
automated=True,
317+
save=True,
318+
materials=True,
319+
textures=True,
320+
as_skeletal=False
321+
):
311322
"""
312323
Create and configure an Unreal AssetImportTask
313324
@@ -318,11 +329,11 @@ def _generate_fbx_import_task(filename, destination_path, destination_name=None,
318329
task = unreal.AssetImportTask()
319330
task.filename = filename
320331
task.destination_path = destination_path
321-
332+
322333
# By default, destination_name is the filename without the extension
323334
if destination_name is not None:
324335
task.destination_name = destination_name
325-
336+
326337
task.replace_existing = replace_existing
327338
task.automated = automated
328339
task.save = save

0 commit comments

Comments
 (0)