Stash Software API  2.0.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
sStashPackage.packageLib.Package Class Reference

[ CLASS ] - Class to operate on Stash packages. More...

Inheritance diagram for sStashPackage.packageLib.Package:

Public Member Functions

def __init__ (self, absolutePath=None, setByStack=False)
 Constructor. More...
 
def __str__ (self)
 String representation. More...
 
def setPackage (self, absolutePath=None)
 Set package. More...
 
def clear (self)
 Clear the instance. More...
 
def getLocalPath (self, relativePath)
 Get absolute path of given relativePath. More...
 
def getLocalHelpFile (self, folder)
 Get absolute path of the requested local help file. More...
 
def getPackagesLocation (self)
 Get location of the packages. More...
 
def getPythonPath (self)
 Get the Python path of the package in absolutePath/packageName/python format. More...
 
def getDefaultPythonPackagePath (self)
 Get the default Python package path of the package in absolutePath/packageName/python/packageName format. More...
 
def getPythonPackagePath (self, pythonPackageName=None)
 Get the Python package path for given Python package name in absolutePath/packageName/python/packageName format. More...
 
def getPythonPackages (self, ignoreDefault=False)
 Get python package names contained by this package. More...
 
def getFiles (self, folder, pythonPackageName=None, absPath=True, extension=None, suffix=None)
 Get files for the requested local folder of the package. More...
 
def getPackageReleaseRelativePath (self)
 Get relative release path of the package. More...
 
def getReleaseFiles (self, relativePath=True)
 Get files to be released. More...
 
def getAllDependencies (self)
 Get all dependent packages used by this package. More...
 
def getReleaseData (self)
 Get release data for this package. More...
 
def runUnitTests (self, pythonPackageName=None)
 Run unit tests of the package. More...
 
def getLineOfCode (self)
 Get line of code contained by this package. More...
 
def createPythonModule (self, pythonModuleName, pythonPackageName=None)
 Create a Python module for the given Python package of the package. More...
 
def createPythonPackage (self, pythonPackageName)
 Create a Python module for the given Python package. More...
 
def asStr (self)
 Get string representation of the class. More...
 
def asHTML (self)
 Get HTML representation of the package. More...
 
def asDict (self)
 Get package information as a dict instance. More...
 
Properties
def name (self)
 Property. More...
 
def version (self)
 Property. More...
 
def description (self)
 Property. More...
 
def keywords (self)
 Property. More...
 
def platforms (self)
 Platforms. More...
 
def documents (self)
 Documents. More...
 
def applications (self)
 Applications. More...
 
def pythonVersions (self)
 Python versions. More...
 
def isActive (self)
 Property. More...
 
def isExternal (self)
 Property. More...
 
def developers (self)
 Property. More...
 
def dependentPackages (self)
 Property. More...
 
def pythonPackages (self)
 Property. More...
 
def isVersioned (self)
 Property. More...
 
def path (self)
 Property. More...
 

Static Public Member Functions

def getRootOfThisPackage ()
 Get the root of this particular package. More...
 
def getRootFromStack ()
 Get the root path of the package in use by using stack. More...
 
def getRootFromPath (absolutePath)
 Get the root path of the package from given path. More...
 
def isRootOfAPackage (absolutePath)
 Check whether the given path is root of a package. More...
 
def isPackageNameValid (name)
 Check whether the given package name is valid. More...
 
def findInfoFile (absolutePath)
 Find package info Python file from given path. More...
 
def findInfoModule (absolutePath)
 Find, import package info Python module and return it. More...
 
def removePythonObjects (verbose=False)
 Remove all files with .pyc and .pyo extension recursively in python path. More...
 
def list ()
 List all packages. More...
 
def find (name)
 Find package with given name. More...
 
def findPythonPackage (name)
 Find Python package with given name. More...
 
def listAsDict ()
 List all packages as dict instances. More...
 
def listAllCommands (includeBinary=False)
 List all commands in packages. More...
 
def create (name, description=None, path=None, isExternal=False, createBin=True, createLib=True, createBuild=True, createConfig=True, createDoc=True, createData=True, createResources=True, createSource=True, createTemp=True, createTest=True, createHoudini=True, createKatana=True, createMari=True, createMaya=True, createNuke=True, extras=True)
 Create a package. More...
 

Static Public Attributes

string NAME_PREFIX = ''
 [ str ] - Prefix of the package names. More...
 
string PACKAGE_NAME_REGEX = r'[a-z]{1,}[A-Z]{1,}\S+'
 [ str ] - Regular Expression for a valid package name. More...
 
string CURRENT_VERSION = '0.0.0'
 [ str ] - Current version. More...
 

Detailed Description

[ CLASS ] - Class to operate on Stash packages.

Constructor & Destructor Documentation

◆ __init__()

def sStashPackage.packageLib.Package.__init__ (   self,
  absolutePath = None,
  setByStack = False 
)

Constructor.

You can pass True via setByStack argument if you want to set the package by using stack. You do not need to provide a value for setByStack argument if you provide a path via absolutePath argument.

If you don't provide any value for absolutePath and setByStack no package will be set. You can also use Package.setPackage method.

Parameters
absolutePath[ str | None | in ] - Absolute path of package info file.
setByStack[ bool | False | in ] - Whether to set package by using stack.
Exceptions
N/A
Returns
None - None.

Member Function Documentation

◆ __str__()

def sStashPackage.packageLib.Package.__str__ (   self)

String representation.

Exceptions
N/A
Returns
str - String representation.

◆ name()

def sStashPackage.packageLib.Package.name (   self)

Property.

Exceptions
N/A
Returns
str - Name.

◆ version()

def sStashPackage.packageLib.Package.version (   self)

Property.

Exceptions
N/A
Returns
str - Version.

◆ description()

def sStashPackage.packageLib.Package.description (   self)

Property.

Exceptions
N/A
Returns
str - Description.

◆ keywords()

def sStashPackage.packageLib.Package.keywords (   self)

Property.

Exceptions
N/A
Returns
list of str - Keywords.

◆ platforms()

def sStashPackage.packageLib.Package.platforms (   self)

Platforms.

Exceptions
N/A
Returns
list of str - Platforms.

◆ documents()

def sStashPackage.packageLib.Package.documents (   self)

Documents.

Exceptions
N/A
Returns
list of dict - Keys of dict instances are: title, url.

◆ applications()

def sStashPackage.packageLib.Package.applications (   self)

Applications.

Exceptions
N/A
Returns
list of str - Applications.

◆ pythonVersions()

def sStashPackage.packageLib.Package.pythonVersions (   self)

Python versions.

Exceptions
N/A
Returns
list of str - Python versions.

◆ isActive()

def sStashPackage.packageLib.Package.isActive (   self)

Property.

Exceptions
N/A
Returns
bool - Whether this package is active (in use).

◆ isExternal()

def sStashPackage.packageLib.Package.isExternal (   self)

Property.

Exceptions
N/A
Returns
bool - Whether this package is external.

◆ developers()

def sStashPackage.packageLib.Package.developers (   self)

Property.

Exceptions
N/A
Returns
list of str - Developers.

◆ dependentPackages()

def sStashPackage.packageLib.Package.dependentPackages (   self)

Property.

Exceptions
N/A
Returns
list of str - Dependent packages.

◆ pythonPackages()

def sStashPackage.packageLib.Package.pythonPackages (   self)

Property.

Exceptions
N/A
Returns
list of str - Python packages contained by this package.

◆ isVersioned()

def sStashPackage.packageLib.Package.isVersioned (   self)

Property.

Exceptions
N/A
Returns
bool - Result.

◆ path()

def sStashPackage.packageLib.Package.path (   self)

Property.

Exceptions
N/A
Returns
str - Path.

◆ setPackage()

def sStashPackage.packageLib.Package.setPackage (   self,
  absolutePath = None 
)

Set package.

A package info Python module can be provided for absolutePath argument.

Method finds package info Python file by using given absolutePath. If absolutePath argument is not provided, stack will be used (by invoking sStashPackage.packageLib.Package.getRootFromStack() method) to find the package info Python file.

Parameters
absolutePath[ str, module | None | in ] - Absolute path of package info Python file or its module.
Exceptions
AttributeError- If info module does not have any of required attributes.
sStashPackage.exceptionLib.PackageNameError- If folder name of the package doesn't match with the name in the package info module.
Returns
bool - Result.

◆ clear()

def sStashPackage.packageLib.Package.clear (   self)

Clear the instance.

Exceptions
N/A
Returns
None - None.

◆ getLocalPath()

def sStashPackage.packageLib.Package.getLocalPath (   self,
  relativePath 
)

Get absolute path of given relativePath.

Method doesn't check whether the returned path exists.

Parameters
relativePath[ str | None | in ] - Structure from sStashPackage.packageLib.FolderStructure (i.e. sStashPackage.packageLib.FolderStructure.kBinLinux).
Exceptions
N/A
Returns
str - Absolute path of the requested folder.
None - If no package has been set.

◆ getLocalHelpFile()

def sStashPackage.packageLib.Package.getLocalHelpFile (   self,
  folder 
)

Get absolute path of the requested local help file.

Parameters
folder[ str | None | in ] - Structure from sStashPackage.packageLib.FolderStructure (i.e. sStashPackage.packageLib.FolderStructure.kDocPythonAPIReference).
Exceptions
N/A
Returns
str - Absolute path of the help file.
None - If help file doesn't exist.
None - If no package has been set.

◆ getPackagesLocation()

def sStashPackage.packageLib.Package.getPackagesLocation (   self)

Get location of the packages.

Since released packages have different path, this method can be used to get the packages path of the package. This is the path where all the packages will be under for any given environment.

Exceptions
N/A
Returns
str - Absolute path of the location of the package.
None - If no package has been set.

◆ getPythonPath()

def sStashPackage.packageLib.Package.getPythonPath (   self)

Get the Python path of the package in absolutePath/packageName/python format.

Exceptions
N/A
Returns
str - Absolute path.
None - If no package has been set.

◆ getDefaultPythonPackagePath()

def sStashPackage.packageLib.Package.getDefaultPythonPackagePath (   self)

Get the default Python package path of the package in absolutePath/packageName/python/packageName format.

Default Python package name is the name of the package itself.

Exceptions
N/A
Returns
str - Absolute path.
None - If no package has been set.

◆ getPythonPackagePath()

def sStashPackage.packageLib.Package.getPythonPackagePath (   self,
  pythonPackageName = None 
)

Get the Python package path for given Python package name in absolutePath/packageName/python/packageName format.

If pythonPackageName argument is not provided, default name of the package will be used.

Parameters
pythonPackageName[ str | None | in ] - Name of the Python package.
Exceptions
N/A
Returns
str - Absolute path.
None - If no package has been set.
None - If no Python package with given name contained by this package.

◆ getPythonPackages()

def sStashPackage.packageLib.Package.getPythonPackages (   self,
  ignoreDefault = False 
)

Get python package names contained by this package.

Parameters
ignoreDefault[ bool | False | in ] - Whether to ignore default package, which is the package with the same name as this package.
Exceptions
N/A
Returns
list of str - Package names, empty if no package has been set.

◆ getFiles()

def sStashPackage.packageLib.Package.getFiles (   self,
  folder,
  pythonPackageName = None,
  absPath = True,
  extension = None,
  suffix = None 
)

Get files for the requested local folder of the package.

If sStashPackage.packageLib.Package.FolderStructure.kPython is provided for folder argument, folder will be set as absolutePath/packageName/python/pythonPackageName.

If no value provided for pythonPackageName argument, name of the package will be used.

Parameters
folder[ str | None | in ] - Structure from sStashPackage.packageLib.Package.FolderStructure (i.e. sStashPackage.packageLib.FolderStructure.kPython).
pythonPackageName[ str | None | in ] - Name of the Python package.
absPath[ bool | True | in ] - Whether to list files with absolute path.
extension[ str | None | in ] - List files only with given extension.
suffix[ str | None | in ] - List files only with given suffix.
Exceptions
IOError- If requested local folder doesn't exist.
Returns
list of str - Files.
None - If no package has been set.
None - If no file is found.

◆ getPackageReleaseRelativePath()

def sStashPackage.packageLib.Package.getPackageReleaseRelativePath (   self)

Get relative release path of the package.

This is the release destination path that includes the version.

Return format: packageName/version/packageName (i.e. sQtWidgets/1.4.8/sQtWidgets)

Exceptions
N/A
Returns
str - Relative path.

◆ getReleaseFiles()

def sStashPackage.packageLib.Package.getReleaseFiles (   self,
  relativePath = True 
)

Get files to be released.

Parameters
relativePath[ bool | True | in ] - Whether the file path will be relative to root of the package.
Exceptions
N/A
Returns
list of str - Path of the files.
None - If no package has been set.

◆ getAllDependencies()

def sStashPackage.packageLib.Package.getAllDependencies (   self)

Get all dependent packages used by this package.

Exceptions
N/A
Returns
list of str - Dependencies.
None - If there is no dependencies.
None - If no package has been set.

◆ getReleaseData()

def sStashPackage.packageLib.Package.getReleaseData (   self)

Get release data for this package.

Exceptions
N/A
Returns
dict - Dict instance that contains release data.
None - If this package doesn't have release Python module.
None - If release Python module doesn't have getReleaseData function.
None - If no package has been set.

◆ runUnitTests()

def sStashPackage.packageLib.Package.runUnitTests (   self,
  pythonPackageName = None 
)

Run unit tests of the package.

Return list contains a dict object for each unit test class. The dict instances contain the following data:

Key Data Type Description
module str Absolute import path of the Python test module.
class str Name of the unit test class.
count int How many tests have been run.
errors list Errors.
failures list Failures.
output str Output.

If no value provided for pythonPackageName argument, Python package with the same name as the package will be used.

Parameters
pythonPackageName[ str | None | in ] - Name of the Python package, which the tests will be run for.
Exceptions
N/A
Returns
list of dict - Result.
None - If no package has been set.

◆ getLineOfCode()

def sStashPackage.packageLib.Package.getLineOfCode (   self)

Get line of code contained by this package.

Exceptions
N/A
Returns
dict - Keys are, python and cpp.
None - If no package has been set.

◆ createPythonModule()

def sStashPackage.packageLib.Package.createPythonModule (   self,
  pythonModuleName,
  pythonPackageName = None 
)

Create a Python module for the given Python package of the package.

Parameters
pythonModuleName[ str | None | in ] - Name of the Python module to be created.
pythonPackageName[ str | None | in ] - Name of the Python package under this package, which the Python module will be created for.
Exceptions
sStashPackage.exceptionLib.PackageLocationError- If this package is versioned.
IOError- If no relevant Python package found for Python module creation.
Returns
list of str - Absolute path of the created Python modules, first one is the module, second one is the unit test module.
None - If no package has been set.

◆ createPythonPackage()

def sStashPackage.packageLib.Package.createPythonPackage (   self,
  pythonPackageName 
)

Create a Python module for the given Python package.

Parameters
pythonPackageName[ str | None | in ] - Name of the Python package under this package, which the Python module will be created for.
Exceptions
sStashPackage.exceptionLib.PackageLocationError- If this package is versioned.
sStashPackage.exceptionLib.PythonPackageNameError- If a Python package with given name already exists under this package.
Returns
str - Absolute path of the created Python package.
None - If no package has been set.

◆ asStr()

def sStashPackage.packageLib.Package.asStr (   self)

Get string representation of the class.

Exceptions
N/A
Returns
str - Information about the package in human readable form.

◆ asHTML()

def sStashPackage.packageLib.Package.asHTML (   self)

Get HTML representation of the package.

This method provides information so it can be used on a GUI such as about dialog.

Exceptions
N/A
Returns
str - Information about the package in human readable form in HTML format.

◆ asDict()

def sStashPackage.packageLib.Package.asDict (   self)

Get package information as a dict instance.

Keys of the returned dict instance are available in sStashPackage.packageLib.InfoModuleAttribute enum class. Additionally PATH and IS_VERSIONED keys are dynamically added to the returned dict instance.

Exceptions
N/A
Returns
dict - Package information.

◆ getRootOfThisPackage()

def sStashPackage.packageLib.Package.getRootOfThisPackage ( )
static

Get the root of this particular package.

Exceptions
N/A
Returns
str - Absolute path of the root of this package.

◆ getRootFromStack()

def sStashPackage.packageLib.Package.getRootFromStack ( )
static

Get the root path of the package in use by using stack.

Stack path should contain a path something like absolutePath/packageName/python/additionalPath so method can obtain the root path of the package properly. Return path will be in absolutePath/packageName format.

Exceptions
N/A
Returns
str - Absolute path of the root of the package.
None - If method couldn't determine the root path.

◆ getRootFromPath()

def sStashPackage.packageLib.Package.getRootFromPath (   absolutePath)
static

Get the root path of the package from given path.

Return path will be in absolutePath/packageName format.

Parameters
absolutePath[ str | None | in ] - Path.
Exceptions
N/A
Returns
str - Absolute path of the root of the package.
None - If method fails to determine the path.

◆ isRootOfAPackage()

def sStashPackage.packageLib.Package.isRootOfAPackage (   absolutePath)
static

Check whether the given path is root of a package.

Following pattern will be checked: absolutePath/packageName

Parameters
absolutePath[ str | None | in ] - Path.
Exceptions
N/A
Returns
bool - Result.

◆ isPackageNameValid()

def sStashPackage.packageLib.Package.isPackageNameValid (   name)
static

Check whether the given package name is valid.

Parameters
name[ str | None | in ] - Name.
Exceptions
N/A
Returns
bool - Result.

◆ findInfoFile()

def sStashPackage.packageLib.Package.findInfoFile (   absolutePath)
static

Find package info Python file from given path.

Parameters
absolutePath[ str | None | in ] - Absolute path of package info file or an absolute path.
Exceptions
N/A
Returns
str - Absolute path of the package info Python file.
None - If method fails finding the file.

◆ findInfoModule()

def sStashPackage.packageLib.Package.findInfoModule (   absolutePath)
static

Find, import package info Python module and return it.

If given package is not in Python path, it will be added temporarily and will be removed after the package info Python module is imported.

Parameters
absolutePath[ None | None | in ] - Absolute path of package info Python file or an absolute path.
Exceptions
N/A
Returns
module - Package info Python module.
None - If no module found.

◆ removePythonObjects()

def sStashPackage.packageLib.Package.removePythonObjects (   verbose = False)
static

Remove all files with .pyc and .pyo extension recursively in python path.

Warning
DO NOT USE THIS METHOD AT ALL, IT HAS BEEN PROVIDED FOR INTERNAL USE ONLY.
Parameters
verbose[ bool | False | in ] - Display deleted files.
Exceptions
N/A
Returns
None - None.

◆ list()

def sStashPackage.packageLib.Package.list ( )
static

List all packages.

Method searches packages by using sys.path.

Exceptions
N/A
Returns
list of module - Imported package info Python modules.

◆ find()

def sStashPackage.packageLib.Package.find (   name)
static

Find package with given name.

Method finds the package with given name by searching Python paths. Please note, searching is case insensitive.

Parameters
name[ str | None | in ] - Name of the package to be found.
Exceptions
N/A
Returns
sStashPackage.packageLib.Package - If package found.
None - If no package found.

◆ findPythonPackage()

def sStashPackage.packageLib.Package.findPythonPackage (   name)
static

Find Python package with given name.

Method finds the Python package with given name by searching Python paths. If the Python package found and it is under a Stash package, an instance of sStashPackage.packageLib.Package class will return, which would represent the Stash package that contains the Python package.

Please note, searching is case sensitive.

Parameters
name[ str | None | in ] - Name of the Python package to be found.
Exceptions
N/A
Returns
sStashPackage.packageLib.Package - If Python package found.
None - If no Python package found.

◆ listAsDict()

def sStashPackage.packageLib.Package.listAsDict ( )
static

List all packages as dict instances.

Keys of the returned dict instances are available in sStashPackage.packageLib.InfoModuleAttribute enum class. Additionally PATH and IS_VERSIONED keys are dynamically added to the dict instance.

Exceptions
N/A
Returns
list of dict - Packages.

◆ listAllCommands()

def sStashPackage.packageLib.Package.listAllCommands (   includeBinary = False)
static

List all commands in packages.

Return dict instances contains the following keys.

  • package
  • command
  • description
Parameters
includeBinary[ bool | False | in ] - Whether to include binary commands (executables).
Exceptions
N/A
Returns
list of dict - Executables.

◆ create()

def sStashPackage.packageLib.Package.create (   name,
  description = None,
  path = None,
  isExternal = False,
  createBin = True,
  createLib = True,
  createBuild = True,
  createConfig = True,
  createDoc = True,
  createData = True,
  createResources = True,
  createSource = True,
  createTemp = True,
  createTest = True,
  createHoudini = True,
  createKatana = True,
  createMari = True,
  createMaya = True,
  createNuke = True,
  extras = True 
)
static

Create a package.

Current working directory will be used if path argument is not provided.

Parameters
name[ str | None | in ] - Name of the package.
description[ str | None | in ] - Description of the package.
path[ str | None | in ] - Absolute path where the package will be created.
isExternal[ bool | False | in ] - Whether the package is external.
createBin[ bool | False | in ] - Whether to create bin folder structure for the package.
createLib[ bool | False | in ] - Whether to create lib folder structure for the package.
createBuild[ bool | False | in ] - Whether to create build folder structure for the package.
createConfig[ bool | False | in ] - Whether to create config folder structure for the package.
createDoc[ bool | False | in ] - Whether to create doc folder structure for the package.
createData[ bool | False | in ] - Whether to create data folder structure for the package.
createResources[ bool | False | in ] - Whether to create resources folder structure for the package.
createSource[ bool | False | in ] - Whether to create source folder structure for the package.
createTemp[ bool | False | in ] - Whether to create temp folder structure for the package.
createTest[ bool | False | in ] - Whether to create unit test folder structure for the package.
createHoudini[ bool | False | in ] - Whether to create Houdini folder structure for the package.
createKatana[ bool | False | in ] - Whether to create Katana folder structure for the package.
createMari[ bool | False | in ] - Whether to create Mari folder structure for the package.
createMaya[ bool | False | in ] - Whether to create Maya folder structure for the package.
createNuke[ bool | False | in ] - Whether to create Nuke folder structure for the package.
extras[ bool | False | in ] - Create extra files, gitignore, README.md, etc.
Exceptions
sStashPackage.exceptionLib.PackageNameError- If provided package name doesn't match with the naming convention.
Returns
list of dict - Dict instances contain contain created paths and files.

Member Data Documentation

◆ NAME_PREFIX

string sStashPackage.packageLib.Package.NAME_PREFIX = ''
static

[ str ] - Prefix of the package names.

◆ PACKAGE_NAME_REGEX

string sStashPackage.packageLib.Package.PACKAGE_NAME_REGEX = r'[a-z]{1,}[A-Z]{1,}\S+'
static

[ str ] - Regular Expression for a valid package name.

◆ CURRENT_VERSION

string sStashPackage.packageLib.Package.CURRENT_VERSION = '0.0.0'
static

[ str ] - Current version.


The documentation for this class was generated from the following file: