pyscaffold package

Submodules

pyscaffold.info module

Provide general information about the system, user etc.

pyscaffold.info.email()[source]

Retrieve the user’s email

Returns:user’s email as string
pyscaffold.info.is_git_configured()[source]

Check if user.name and user.email is set globally in git

Returns:boolean
pyscaffold.info.is_git_installed()[source]

Check if git is installed

Returns:boolean
pyscaffold.info.project(args)[source]

Update user settings with the settings of an existing PyScaffold project

Parameters:args – command line parameters as argparse.Namespace
Returns:updated command line parameters as argparse.Namespace
pyscaffold.info.read_setup_cfg(args)[source]

Read setup.cfg (PyScaffold >= 2.0) for user settings

Parameters:args – command line parameters as argparse.Namespace
Returns:updated command line parameters as argparse.Namespace
pyscaffold.info.read_setup_py(args)[source]

Read setup.py (PyScaffold < 2.0) for user settings

Parameters:args – command line parameters as argparse.Namespace
Returns:updated command line parameters as argparse.Namespace
pyscaffold.info.username()[source]

Retrieve the user’s name

Returns:user’s name as string

pyscaffold.repo module

Functionality for working with a git repository

pyscaffold.repo.add_tag(project, tag_name, message=None)[source]

Add an (annotated) tag to the git repository.

Parameters:
  • project – path to the project as string
  • tag_name – name of the tag as string
  • message – optional tag message as string
pyscaffold.repo.git_tree_add(struct, prefix='')[source]

Adds recursively a directory structure to git

Parameters:
  • struct – directory structure as dictionary of dictionaries
  • prefix – prefix for the given directory structure as string
pyscaffold.repo.init_commit_repo(project, struct)[source]

Initialize a git repository

Parameters:
  • project – path to the project as string
  • struct – directory structure as dictionary of dictionaries
pyscaffold.repo.is_git_repo(folder)[source]

Check if a folder is a git repository

Parameters:folder – path as string

pyscaffold.runner module

Command-Line-Interface of PyScaffold

pyscaffold.runner.main(args)[source]

Main entry point of PyScaffold

Parameters:args – command line parameters as list of strings
pyscaffold.runner.parse_args(args)[source]

Parse command line parameters

Parameters:args – command line parameters as list of strings
Returns:command line parameters as argparse.Namespace
pyscaffold.runner.prepare_namespace(namespace_str)[source]

Check the validity of namespace_str and split it up into a list

Parameters:namespace_str – namespace as string, e.g. “com.blue_yonder”
Returns:list of namespaces, e.g. [“com”, “com.blue_yonder”]
pyscaffold.runner.run(*args, **kwargs)[source]

Entry point for setup.py

pyscaffold.shell module

Shell commands like git, django-admin.py etc.

class pyscaffold.shell.ShellCommand(command, shell=True, cwd=None)[source]

Bases: object

Shell command that can be called with flags like git(‘add’, ‘file’)

Parameters:
  • command – command to handle
  • shell – run the command in the shell
  • cwd – current working dir to run the command
pyscaffold.shell.called_process_error2exit_decorator(func)[source]

Decorator to convert given CalledProcessError to an exit message

This avoids displaying nasty stack traces to end-users

pyscaffold.shell.django_admin = <pyscaffold.shell.ShellCommand object at 0x7f060f649e10>

Command for django-admin.py

pyscaffold.shell.get_git_cmd(**args)[source]

Retrieve the git shell command depending on the current platform

All additional parameters are passed to ShellCommand

pyscaffold.shell.git = <pyscaffold.shell.ShellCommand object at 0x7f060f649dd0>

Command for git

pyscaffold.structure module

Functionality to generate and work with the directory structure of a project

pyscaffold.structure.add_namespace(args, struct)[source]

Prepend the namespace to a given file structure

Parameters:
  • args – command line parameters as argparse.Namespace
  • struct – directory structure as dictionary of dictionaries
Returns:

directory structure as dictionary of dictionaries

pyscaffold.structure.check_files_exist(struct, prefix=None)[source]

Checks which files exist in a directory structure

Parameters:
  • struct – directory structure as dictionary of dictionaries
  • prefix – prefix path for the structure
Returns:

returns a dictionary of dictionaries where keys representing files exists in the filesystem.

pyscaffold.structure.create_cookiecutter(args)[source]
pyscaffold.structure.create_django_proj(args)[source]

Creates a standard Django project with django-admin.py

Parameters:args – command line parameters as argparse.Namespace
pyscaffold.structure.create_structure(struct, prefix=None, update=False)[source]

Manifests a directory structure in the filesystem

Parameters:
  • struct – directory structure as dictionary of dictionaries
  • prefix – prefix path for the structure
  • update – update an existing directory structure as boolean
pyscaffold.structure.make_structure(args)[source]

Creates the project structure as dictionary of dictionaries

Parameters:args – command line parameters as argparse.Namespace
Returns:structure as dictionary of dictionaries
pyscaffold.structure.remove_from_struct(orig_struct, del_struct)[source]

Removes files existing in del_struct from structure orig_struct

Parameters:
  • orig_struct – directory structure as dictionary of dictionaries
  • del_struct – directory structure as dictionary of dictionaries
Returns:

directory structure as dictionary of dictionaries

pyscaffold.structure.set_default_args(args)[source]

Set default arguments for some parameters

Parameters:args – command line parameters as argparse.Namespace
Returns:command line parameters as argparse.Namespace

pyscaffold.templates module

Templates for all files of a project’s scaffold

pyscaffold.templates.authors(args)[source]

Template of AUTHORS.rst

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.best_fit_license(txt)[source]

Finds proper license name for the license defined in txt

Parameters:txt – license name as string
Returns:license name as string
pyscaffold.templates.changes(args)[source]

Template of CHANGES.rst

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.coveragerc(args)[source]

Template of .coveragerc

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.get_template(name)[source]

Retrieve the template by name

Parameters:name – name of template
Returns:template as string.Template
pyscaffold.templates.gitattributes(args)[source]

Template of .gitattributes

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.gitignore(args)[source]

Template of .gitignore

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.gitignore_empty(args)[source]

Template of empty .gitignore

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.init(args)[source]

Template of __init__.py

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.license(args)[source]

Template of LICENSE.txt

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.namespace(args)[source]

Template of __init__.py defining a namespace package

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.pre_commit_config(args)[source]

Template of .pre-commit-config.yaml

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.readme(args)[source]

Template of README.rst

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.requirements(args)[source]

Template of requirements.txt

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.setup_cfg(args)[source]

Template of setup.cfg

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.setup_py(args)[source]

Template of setup.py

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.skeleton(args)[source]

Template of skeleton.py defining a basic console script

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.sphinx_authors(args)[source]

Template of authors.rst

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.sphinx_changes(args)[source]

Template of changes.rst

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.sphinx_conf(args)[source]

Template of conf.py

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.sphinx_index(args)[source]

Template of index.rst

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.sphinx_license(args)[source]

Template of license.rst

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.sphinx_makefile(args)[source]

Template of Sphinx’s Makefile

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.tox(args)[source]

Template of tox.ini

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.travis(args)[source]

Template of .travis.yml

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.travis_install(args)[source]

Template of travis_install.sh

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string
pyscaffold.templates.version(args)[source]

Template of _version.py

Parameters:args – command line parameters as argparse.Namespace
Returns:file content as string

pyscaffold.utils module

Miscellaneous utilities and tools

class pyscaffold.utils.ObjKeeper(name, bases, dct)[source]

Bases: type

Metaclass to keep track of generated instances of a class

instances = {}
pyscaffold.utils.capture_objs(cls)[source]

Captures the instances of a given class during runtime

param cls:class to capture
return:dynamic list with references to all instances of cls
pyscaffold.utils.chdir(*args, **kwds)[source]

Contextmanager to change into a directory

Parameters:path – path to change into as string
pyscaffold.utils.exceptions2exit(exception_list)[source]

Decorator to convert given exceptions to exit messages

This avoids displaying nasty stack traces to end-users

Parameters:exception_list – list of exceptions to convert
pyscaffold.utils.git2pep440(ver_str)[source]

Converts a git description to a PEP440 conforming string

Parameters:ver_str – git version description
Returns:PEP440 version description
pyscaffold.utils.is_valid_identifier(string)[source]

Check if string is a valid package name

Parameters:string – package name as string
Returns:boolean
pyscaffold.utils.levenshtein(s1, s2)[source]

Calculate the Levenshtein distance between two strings

Parameters:
  • s1 – first string
  • s2 – second string
Returns:

distance between s1 and s2 as integer

pyscaffold.utils.list2str(lst, indent=0, brackets=True, quotes=True)[source]

Generate a Python syntax list string with an indention

Parameters:
  • lst – list
  • indent – indention as integer
  • brackets – surround the list expression by brackets as boolean
  • quotes – surround each item with quotes
Returns:

string

pyscaffold.utils.make_valid_identifier(string)[source]

Try to make a valid package name identifier from a string

Parameters:string – invalid package name as string
Returns:valid package name as string or RuntimeError
pyscaffold.utils.safe_get(namespace, attr)[source]

Safely retrieve the value of a namespace’s attribute

Parameters:
Returns:

value of the attribute or None

pyscaffold.utils.safe_set(namespace, attr, value)[source]

Safely set an attribute of a namespace object

The new attribute is set only if the attribute did not exist or was None.

Parameters:
  • namespace – namespace as argparse.Namespace object
  • attr – attribute name as string
  • value – value for new attribute
pyscaffold.utils.stash(*args, **kwds)[source]

Stashes a file away inside the context and restores it when leaving.

Parameters:filename – file name as string
pyscaffold.utils.utf8_decode(string)[source]

Decode a Python 2 str object to unicode for compatibility with Python 3

Parameters:string – Python 2 str object or Python 3 str object
Returns:Python 2 unicode object or Python 3 str object
pyscaffold.utils.utf8_encode(string)[source]

Encode a Python 2 unicode object to str for compatibility with Python 3

Parameters:string – Python 2 unicode object or Python 3 str object
Returns:Python 2 str object or Python 3 str object

Module contents