silx.resources: Project resources access

Access project’s data and documentation files.

All access to data and documentation files MUST be made through the functions of this modules to ensure access across different distribution schemes:

  • Installing from source or from wheel

  • Installing package as a zip (through the use of pkg_resources)

  • Linux packaging willing to install data files (and doc files) in alternative folders. In this case, this file must be patched.

  • Frozen fat binary application using silx (frozen with cx_Freeze or py2app). This needs special care for the resource files in the setup:

    • With cx_Freeze, add silx/resources to include_files:

      import silx.resources
      silx_include_files = (os.path.dirname(silx.resources.__file__),
                            os.path.join('silx', 'resources'))
      setup(...
            options={'build_exe': {'include_files': [silx_include_files]}}
            )
      
    • With py2app, add silx in the packages list of the py2app options:

      setup(...
            options={'py2app': {'packages': ['silx']}}
            )
      
register_resource_directory(name, package_name, forced_path=None)[source]

Register another resource directory to the available list.

By default only the directory “silx” is available.

New in version 0.6.

Parameters:
  • name (str) – Name of the resource directory. It is used on the resource name to specify the resource directory to use. The resource “silx:foo.png” will use the “silx” resource directory.
  • package_name (str) – Python name of the package containing resources. For example “silx.resources”.
  • forced_path (str) – Path containing the resources. If specified pkg_resources nor package_name will be used For example “silx.resources”.
Raises:

ValueError – If the resource directory name already exists.

list_dir(resource)[source]

List the content of a resource directory.

Result are not prefixed by the resource name.

The resource name can be prefixed by the name of a resource directory. For example “silx:foo.png” identify the resource “foo.png” from the resource directory “silx”. See also register_resource_directory().

Parameters:resource (str) – Name of the resource directory to list
Returns:list of name contained in the directory
Return type:List
is_dir(resource)[source]

True is the resource is a resource directory.

The resource name can be prefixed by the name of a resource directory. For example “silx:foo.png” identify the resource “foo.png” from the resource directory “silx”. See also register_resource_directory().

Parameters:resource (str) – Name of the resource
Return type:bool
exists(resource)[source]

True is the resource exists.

Parameters:resource (str) – Name of the resource
Return type:bool
resource_filename(resource)[source]

Return filename corresponding to resource.

The existence of the resource is not checked.

The resource name can be prefixed by the name of a resource directory. For example “silx:foo.png” identify the resource “foo.png” from the resource directory “silx”. See also register_resource_directory().

Parameters:resource (str) – Resource path relative to resource directory using ‘/’ path separator. It can be either a file or a directory.
Raises:ValueError – If the resource name uses an unregistred resource directory name
Returns:Absolute resource path in the file system
Return type:str
class ExternalResources(project, url_base, env_key=None, timeout=60)[source]

Utility class which allows to download test-data from www.silx.org and manage the temporary data during the tests.

getfile(filename)[source]

Downloads the requested file from web-server available at https://www.silx.org/pub/silx/

Param:relative name of the image.
Returns:full path of the locally saved file.
getdir(dirname)[source]

Downloads the requested tarball from the server https://www.silx.org/pub/silx/ and unzips it into the data directory

Param:relative name of the image.
Returns:list of files with their full path.
download_all(imgs=None)[source]

Download all data needed for the test/benchmarks

Parameters:imgs – list of files to download, by default all
Returns:list of path with all files