Skip to content

Commit

Permalink
Pre-commit linter fixes (#3)
Browse files Browse the repository at this point in the history
* Pre-commmit linter fixes

* Update Azure Pipeline ID
  • Loading branch information
rob-aitchison authored Jun 29, 2023
1 parent eefb4c0 commit a2df4eb
Show file tree
Hide file tree
Showing 37 changed files with 578 additions and 318 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Python 3.7 3.9](https://img.shields.io/badge/python-3.7%20%7C%203.9-blue.svg)](https://www.python.org/)
[![Build Status](https://dev.azure.com/shotgun-ecosystem/Toolkit/_apis/build/status/Frameworks/tk-framework-alias?branchName=main)](https://dev.azure.com/shotgun-ecosystem/Toolkit/_build/latest?definitionId=62&branchName=main)
[![Build Status](https://dev.azure.com/shotgun-ecosystem/Toolkit/_apis/build/status/Frameworks/tk-framework-alias?branchName=main)](https://dev.azure.com/shotgun-ecosystem/Toolkit/_build/latest?definitionId=120&branchName=main)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

# tk-framework-alias
Expand All @@ -18,7 +18,7 @@ The main use of this framework is by the [Alias Engine](https://github.com/shotg
## What's in the Framework

### <a name="alias_plugin"></a>Alias Plugin ###

This plugin is loaded by Alias and is the main entry point to integrating a Python client (e.g. ShotGrid) with Alias. This is maintained by the ShotGrid Automotive Team.

File location: `dist/Alias/{python_version/{alias_version}/{plugin_name}.plugin`
Expand Down
4 changes: 3 additions & 1 deletion dev/build_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ def _validate_args(args):
# setup the logger for use from here on out
try:
# set up std toolkit logging to file
sgtk.LogManager().initialize_base_file_handler("tk-framework-alias_build_plugin")
sgtk.LogManager().initialize_base_file_handler(
"tk-framework-alias_build_plugin"
)

# set up output of all sgtk log messages to stdout
sgtk.LogManager().initialize_custom_handler()
Expand Down
1 change: 0 additions & 1 deletion dev/env.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ rem uncomment the following line and set your path accordingly.
@REM set "TKCORE_FOLDER=C:\Users\qa\sg_envs\dv\tk\tk-core"

set "PYTHON_EXE=python"

5 changes: 4 additions & 1 deletion dev/get-pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
message_parts = [
"This script does not work on Python {}.{}".format(*this_python),
"The minimum supported Python version is {}.{}.".format(*min_version),
"Please use https://bootstrap.pypa.io/pip/{}.{}/get-pip.py instead.".format(*this_python),
"Please use https://bootstrap.pypa.io/pip/{}.{}/get-pip.py instead.".format(
*this_python
),
]
print("ERROR: " + " ".join(message_parts))
sys.exit(1)
Expand Down Expand Up @@ -113,6 +115,7 @@ def bootstrap(tmpdir):
# Execute the included pip and use it to install the latest pip and
# setuptools from PyPI
from pip._internal.cli.main import main as pip_entry_point

args = determine_pip_install_arguments()
sys.exit(pip_entry_point(args))

Expand Down
2 changes: 1 addition & 1 deletion dist/Python/Python37/embed_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.1
1.2.1
2 changes: 1 addition & 1 deletion dist/Python/Python39/embed_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.0.0
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.0.2
v0.0.2
1 change: 0 additions & 1 deletion dist/Toolkit/plugin/com.sg.basic.alias/info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ base_configuration:
# will be called sgtk_plugin_review_maya and will be located in a python subfolder
# once the plugin has been built.
plugin_id: "basic.alias"

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# this file was auto generated.
from . import manifest

# end of file.
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
# this file was auto generated.


base_configuration="sgtk:descriptor:app_store?name=tk-config-basic"
plugin_id="basic.alias"
base_configuration = "sgtk:descriptor:app_store?name=tk-config-basic"
plugin_id = "basic.alias"


# system generated parameters
BUILD_DATE="20230525_161934"
BUILD_GENERATION=2
BUILD_DATE = "20230525_161934"
BUILD_GENERATION = 2


def get_sgtk_pythonpath(plugin_root):
"""
Auto generated helper method which returns the
"""
Auto generated helper method which returns the
path to the core bundled with the plugin.
For more information, see the documentation.
"""
"""
import os
return os.path.join(plugin_root, "bundle_cache", "app_store", "tk-core", "v0.20.16", "python")


return os.path.join(
plugin_root, "bundle_cache", "app_store", "tk-core", "v0.20.16", "python"
)


def initialize_manager(manager, plugin_root):
"""
"""
Auto generated helper method which initializes
a toolkit manager with common plugin parameters.
For more information, see the documentation.
"""
"""
import os
manager.base_configuration = 'sgtk:descriptor:app_store?name=tk-config-basic'
manager.plugin_id = 'basic.alias'
bundle_cache_path = os.path.join(plugin_root, 'bundle_cache')

manager.base_configuration = "sgtk:descriptor:app_store?name=tk-config-basic"
manager.plugin_id = "basic.alias"
bundle_cache_path = os.path.join(plugin_root, "bundle_cache")
manager.bundle_cache_fallback_paths = [bundle_cache_path]
return manager

Expand Down
1 change: 0 additions & 1 deletion plugin/Toolkit/basic/info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ base_configuration:
# will be called sgtk_plugin_review_maya and will be located in a python subfolder
# once the plugin has been built.
plugin_id: "basic.alias"

5 changes: 4 additions & 1 deletion python/tk_framework_alias/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
# First add our third-party packages to sys.path
import sys
from tk_framework_alias_utils.environment_utils import get_python_site_packages
site_packages_path = get_python_site_packages(sys.version_info.major, sys.version_info.minor)

site_packages_path = get_python_site_packages(
sys.version_info.major, sys.version_info.minor
)
sys.path.insert(0, site_packages_path)

from . import client
Expand Down
15 changes: 10 additions & 5 deletions python/tk_framework_alias/client/socketio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from tk_framework_alias_utils import utils as framework_utils
from tk_framework_alias_utils import environment_utils as framework_env_utils


class AliasSocketIoClient(socketio.Client):
"""
A socketio client to communicate with Alias.
Expand All @@ -45,14 +46,16 @@ def __init__(self, *args, **kwargs):
self.__json = None

# If no logger specified, provide a default logger that will write to the Alisa plugin
# install directory (as specified n the environment utils).
logger = None
# install directory (as specified n the environment utils).
logger = None
if kwargs.get("logger") is None:
logger = framework_utils.get_logger(self.__class__.__name__, "sio_client")
kwargs["logger"] = logger

if kwargs.get("engineio_logger") is None:
kwargs["engineio_logger"] = logger or framework_utils.get_logger(self.__class__.__name__, "sio_client")
kwargs["engineio_logger"] = logger or framework_utils.get_logger(
self.__class__.__name__, "sio_client"
)

super(AliasSocketIoClient, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -311,7 +314,9 @@ def get_alias_api(self):

# Get the cache file path for the api module
filename = os.path.basename(api_info["file_path"]).split(".")[0]
cache_filepath = framework_env_utils.get_alias_api_cache_file_path(filename, api_info["alias_version"], api_info["python_version"])
cache_filepath = framework_env_utils.get_alias_api_cache_file_path(
filename, api_info["alias_version"], api_info["python_version"]
)

cache_loaded = False
if os.path.exists(cache_filepath):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def _handle_callback(self, callback_func, data=None):
args = data.get("args", [])
kwargs = data.get("kwargs", {})

self.client.logger.debug(f"Executing callback function {callback_func.__name__}")
self.client.logger.debug(
f"Executing callback function {callback_func.__name__}"
)
return callback_func(*args, **kwargs)

def _log_message(self, msg, level=logging.INFO):
Expand Down
2 changes: 1 addition & 1 deletion python/tk_framework_alias/client/socketio/proxy_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class AliasClientObjectProxyWrapper:
__types_by_module = {}
__types_by_module_lock = threading.Lock()


def __init__(self, data, module=None, attribute_name=None):
"""Initialize the proxy wrapper object."""

Expand Down Expand Up @@ -654,6 +653,7 @@ def value(self):
"""Get the value of the enum."""
return self.__value


class AliasClientObjectProxy(AliasClientObjectProxyWrapper):
"""A proxy wrapper for intances of Alias objects."""

Expand Down
46 changes: 34 additions & 12 deletions python/tk_framework_alias/server/alias_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
AliasEventsClientNamespace,
)
from .utils.singleton import Singleton
from .utils.exceptions import AliasBridgeException, ClientAlreadyRegistered, ServerAlreadyRunning, ClientNameReservered
from .utils.exceptions import (
AliasBridgeException,
ClientAlreadyRegistered,
ServerAlreadyRunning,
ClientNameReservered,
)

from tk_framework_alias_utils import utils as framework_utils

Expand Down Expand Up @@ -57,7 +62,9 @@ def __init__(self):

# Create the SocketIO server, long-polling is the default transport but websocket
# transport will be used if possible
server_sio_logger = framework_utils.get_logger(self.__class__.__name__, "sio_server")
server_sio_logger = framework_utils.get_logger(
self.__class__.__name__, "sio_server"
)
self.__server_sio = socketio.Server(
aysnc_mode="eventlet",
logger=server_sio_logger,
Expand All @@ -72,7 +79,9 @@ def __init__(self):
# events client.
# These are special client/server namespaces, do not use the register_client_namespace
# for these.
client_sio_logger = framework_utils.get_logger(self.__class__.__name__, "sio_client")
client_sio_logger = framework_utils.get_logger(
self.__class__.__name__, "sio_client"
)
self.__alias_events_client_sio = socketio.Client(
logger=client_sio_logger, engineio_logger=client_sio_logger
)
Expand All @@ -82,7 +91,6 @@ def __init__(self):
# Create the WSGI middleware for the SocketIO server
self.__app = socketio.WSGIApp(self.__server_sio, static_files={})


# Properties
# ----------------------------------------------------------------------------------------

Expand Down Expand Up @@ -129,9 +137,13 @@ def start_server(self, host=None, port=None, max_retries=None):
# Already started
host_in_use, port_in_use = self.__server_socket.getsockname()
if host is not None and host != host_in_use:
raise ServerAlreadyRunning("Server already running on {host_in_use}:{port_in_use}. Server must be stopped first.")
raise ServerAlreadyRunning(
"Server already running on {host_in_use}:{port_in_use}. Server must be stopped first."
)
if port is not None and port != port_in_use:
raise ServerAlreadyRunning("Server already running on {host_in_use}:{port_in_use}. Server must be stopped first.")
raise ServerAlreadyRunning(
"Server already running on {host_in_use}:{port_in_use}. Server must be stopped first."
)
return True

# First, find an open port on the host for the server socket to listen on.
Expand Down Expand Up @@ -236,7 +248,9 @@ def register_client_namespace(self, client_name, client_info):

namespace_handler = AliasServerNamespace(client_name)
if namespace_handler.namespace == AliasEventsServerNamespace.get_namespace():
raise ClientNameReservered("Client name '{client_name}' is reserved. Use a different name.")
raise ClientNameReservered(
"Client name '{client_name}' is reserved. Use a different name."
)

self.__server_sio.register_namespace(namespace_handler)

Expand Down Expand Up @@ -291,13 +305,15 @@ def bootstrap_client(self, client, client_info=None):
# this reason it is currently turned off. Ideally we can store an encryption key
# in the ShotGrid database or a key vault. For ShotGrid clients, this is not an
# issue because the toolkit manager should be used to start the ShotGrid engine.
#
#
# client_info = client_info or {}
# client_exec_path = os.environ.get("ALIAS_PLUGIN_CLIENT_EXECPATH")
# if client_exec_path:
# client_info["exec_path"] = client_exec_path

pipeline_config_id = os.environ.get("ALIAS_PLUGIN_CLIENT_SHOTGRID_PIPELINE_CONFIG_ID")
pipeline_config_id = os.environ.get(
"ALIAS_PLUGIN_CLIENT_SHOTGRID_PIPELINE_CONFIG_ID"
)
entity_type = os.environ.get("ALIAS_PLUGIN_CLIENT_SHOTGRID_ENTITY_TYPE")
entity_id = os.environ.get("ALIAS_PLUGIN_CLIENT_SHOTGRID_ENTITY_ID")
if pipeline_config_id and entity_type and entity_id:
Expand All @@ -324,7 +340,7 @@ def bootstrap_client(self, client, client_info=None):
python_exe = sys.executable

# Get the client executable and args
shotgrid_info = client["info"].get("shotgrid")
shotgrid_info = client["info"].get("shotgrid")
if shotgrid_info:
# Bootstrap using ShotGrid toolkit manager
pipeline_config_id = shotgrid_info["pipeline_config_id"]
Expand All @@ -351,7 +367,9 @@ def bootstrap_client(self, client, client_info=None):
]
else:
# Bootstrap by running the client executable
client_exe_path = framework_utils.decrypt_from_str(client["info"].get("exec_path"))
client_exe_path = framework_utils.decrypt_from_str(
client["info"].get("exec_path")
)
if not client_exe_path:
return False

Expand Down Expand Up @@ -417,7 +435,11 @@ def __open_server_socket(self, hostname, port, max_retries):

hostname = hostname or self.__default_hostname
port = port if port is not None and port >= 0 else self.__default_port
max_retry_count = max_retries if max_retries is not None and max_retries >= 0 else self.__max_retry_count
max_retry_count = (
max_retries
if max_retries is not None and max_retries >= 0
else self.__max_retry_count
)
server_socket = None
retry_count = 0
while server_socket is None and retry_count <= max_retry_count:
Expand Down
5 changes: 4 additions & 1 deletion python/tk_framework_alias/server/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
OPEN_ALIAS_API_NAME = "alias_api"
OPEN_MODEL_API_NAME = "alias_api_om"


def get_alias_version():
"""Return the Alias version."""

Expand All @@ -31,7 +32,9 @@ def get_alias_version():
def get_module_path(module_name, alias_version):
"""Return the file path to the Alias Python API module to use."""

api_folder_path = environment_utils.get_alias_distribution_directory(alias_version, sys.version_info.major, sys.version_info.minor)
api_folder_path = environment_utils.get_alias_distribution_directory(
alias_version, sys.version_info.major, sys.version_info.minor
)
if not api_folder_path or not os.path.exists(api_folder_path):
raise AliasPythonApiImportError(
"Failed to get Alias Python API module path for Alias {alias_version} and Python {py_version}".format(
Expand Down
Loading

0 comments on commit a2df4eb

Please sign in to comment.