pkglts package

Subpackages

Submodules

pkglts.config module

pkglts.config_management module

class pkglts.config_management.Config(*args, **kwds)[source]

Bases: dict

Object used to store both a templated version of the config as a dict interface its resolution and a jinja2 environment that reflect the config.

installed_options()[source]

List all installed options.

Returns:(iter of str)
load_extra()[source]

load option specific handlers.

Returns:None
render(txt)[source]

Use items in config to render text

Parameters:txt (str) – templated text to render
Returns:
same text where all templated parts have been replaced
by their values.
Return type:(str)
resolve()[source]

Try to resolve all templated items.

Returns:None
template()[source]
class pkglts.config_management.ConfigSection[source]

Bases: object

Small class to allow accessing parameters using the dot method instead of [‘param_name’] method

pkglts.config_management.get_pkg_config(rep='.')[source]

Read pkg_cfg file associated to this package.

Parameters:rep (str) – directory to search for info
Returns:Config initialized with pkg_config
Return type:(Config)
pkglts.config_management.upgrade_pkg_cfg_version(pkg_cfg, version)[source]

Upgrade the version of pkg_cfg file from version to version +1

Parameters:
  • pkg_cfg (dict of str, any) – package configuration
  • version (int) – current version of file
Returns:

any): a reference to an updated pkg_cfg

Return type:

(dict of str

pkglts.config_management.write_pkg_config(cfg, rep='.')[source]

Store config associated to this package on disk.

Parameters:
  • cfg (Config) – current working config
  • rep (str) – directory to search for info
Returns:

None

pkglts.data_access module

Set of function to work with resources that are located inside this package data

pkglts.data_access.get(file_name, mode='r')[source]

Retrieve the content of a given filename located in the data part of this package.

Parameters:
  • filename (-) – name of the file to read
  • mode (-) – mode to use to read the file either ‘r’ or ‘rb’
Returns:

content of the file red in ‘r’ mode

Return type:

(str)

pkglts.data_access.get_data_dir()[source]
pkglts.data_access.ls(dir_name)[source]

List all files and directories in dir_name located in the data part of this package.

Parameters:dir_name (-) – name of the directory to walk
Returns:
list the content of dir_name
without any specific order, items are (entity_name, is_directory)
Return type:(list of [str, bool])

pkglts.dependency module

class pkglts.dependency.Dependency(name, pkg_mng=None, channel=None)[source]

Bases: object

Simple container to keep track of all the required info to install a dependency.

fmt_requirement()[source]

Format dependency for requirements files

Returns:(str)

pkglts.file_management module

pkglts.file_management.write_file(pth, content)[source]

Write the content of a file on a local path and register associated hash for further modification tests.

Parameters:
  • pth (str) – path to the new created file
  • content (str) – content to write on disk

Returns:

pkglts.hash_management module

pkglts.hash_management.compute_hash(txt)[source]

Compute hash summary of a text

Parameters:txt (str) – content to hash
Returns:hash key
Return type:(str)
pkglts.hash_management.get_pkg_hash(rep='.')[source]

Read pkg_hash file associated to this package

Parameters:rep (str) – directory to search for info
Returns:
hash map of preserved sections in this
package
Return type:(dict of str, list)
pkglts.hash_management.modified_file_hash(pth, pkg_hash)[source]

Check whether a file complies with previously stored hash

Parameters:
  • pth (str) – path to file to test
  • pkg_hash (dict of str, list) – hash map of preserved sections in this package
Returns:

whether this file has been modified or not

Return type:

(bool)

pkglts.hash_management.pth_as_key(pth)[source]

Normalize path to enable to use them as keys

Parameters:pth (str) – path to normalize
Returns:(str)
pkglts.hash_management.write_pkg_hash(pkg_hash, rep='.')[source]

Store hash associated to this package on disk.

Parameters:
  • pkg_hash (dict of str, list) – hash map of preserved sections in this package
  • rep (str) – directory to search for info
Returns:

None

pkglts.local module

Regroup set of functions that make use of local environment inside a package. Just a way to normalize pre defined paths.

pkglts.local.init_namespace_dir(pth, cfg)[source]

Populate a directory with specific __init__.py for namespace packages.

Parameters:
  • pth (str) – path in which to create the files
  • cfg (Config) – current package configuration
Returns:

None

pkglts.local.pkg_full_name(cfg)[source]

Compute name of src dir according to pkgname and namespace in environment

Parameters:cfg (Config) – current package configuration
Returns:(str)
pkglts.local.src_dir(cfg)[source]

Compute name of src dir according to pkgname and namespace in environment

Parameters:cfg (Config) – current package configuration
Returns:(str)

pkglts.logging_tools module

pkglts.manage module

Contains functions to manage the structure of the package.

Use ‘setup.py’ for common tasks.

pkglts.manage.add_option(name, cfg)[source]

Add a new option to this package.

Notes: See the list of available options online

Parameters:
  • name (str) – name of option to add
  • cfg (Config) – current package configuration
Returns:

updated package configuration

Return type:

(Config)

pkglts.manage.clean(rep='.')[source]

Thorough cleaning of all arborescence rooting at rep.

Todo: exception list instead of hardcoded one

Parameters:rep (str) – default ”.”, top directory to clean
Returns:None
pkglts.manage.init_pkg(rep='.')[source]

Initialise a package in given directory.

Parameters:rep (str) – directory to create pkg into, default current
Returns:None
pkglts.manage.install_example_files(option, cfg, target='.')[source]

Install example files associated to an option.

Parameters:
  • option (str) – name of option
  • cfg (Config) – current package configuration
  • target (str) – target directory to write into
Returns:

whether operation succeeded or not

Return type:

(bool)

pkglts.manage.regenerate_option(cfg, name, target='.', overwrite=False)[source]

Call the regenerate function of a given option

Parameters:
  • cfg (Config) – current package configuration
  • name – (str) name of option
  • target – (str) target directory to write into
  • overwrite (bool) – default False, whether or not to overwrite user modified files
Returns:

None

pkglts.manage.regenerate_package(cfg, target='.', overwrite=False)[source]

Rebuild all automatically generated files.

Parameters:
  • cfg (Config) – current package configuration
  • target (str) – target directory to write into
  • overwrite (bool) – default False, whether or not to overwrite user modified files
Returns:

None

pkglts.manage_script module

pkglts.manage_script.action_add(*args, **kwds)[source]

Add new options in the package.

pkglts.manage_script.action_clean(*args, **kwds)[source]

Clean package of all un necessary files.

pkglts.manage_script.action_clear(*args, **kwds)[source]

Attempt to free the package from pkglts interactions.

pkglts.manage_script.action_example(*args, **kwds)[source]

Install example files associated with options.

pkglts.manage_script.action_info(*args, **kwds)[source]

Display info on package for debug purpose.

pkglts.manage_script.action_init(*args, **kwds)[source]

Initialize environment for use of pkglts.

pkglts.manage_script.action_regenerate(*args, **kwds)[source]

Regenerate all files in the package.

pkglts.manage_script.action_remove(*args, **kwds)[source]

Remove options from the package.

pkglts.manage_script.action_update(*args, **kwds)[source]

Check if a new version of pkglts is available.

pkglts.manage_script.main()[source]

pkglts.manage_tools module

Specific helper function for manage script

pkglts.manage_tools.check_option_parameters(name, cfg)[source]

Check that the parameters associated to an option are valid.

Try to import Check function in option dir.

Parameters:
  • name (str) – option name
  • cfg (Config) – current package configuration
pkglts.manage_tools.ensure_installed_packages(requirements, msg, cfg)[source]

Ensure all packages in requirements are installed.

If not, ask user permission to install them.

Parameters:
  • requirements (list of str) – list of package names to install if needed
  • msg (str) – error message to print
  • cfg (Config) – current package configuration
Returns:

whether all required packages are installed or not

Return type:

(bool)

pkglts.manage_tools.regenerate_dir(src_dir, tgt_dir, cfg, overwrite_file)[source]

Walk all files in src_dir and create/update them on tgt_dir

Parameters:
  • src_dir (str) – path to reference files
  • tgt_dir (str) – path to target where files will be written
  • cfg (Config) – current package configuration
  • overwrite_file (dict of str, bool) – whether or not to overwrite some files
Returns:

hash key of preserved sections

Return type:

(dict of str, map)

pkglts.manage_tools.update_opt(name, cfg)[source]

Update an option of this package.

Notes: If the option does not exists yet, add it first.
See the list of available option online
Parameters:
  • name (str) – name of option to add
  • cfg (Config) – current package configuration

pkglts.option_tools module

Some helpers for options

class pkglts.option_tools.Option[source]

Bases: object

Base class to store information associated with an option

check(*args, **kwds)[source]
environment_extensions(*args, **kwds)[source]
files_dir()[source]
from_entry_point(ep)[source]
regenerate(*args, **kwds)[source]
require(*args, **kwds)[source]
update_parameters(cfg)[source]
pkglts.option_tools.find_available_options()[source]
pkglts.option_tools.get_user_permission(action_name, default_true=True)[source]

pkglts.templating module

class pkglts.templating.TplBlock[source]

Bases: object

Simple container for templated blocks.

pkglts.templating.parse_source(txt)[source]

Parse text to find preserved blocks

Parameters:txt (str) – full text to parse
Returns:
ordered list of blocks:
  • block_id (or None if content is not preserved
  • line start before start for preserved content
  • content
  • line start before end for preserved content
Return type:(list of [str, str, str, str])
pkglts.templating.render(cfg, src_pth, tgt_pth)[source]

Render src_pth templated file into tgt_pth

Notes: keeps ‘preserved’ block structure

Parameters:
  • cfg (Config) – current package configuration
  • src_pth (str) – path to reference file
  • tgt_pth (str) – path to potentially non existent yet target file
Returns:

key, cnt for preserved blocks

Return type:

(list of [str, str])

pkglts.tree_ascii_fmt module

pkglts.tree_ascii_fmt.fmt_tree(dname)[source]
pkglts.tree_ascii_fmt.nn(cfg, pth)[source]
pkglts.tree_ascii_fmt.tree(dname, padding, txt)[source]

pkglts.version module

pkglts.version.major = 2

(int) Version major component.

pkglts.version.minor = 1

(int) Version minor component.

pkglts.version.post = 0

(int) Version post or bugfix component.

Module contents