Skip to content

Commit

Permalink
SG-13280 Python 3 port (shotgunsoftware#19)
Browse files Browse the repository at this point in the history
* Code ported to Python 3.

* Fixed previously broken tests. Removed unneeded test_engine, as it is provided by core.

* Now states the additional repos needed for the test to run on Azure.

* Added Python codecov and azure badges.
(Azure should have been added in the black branch but I forgot.)
  • Loading branch information
pscadding authored Mar 16, 2020
1 parent 41c2416 commit c0eef4f
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 145 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[![Python 2.6 2.7 3.7](https://img.shields.io/badge/python-2.6%20%7C%202.7%20%7C%203.7-blue.svg)](https://www.python.org/)
[![Build Status](https://dev.azure.com/shotgun-ecosystem/Toolkit/_apis/build/status/Apps/tk-multi-breakdown?branchName=master)](https://dev.azure.com/shotgun-ecosystem/Toolkit/_build/latest?definitionId=52&branchName=master)
[![codecov](https://codecov.io/gh/shotgunsoftware/tk-multi-breakdown/branch/master/graph/badge.svg)](https://codecov.io/gh/shotgunsoftware/tk-multi-breakdown)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Linting](https://img.shields.io/badge/PEP8%20by-Hound%20CI-a873d1.svg)](https://houndci.com)

Expand Down
5 changes: 1 addition & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
A breakdown app which shows what in the scene is out of date.
"""

from tank.platform import Application

import sys
import os
from sgtk.platform import Application


class MultiBreakdown(Application):
Expand Down
5 changes: 5 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ variables:
# Launch into the build pipeline.
jobs:
- template: build-pipeline.yml@templates
parameters:
additional_repositories:
- name: tk-framework-shotgunutils
- name: tk-framework-widget
- name: tk-framework-qtwidgets
2 changes: 1 addition & 1 deletion hooks/get_version_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def execute(self, template, curr_fields, **kwargs):

# first, find all abstract (Sequence) keys from the template:
abstract_keys = set()
for key_name, key in template.keys.iteritems():
for key_name, key in template.keys.items():
if key.is_abstract:
abstract_keys.add(key_name)

Expand Down
4 changes: 3 additions & 1 deletion python/tk_multi_breakdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
# By accessing, using, copying or modifying this work you indicate your
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.
from breakdown import get_breakdown_items

# Import the get_breakdown_items() method so that it can be used in the app.py.
from .breakdown import get_breakdown_items # noqa


def show_dialog(app):
Expand Down
18 changes: 6 additions & 12 deletions python/tk_multi_breakdown/breakdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.

import urlparse
import os
import urllib
import shutil
import sys
import tank

from tank import TankError
import sgtk

# cache the publish data we pull down from shotgun for performance
g_cached_sg_publish_data = {}
Expand Down Expand Up @@ -83,7 +77,7 @@ def get_breakdown_items():

# perform the scene scanning in the main UI thread - a lot of apps are sensitive to these
# types of operations happening in other threads.
app = tank.platform.current_bundle()
app = sgtk.platform.current_bundle()
scene_objects = app.engine.execute_in_main_thread(
app.execute_hook_method, "hook_scene_operations", "scan_scene"
)
Expand All @@ -97,7 +91,7 @@ def get_breakdown_items():
file_name = scene_object.get("path").replace("/", os.path.sep)

# see if this read node matches any path in the templates setup
matching_template = app.tank.template_from_path(file_name)
matching_template = app.sgtk.template_from_path(file_name)

if matching_template:

Expand All @@ -111,7 +105,7 @@ def get_breakdown_items():
# remove all abstract fields from keys so that the default value will get used
# when building a path from the template. This is consistent with the utility
# method 'register_publish'
for key_name, key in matching_template.keys.iteritems():
for key_name, key in matching_template.keys.items():
if key_name in fields and key.is_abstract:
del fields[key_name]

Expand Down Expand Up @@ -162,12 +156,12 @@ def get_breakdown_items():
"project",
]

if tank.util.get_published_file_entity_type(app.tank) == "PublishedFile":
if sgtk.util.get_published_file_entity_type(app.sgtk) == "PublishedFile":
fields.append("published_file_type")
else: # == "TankPublishedFile"
fields.append("tank_type")

sg_data = tank.util.find_publish(app.tank, paths_to_fetch, fields=fields)
sg_data = sgtk.util.find_publish(app.sgtk, paths_to_fetch, fields=fields)

# process and cache shotgun items
for (path, sg_chunk) in sg_data.items():
Expand Down
16 changes: 4 additions & 12 deletions python/tk_multi_breakdown/breakdown_list_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,13 @@
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.

import urlparse
import os
import urllib
import shutil
import sys
import tank

from tank import TankError
import sgtk
from sgtk.platform.qt import QtGui

from tank.platform.qt import QtCore, QtGui

browser_widget = tank.platform.import_framework("tk-framework-widget", "browser_widget")
browser_widget = sgtk.platform.import_framework("tk-framework-widget", "browser_widget")

from .ui.item import Ui_Item
from . import breakdown


class BreakdownListItem(browser_widget.ListItem):
Expand Down Expand Up @@ -124,7 +116,7 @@ def _calculate_status(self, data):
output["thumbnail"] = ":/res/no_thumb.png"

# first, get the latest available version for this item
app = tank.platform.current_bundle()
app = sgtk.platform.current_bundle()
latest_version = app.execute_hook(
"hook_get_version_number", template=self._template, curr_fields=self._fields
)
Expand Down
6 changes: 1 addition & 5 deletions python/tk_multi_breakdown/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.

import tank
import copy
import os
import sys
import threading

from tank.platform.qt import QtCore, QtGui
from sgtk.platform.qt import QtGui
from .ui.dialog import Ui_Dialog


Expand Down
14 changes: 4 additions & 10 deletions python/tk_multi_breakdown/scene_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.

import tank
import os
import sys
import datetime
import threading
import tank

from tank.platform.qt import QtCore, QtGui
import sgtk

from . import breakdown

browser_widget = tank.platform.import_framework("tk-framework-widget", "browser_widget")
shotgun_globals = tank.platform.import_framework(
browser_widget = sgtk.platform.import_framework("tk-framework-widget", "browser_widget")
shotgun_globals = sgtk.platform.import_framework(
"tk-framework-shotgunutils", "shotgun_globals"
)

Expand Down Expand Up @@ -91,7 +85,7 @@ def process_result(self, result):
################################################################################
# PASS 2 - display the content of all groups

if tank.util.get_published_file_entity_type(self._app.tank) == "PublishedFile":
if sgtk.util.get_published_file_entity_type(self._app.sgtk) == "PublishedFile":
published_file_type_field = "published_file_type"
else: # == "TankPublishedFile"
published_file_type_field = "tank_type"
Expand Down
5 changes: 1 addition & 4 deletions python/tk_multi_breakdown/ui/clickbubbling_groupbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.

import os
import sys

from tank.platform.qt import QtCore, QtGui
from sgtk.platform.qt import QtGui

class ClickBubblingGroupBox(QtGui.QGroupBox):

Expand Down
2 changes: 1 addition & 1 deletion python/tk_multi_breakdown/ui/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'dialog.ui'
#
# by: pyside-uic 0.2.15 running on PySide 1.2.2
# by: pyside-uic 0.2.15 running on PySide 1.2.4
#
# WARNING! All changes made in this file will be lost!

Expand Down
2 changes: 1 addition & 1 deletion python/tk_multi_breakdown/ui/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'item.ui'
#
# by: pyside-uic 0.2.15 running on PySide 1.2.2
# by: pyside-uic 0.2.15 running on PySide 1.2.4
#
# WARNING! All changes made in this file will be lost!

Expand Down
6 changes: 3 additions & 3 deletions python/tk_multi_breakdown/ui/resources_rc.py

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions python/tk_multi_breakdown/ui/thumbnail_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.

import os
import sys

from tank.platform.qt import QtCore, QtGui
from sgtk.platform.qt import QtCore, QtGui

class ThumbnailLabel(QtGui.QLabel):

Expand Down
2 changes: 1 addition & 1 deletion resources/build_resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function build_ui {
}

function build_res {
build_qt "pyside-rcc" "$1.qrc" "$1_rc"
build_qt "pyside-rcc -py3" "$1.qrc" "$1_rc"
}


Expand Down
38 changes: 0 additions & 38 deletions tests/fixtures/config/bundles/test_engine/engine.py

This file was deleted.

22 changes: 0 additions & 22 deletions tests/fixtures/config/bundles/test_engine/info.yml

This file was deleted.

16 changes: 6 additions & 10 deletions tests/fixtures/config/env/test.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
engines:
test_engine:
location: {'type': 'dev', 'path': '{PIPELINE_CONFIG}/config/bundles/test_engine'}
location: {'type': 'dev', 'path': '$SHOTGUN_TEST_ENGINE'}
debug_logging: false

apps:
tk-multi-breakdown:
location: {'type': 'dev', 'path': '${BUNDLE_ROOT}/tk-multi-breakdown'}
location: {'type': 'dev', 'path': '$SHOTGUN_CURRENT_REPO_ROOT'}
hook_scene_operations: '{config}/scene_operations.py'


frameworks:
tk-framework-widget_v0.2.x:
location: {name: tk-framework-widget, type: dev, version: v0.2.33, path: '${BUNDLE_ROOT}/tk-framework-widget' }
tk-framework-shotgunutils_v2.x.x:
location: {name: tk-framework-shotgunutils, type: dev, version: v2.0.10, path: '${BUNDLE_ROOT}/tk-framework-shotgunutils' }
tk-framework-shotgunutils_v4.x.x:
location: {name: tk-framework-shotgunutils, type: dev, version: v2.0.10, path: '${BUNDLE_ROOT}/tk-framework-shotgunutils' }
tk-framework-qtwidgets_v1.x.x:
location: {name: tk-framework-qtwidgets, type: dev, version: v1.0.1, path: '${BUNDLE_ROOT}/tk-framework-qtwidgets' }
location: {type: dev, path: '$SHOTGUN_REPOS_ROOT/tk-framework-widget' }
tk-framework-shotgunutils_v5.x.x:
location: {type: dev, path: '$SHOTGUN_REPOS_ROOT/tk-framework-shotgunutils' }
tk-framework-qtwidgets_v2.x.x:
location: {name: tk-framework-qtwidgets, type: dev, version: v1.0.1, path: '${BUNDLE_ROOT}/tk-framework-qtwidgets' }
location: {type: dev, path: '$SHOTGUN_REPOS_ROOT/tk-framework-qtwidgets' }
25 changes: 9 additions & 16 deletions tests/test_breakdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.

import sys
import os
import shutil
import tempfile

from tank_test.tank_test_base import *
import tank
from tank.errors import TankError
from tank.platform import application
from tank.platform import constants
from tank.template import Template
from tank.deploy import descriptor
import sgtk
from sgtk.errors import TankError


class TestApplication(TankTestBase):
Expand Down Expand Up @@ -91,14 +84,14 @@ def setUp(self):
context = self.tk.context_from_entity(self.shot["type"], self.shot["id"])

# and start the engine
self.engine = tank.platform.start_engine("test_engine", self.tk, context)
self.engine = sgtk.platform.start_engine("test_engine", self.tk, context)

def tearDown(self):
"""
Fixtures teardown
"""
# engine is held as global, so must be destroyed.
cur_engine = tank.platform.current_engine()
cur_engine = sgtk.platform.current_engine()
if cur_engine:
cur_engine.destroy()

Expand Down Expand Up @@ -209,15 +202,15 @@ def test_update(self):
fields["version"] = 4

# clear temp location where hook writes to
tank._hook_items = None
sgtk._hook_items = None

# execute hook
self.app.update_item(
item["node_type"], item["node_name"], item["template"], fields
)

# check result
self.assertEqual(len(tank._hook_items), 1)
self.assertEqual(tank._hook_items[0]["node"], "maya_publish")
self.assertEqual(tank._hook_items[0]["path"], self.test_path_2)
self.assertEqual(tank._hook_items[0]["type"], "TestNode")
self.assertEqual(len(sgtk._hook_items), 1)
self.assertEqual(sgtk._hook_items[0]["node"], "maya_publish")
self.assertEqual(sgtk._hook_items[0]["path"], self.test_path_2)
self.assertEqual(sgtk._hook_items[0]["type"], "TestNode")

0 comments on commit c0eef4f

Please sign in to comment.