Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 34 additions & 32 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# :coding: utf-8
# :copyright: Copyright (c) 2014 ftrack

'''ftrack Python API documentation build configuration file.'''
"""ftrack Python API documentation build configuration file."""

import os
import re
Expand All @@ -11,89 +11,91 @@

# Extensions.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.extlinks',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.viewcode',
'lowdown'
"sphinx.ext.autodoc",
"sphinx.ext.extlinks",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"lowdown",
]


# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = u'ftrack Python API'
copyright = u'2014, ftrack'
project = "ftrack Python API"
copyright = "2014, ftrack"

# contents of docs/conf.py
try:
release = get_distribution('ftrack-python-api').version
release = get_distribution("ftrack-python-api").version
# take major/minor/patch
VERSION = '.'.join(release.split('.')[:3])
VERSION = ".".join(release.split(".")[:3])
except DistributionNotFound:
# package is not installed
VERSION = 'Unknown version'
# package is not installed
VERSION = "Unknown version"

version = VERSION
release = VERSION

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_template']
exclude_patterns = ["_template"]

# A list of prefixes to ignore for module listings.
modindex_common_prefix = [
'ftrack_api.'
]
modindex_common_prefix = ["ftrack_api."]

# -- HTML output --------------------------------------------------------------

if not os.environ.get('READTHEDOCS', None) == 'True':
if not os.environ.get("READTHEDOCS", None) == "True":
# Only import and set the theme if building locally.
import sphinx_rtd_theme

html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

html_static_path = ['_static']
html_style = 'ftrack.css'
html_static_path = ["_static"]
html_style = "ftrack.css"

# If True, copy source rst files to output for reference.
html_copy_source = True


# -- Autodoc ------------------------------------------------------------------

autodoc_default_options = {"members": None, 'undoc-members': None, 'inherited-members': None}
autodoc_member_order = 'bysource'
autodoc_default_options = {
"members": None,
"undoc-members": None,
"inherited-members": None,
}
autodoc_member_order = "bysource"


def autodoc_skip(app, what, name, obj, skip, options):
'''Don't skip __init__ method for autodoc.'''
if name == '__init__':
"""Don't skip __init__ method for autodoc."""
if name == "__init__":
return False

return skip


# -- Intersphinx --------------------------------------------------------------

intersphinx_mapping = {
'python': ('http://docs.python.org/', None)
}
intersphinx_mapping = {"python": ("http://docs.python.org/", None)}


# -- Todos ---------------------------------------------------------------------

todo_include_todos = os.environ.get('FTRACK_DOC_INCLUDE_TODOS', False) == 'True'
todo_include_todos = os.environ.get("FTRACK_DOC_INCLUDE_TODOS", False) == "True"


# -- Setup --------------------------------------------------------------------


def setup(app):
app.connect('autodoc-skip-member', autodoc_skip)
app.connect("autodoc-skip-member", autodoc_skip)
10 changes: 5 additions & 5 deletions doc/resource/example_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@


def register(session, **kw):
'''Register plugin. Called when used as an plugin.'''
logger = logging.getLogger('com.example.example-plugin')
"""Register plugin. Called when used as an plugin."""
logger = logging.getLogger("com.example.example-plugin")

# Validate that session is an instance of ftrack_api.Session. If not,
# assume that register is being called from an old or incompatible API and
# return without doing anything.
if not isinstance(session, ftrack_api.session.Session):
logger.debug(
'Not subscribing plugin as passed argument {0!r} is not an '
'ftrack_api.Session instance.'.format(session)
"Not subscribing plugin as passed argument {0!r} is not an "
"ftrack_api.Session instance.".format(session)
)
return

# Perform your logic here, such as subscribe to an event.
pass

logger.debug('Plugin registered')
logger.debug("Plugin registered")
25 changes: 12 additions & 13 deletions doc/resource/example_plugin_using_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,32 @@


def register_with_session_ready(event):
'''Called when session is ready to be used.'''
logger = logging.getLogger('com.example.example-plugin')
logger.debug('Session ready.')
session = event['data']['session']
"""Called when session is ready to be used."""
logger = logging.getLogger("com.example.example-plugin")
logger.debug("Session ready.")
session = event["data"]["session"]

# Session is now ready and can be used to e.g. query objects.
task = session.query('Task').first()
print(task['name'])
task = session.query("Task").first()
print(task["name"])


def register(session, **kw):
'''Register plugin. Called when used as an plugin.'''
logger = logging.getLogger('com.example.example-plugin')
"""Register plugin. Called when used as an plugin."""
logger = logging.getLogger("com.example.example-plugin")

# Validate that session is an instance of ftrack_api.Session. If not,
# assume that register is being called from an old or incompatible API and
# return without doing anything.
if not isinstance(session, ftrack_api.session.Session):
logger.debug(
'Not subscribing plugin as passed argument {0!r} is not an '
'ftrack_api.Session instance.'.format(session)
"Not subscribing plugin as passed argument {0!r} is not an "
"ftrack_api.Session instance.".format(session)
)
return

session.event_hub.subscribe(
'topic=ftrack.api.session.ready',
register_with_session_ready
"topic=ftrack.api.session.ready", register_with_session_ready
)

logger.debug('Plugin registered')
logger.debug("Plugin registered")
15 changes: 7 additions & 8 deletions resource/plugin/configure_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@


def configure_locations(event):
'''Configure locations for session.'''
session = event['data']['session']
"""Configure locations for session."""
session = event["data"]["session"]

# Find location(s) and customise instances.
#
Expand All @@ -20,20 +20,19 @@ def configure_locations(event):


def register(session):
'''Register plugin with *session*.'''
logger = logging.getLogger('ftrack_plugin:configure_locations.register')
"""Register plugin with *session*."""
logger = logging.getLogger("ftrack_plugin:configure_locations.register")

# Validate that session is an instance of ftrack_api.Session. If not, assume
# that register is being called from an old or incompatible API and return
# without doing anything.
if not isinstance(session, ftrack_api.Session):
logger.debug(
'Not subscribing plugin as passed argument {0} is not an '
'ftrack_api.Session instance.'.format(session)
"Not subscribing plugin as passed argument {0} is not an "
"ftrack_api.Session instance.".format(session)
)
return

session.event_hub.subscribe(
'topic=ftrack.api.session.configure-location',
configure_locations
"topic=ftrack.api.session.configure-location", configure_locations
)
19 changes: 9 additions & 10 deletions resource/plugin/construct_entity_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@


class Factory(ftrack_api.entity.factory.StandardFactory):
'''Entity class factory.'''
"""Entity class factory."""

def create(self, schema, bases=None):
'''Create and return entity class from *schema*.'''
"""Create and return entity class from *schema*."""
# Optionally change bases for class to be generated.
cls = super(Factory, self).create(schema, bases=bases)

Expand All @@ -20,27 +20,26 @@ def create(self, schema, bases=None):


def register(session):
'''Register plugin with *session*.'''
logger = logging.getLogger('ftrack_plugin:construct_entity_type.register')
"""Register plugin with *session*."""
logger = logging.getLogger("ftrack_plugin:construct_entity_type.register")

# Validate that session is an instance of ftrack_api.Session. If not, assume
# that register is being called from an old or incompatible API and return
# without doing anything.
if not isinstance(session, ftrack_api.Session):
logger.debug(
'Not subscribing plugin as passed argument {0!r} is not an '
'ftrack_api.Session instance.'.format(session)
"Not subscribing plugin as passed argument {0!r} is not an "
"ftrack_api.Session instance.".format(session)
)
return

factory = Factory()

def construct_entity_type(event):
'''Return class to represent entity type specified by *event*.'''
schema = event['data']['schema']
"""Return class to represent entity type specified by *event*."""
schema = event["data"]["schema"]
return factory.create(schema)

session.event_hub.subscribe(
'topic=ftrack.api.session.construct-entity-type',
construct_entity_type
"topic=ftrack.api.session.construct-entity-type", construct_entity_type
)
17 changes: 4 additions & 13 deletions source/ftrack_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,18 @@


def mixin(instance, mixin_class, name=None):
'''Mixin *mixin_class* to *instance*.
"""Mixin *mixin_class* to *instance*.

*name* can be used to specify new class name. If not specified then one will
be generated.

'''
"""
if name is None:
name = '{0}{1}'.format(
instance.__class__.__name__, mixin_class.__name__
)
name = "{0}{1}".format(instance.__class__.__name__, mixin_class.__name__)

# Check mixin class not already present in mro in order to avoid consistent
# method resolution failure.
if mixin_class in instance.__class__.mro():
return

instance.__class__ = type(
name,
(
mixin_class,
instance.__class__
),
{}
)
instance.__class__ = type(name, (mixin_class, instance.__class__), {})
Loading