ouroboros.tools.pproject package

Submodules

ouroboros.tools.pproject.conda module

Copyright (C) 2018 Simon Kallfass

conda-commands used by the pproject-module.

class ouroboros.tools.pproject.conda.CondaEnvironment(name)[source]

Bases: object

Class representing a conda-environment. Includes methods for creation, removal (local and remote) of the conda-environment.

create(dependencies)[source]

Create conda-environment with name self.name and passed dependencies.

Parameters:

dependencies (list) – List of strings with dependencies (packagename with optional version) to install inside environment.

Example:

[‘python=3.6’, ‘attrs=>17.3’]

create_remote(ssh, pythonversion, packagename, version, projectpath)[source]

Release the package in its own conda-envrionment on a remote host.

Parameters:
  • ssh (paramiko.SSHClient) – Connection via ssh where the conda-environment should be created.
  • pythonversion (str) – pythonversion to create the environment for.
  • packagename (str) – Name of the package to install inside the created environment.
  • version (str) – Version of the package to install inside the created environment.
  • projectpath (str) – Path of currrent project.
exists()[source]

Check if conda-environment with name self.name exists.

Returns:bool – True if conda-environment exists, else False.
recreate(dependencies)[source]

Remove conda-environment if it already exists. Then creates new environment as self.name with passed dependencies.

Parameters:

dependencies (list) – List of strings with dependencies (packagename with optional version) to install inside environment.

Example:

[‘python=3.6’, ‘attrs=>17.3’]

release_log(ssh, action, projectpath)[source]

Write information about ssh-interaction on the destination host as passed in ssh.

ssh: paramiko.SSHClient
Connection via ssh where to log the output to.
action: str

action as a string to log into the log-file.

Example:
“create”
projectpath: str
Path of currrent project.
remove()[source]

Remove conda-environment with name self.name if it exists.

remove_remote(ssh, projectpath)[source]

Remove the conda-environment as defined in self.name via ssh from remote.

Parameters:
  • ssh (paramiko.SSHClient) – Connection via ssh where the conda-environment should be removed from.
  • projectpath (str) – Path of currrent project.
class ouroboros.tools.pproject.conda.MetaYaml(path=None)[source]

Bases: object

Class representing the meta.yaml file of a python-conda-package. Includes a get_content-method for reading the content of the meta.yaml-file and a update-method which calls the get_content-method and updates the class-attributes with the collected informations.

path

str

content

dict

dependencies

dict

pythonversion

str

package_name

str

get_content()[source]

Collects the contents of the meta.yaml file and returns the collected informations.

Returns:content (dict) – Contents of the meta.yaml file.
update()[source]

Updates the class-attributes with informations collected by the get_content-method.

Note

Uses method MetaYaml.get_content() to collect the content of the meta.yaml file.

ouroboros.tools.pproject.conda.build_package(path, pythonversion, simulate=False)[source]

Build conda-package from source at passed path for passed pythonversion. If simulate is set to True, the package isn’t built. The function only returns the path of the resulting package if it would have been built.

Parameters:
  • path (pathlib.Path) – The path to the source for which the conda-package should be build.
  • pythonversion (str) – The pythonversion to build the conda-package for.
  • simulate (bool) – Flag if build is only simulated or not.
Returns:

result (str) – The path of the resulting conda-package (simulated or real).

ouroboros.tools.pproject.conda.publish_package_on_reposerver(sourcepath)[source]

Publish a conda-package from sourcepath on conda-repository-server as defined in the pprojects-config-file.

Parameters:sourcepath (str) – Local path to the conda-package to publish on the conda-repository-server.

ouroboros.tools.pproject.git module

Copyright (C) 2018 Simon Kallfass

git- and gitlab-commands used by the pproject-module.

class ouroboros.tools.pproject.git.GitRepo(path)[source]

Bases: object

Class representing a local git-repository. Includes methods to check its status, initialize, add, push, create tag, etc.

add_all()[source]

Add all content of local git-repository.

check_tag_on_remote()[source]

Check if current tag is pushed to the origin url.

Returns:check (bool)
commit()[source]

Commit current state of local git-repository.

create_tag(tag, message)[source]

Create git tag as passed with passed message for current local git-repository.

Parameters:
  • tag (str) – The tag to create for current local git-repository.
  • message (str) – The message to pass with the tag.
get_branch()[source]
get_email()[source]

Collect the email of the current user as defined in the .gitconfig-file.

Returns:str – Email of current user as defined in the .gitconfig-file.
get_tag()[source]

Try to get the git tag for the current local git-repository and returns the result. If the repo doesn’t have a git tag yet, it returns “0.0.0”

Returns:str – Git tag for current local git-repository or “0.0.0” if no git tag available yet.
get_username()[source]

Collect the name of the current user as defined in the .gitconfig-file.

Returns:str – Name of current user as defined in the .gitconfig-file.
initialize()[source]

Initialize current local project as a git-repository.

push_tag(tag)[source]

Push passed tag of current local git-repository to its origin.

Parameters:tag (str) – The tag to push to the git-repositories origin.
push_to_branch(branch)[source]

Push passed branch of current local git-repository to its origin.

Parameters:branch (str) – Branchname to push to origin.
set_origin(origin)[source]

Set origin of current local git-repository to passed origin.

Parameters:origin (str) – Origin to set for the local git-repository.
status()[source]

Check status of current local git-repository. Returns True if it is clean. If there is uncommited stuff it returns False.

Returns:bool – Represents if current local git-repository is clean. If there is uncommited stuff inside the repository, False is returned.
ouroboros.tools.pproject.git.check_remote_vcs()[source]

Check if the vcs-url is reachable.

Returns:check_result (bool) – Result for the remote vcs to check.
ouroboros.tools.pproject.git.create_on_remote_vcs(*, company, namespace, project, username)[source]

Create new project on remote vcs (as defined in config) based on the passed values “company”, “namespace” and “project”.

Parameters:
  • company (str)
  • namespace (str)
  • project (str)
  • username (str)
Returns:

project_to_create/gitlab_group (str) – The name of the created project / The name of the gitlab-group in which the project was created.

ouroboros.tools.pproject.git.get_gitlab_groups()[source]

Collect the available gitlab-groups for the gitlab-user and his gitlab-token from the defined gitlab-api.

Returns:gitlab_groups (dict) – Dict containing the available gitlab-groups.
ouroboros.tools.pproject.git.get_vcs_token()[source]

Collect the users vcs-token from the token-file as defined in the config and return it.

Returns:token (str) – The vcs-token to interact with the remote vcs.

ouroboros.tools.pproject.inform module

Copyright (C) 2018 Simon Kallfass

Provides the functions used for visual output for the user inside the pproject-tool.

ouroboros.tools.pproject.inform.BOLD = '\x1b[1;37m'

str – Bold-style used for visual output for the user.

ouroboros.tools.pproject.inform.CYAN = '\x1b[0;94m'

str – Color cyan used for visual output for the user.

ouroboros.tools.pproject.inform.GREEN = '\x1b[1;92m'

str – Color green used for visual output for the user.

ouroboros.tools.pproject.inform.NCOLOR = '\x1b[0m'

str – Resets the color used for visual output for the user.

ouroboros.tools.pproject.inform.RED = '\x1b[1;91m'

str – Color red used for visual output for the user.

ouroboros.tools.pproject.inform.critical(msg=None)[source]

Generates output in defined critical-style for the user. Stops the pproject-script with sys.exit(1).

Parameters:msg (str) – (default=None) Message to output for the user in info-style. Before existing.
ouroboros.tools.pproject.inform.error(msg=None)[source]

Generates output in defined error-style for the user.

Parameters:msg (str) – (default=None) Message to output for the user in info-style.
ouroboros.tools.pproject.inform.finished(msg=None)[source]

Generates output in defined finished-style for the user.

Parameters:msg (str) – (default=None) Message to output for the user in info-style.
ouroboros.tools.pproject.inform.info(msg=None)[source]

Generates output in defined info-style for the user.

Parameters:msg (str) – (default=None) Message to output for the user in info-style.

ouroboros.tools.pproject.pproject module

Copyright (C) 2018 Simon Kallfass

The pproject-module provides the functionality and logic used by the pproject.sh-file.

class ouroboros.tools.pproject.pproject.Project(company, namespace, project, pythonversion, path=PosixPath('/home/ektom/devl/ouroboros-tools-pproject'))[source]

Bases: object

Class representing an pproject-project. It contains methods to create new projects with cookiecutter, update project-environment, test defined tests with pytest, build a conda-package from the project, increase projects git-tag based on semantic versioning, release of the project as a conda-package in its on environment on another host.

company

str – The name of the company to use in the project.

namespace

str – The namespace in which the project is placed.

project

str – The name of the project.

pythonversion

str – The pythonversion to use inside the project.

username

str – The name of the author of the project (collected by git config).

email

str – The email of the author of the project (collected by git config).

year

str – The year in which the project was created.

today

str – The date when the project was created.

version

str – The current git tag of the project. Collected by git describe tag. Should be raised with “pproject new_version”.

environment

str – The name of the conda-environment associated with the project. Either collected from meta.yaml if project already exists, or combined by “company-namespace-project” if created.

git

git.GitRepo – Enables git-interactions for project.

build(publish=False, path=None)[source]

Builds a conda-package from the project. First it runs all tests to ensure functionality of the resulting package. Assuming the test-coverage is acceptable. Then it checks for uncommited stuff inside the project and if it is tagged with a version-tag. Finally the conda-package is build. If the publish-flag is set it is uploaded to the conda-repo-server. Else it is only built local.

Parameters:
  • publish (bool) – Flag which indicates if the resulting conda-package should be uploaded to the conda-repository-server defined in the config-file or not.
  • path (pathlib.Path) – The projects path.

Note

Runs Project.test() before build to check for failures. Checks if uncommited stuff remains inside project-folder before build with check_git_status(). Also checks if a required git-tag exists with get_git_tag(). To execute the conda-build command utils.run_in_bash() is used.

create(on_vcs=False, path=None)[source]

Creates new project based on a defined skeleton either local or on gitlab with cookiecutter, creates the base-conda-environment for developing the new project and manages corresponding git-tasks.

Parameters:
  • on_vcs (bool) – Flag to define if project should be added to remote vcs after creation.
  • path (pathlib.Path) – The projects path.

Note

Calls Project.update_informations() with create=True to update the attributes of the project. For git operations the function utils.run_in_bash() is called. After creation Project.update() with path set to current working directory is called to create the conda-environment of the project.

info(path=None)[source]

Collects and prints information about the pproject-configuration and the current project.

Parameters:path (pathlib.Path) – The projects path.

Note

Uses conda.MetaYaml to collect the project informations. The current version is collected by get_git_tag(). Resulting packagename is collected by conda.build_package(). The pproject-settings are collected by the global variables.

new_version(vtype, message='New version triggered by pproject', path=None)[source]

Raises the passed vtype (versiontype) inside version (git-tag) of the project. Version has to be in semantic versioning style (see https://semver.org/ for details). Example for version in semantic versioning style: General: “major.minor.patch” Example: “1.0.1”

Parameters:
  • vtype (str) – The part to raise inside current version. Valid are: “major”, “minor” and “patch”
  • message (str) – The message to use for the git tag.
  • path_ (pathlib.Path()) – The projects path.

Note

First checks if there is uncommited stuff inside the current branch. If there is uncommited stuff, the operation is aborted. Else checks if the gitlab is reachable. Then the current version is collected. The passed vtype is raised by 1. Finally the resulting version-tag is added with passed message and the new tag is pushed to gitlab. For these operations git.GitRepo is used.

release(dst='localhost', envname=None, path=None)[source]

Rolls out the current project as a conda-package in its own conda-environment either on localhost or on a remote.

Parameters:
  • dst (str) – The destination where the resulting package should be rolled out. Valid values are: “localhost” (default), “USER@HOSTNAME
  • envname (str) – The name of the environment to create on destination with the resulting package. If no “environment” is passed, the name of the project-environment is used.
  • path (pathlib.Path) – The projects path.

Note

The version of the project is collected by get_git_tag(). Then the project is build as a conda-package with Project.build(). If destination is “localhost”, the creation of the conda-envrionment for the just created package is done by utils.run_in_bash(). Else the required commands are executed by paramiko.

sphinx(path=None)[source]

Creates a sphinx documentation for the current pproject project.

Parameters:path (pathlib.Path) – The projects path.
test(path=None)[source]

Runs all tests for the project in its tests folder with pytest.

Parameters:path (pathlib.Path) – The projects path.

Note

Calls Project.test() to update the projects conda-environment before running the tests with pytest.

update(path=None)[source]

Updates the project-related conda-environment. If it already exists it will be removed and then recreated. This ensures to remove dependencies of packages which aren’t required anymore. If the environment doesn’t exist yet, the environment will be created. Finally stores the md5sum of the based meta.yaml file inside a file to enable the pproject-autoenv functionality triggered by changes inside the meta.yaml file.

Parameters:path (str) – Path of the required meta.yaml file. Only required if the meta.yaml is outside of the current working directory

Note

The pythonversion and the dependencies are collected with conda.MetaYaml. Environment creation/removal is done using conda.CondaEnvironment. To calculate the new md5sum of the meta.yaml and store it inside the hash.md5-file, update_md5sum() is used.

update_informations(create=False, path=None)[source]

Updates class-attributes with new informations collected from meta.yaml, git config and current datetime.

Parameters:
  • create (bool) – If project isn’t created yet the name of the environment can’t be extracted from the meta.yaml. In this case it has to be combined from companyname, namespace and projectname.
  • path (pathlib.Path) – The projects-path.

Note

Uses conda.MetaYaml to collect the name of environment from the current project if create is False. To collect git-specific informations git.GitRepo is used. Checks for valid project-definition with validators.SProject.

update_md5sum()[source]
ouroboros.tools.pproject.pproject.build_arguments(args)[source]

The argument parsing for the python-part of the pproject-tool.

Parameters:args (list)
Returns:parsed_args (argparse.Namespace)
ouroboros.tools.pproject.pproject.general_info()[source]

Collects and prints information about the pproject-configuration and the current project.

Note

The pproject-settings are collected by the global variables.

ouroboros.tools.pproject.pproject.main()[source]

The main function coordinating the python-part of the pproject-tool.

Note

The arguments are parsed by build_arguments(). All other operations are done by conda.MetaYaml and Project and their methods.

ouroboros.tools.pproject.pproject.run(options, path=PosixPath('/home/ektom/devl/ouroboros-tools-pproject'))[source]
Parameters:
  • options (argparse.Namespace)
  • path (pathlib.Path)

ouroboros.tools.pproject.sphinx module

Copyright (C) 2018 Simon Kallfass

sphinx-commands used by the pproject-module.

ouroboros.tools.pproject.sphinx.COMPANY = 'ouroboros'

str – The company name to use for new project creations based on “pproject create”.

ouroboros.tools.pproject.sphinx.PPROJECT_ENV_PATH = '/var/local/conda/envs/pproject'

str – The folder where the pproject-env is stored.

ouroboros.tools.pproject.sphinx.create_coverage_badge(path, environment)[source]

Run pytest-cov and create coverage-badge for the coverage-result. Store the resulting badge inside the static folder for use inside documentation.

Parameters:
  • path (pathlib.Path) – Path where to change into for testing and creation of badge.
  • environment (str) – Name of the project to document.
ouroboros.tools.pproject.sphinx.customize_config(path)[source]

Rename content of source/conf.py for custom setup.

Parameters:path (pathlib.Path) – Path to create the documentation for.
ouroboros.tools.pproject.sphinx.make_documentation(path)[source]

Generatie html- and pdf-documentation for passed path.

Parameters:path (pathlib.Path) – Path to create the documentation for.
ouroboros.tools.pproject.sphinx.run_sphinx_quickstart(path, environment, username, version)[source]

Run sphinx-quickstart for the passed path. Required variables for this setup are the passed environment (as name of the project), the username and the version of the project to document.

Parameters:
  • path (pathlib.Path) – Path to create the documentation for.
  • environment (str) – The name of the project to document.
  • username (str) – The name of maintainer of the project.
  • version (str) – The current version of the project.
ouroboros.tools.pproject.sphinx.update_source(path)[source]

Update source for documentation to create of passed path.

Parameters:path (pathlib.Path) – Path to create the documentation for.

ouroboros.tools.pproject.utils module

Copyright (C) 2018 Simon Kallfass

Utils used by the pproject-module like md5sum-calculations, config-loading, executing commands in bash and ssh-interactions.

ouroboros.tools.pproject.utils.connect_ssh(dst)[source]

Connect to destination host (dst).

Parameters:dst (str) – The destination-host as combination of “username@hostname”.
Returns:paramiko.SSHClient – The connection-object to the dst-host.
ouroboros.tools.pproject.utils.get_config_for_terminal()[source]

Reads the config file of pproject and prints the content. Used to source the config variables inside the pproject.sh script.

Parameters:path (pathlib.Path) – The path of the config file.
ouroboros.tools.pproject.utils.load_configs(default_config_path=None, user_config_path=None)[source]

Unwritten yet

Parameters:
  • default_config_path (pathlib.Path)
  • user_config_path (pathlib.Path)
Returns:

list – List of dicts containing “default_config”-content and “user_config”-content.

ouroboros.tools.pproject.utils.md5(fname)[source]

Calculates the md5sum of the passed file and returns the calculated value.

Parameters:fname (str) – filename of file to calculate the md5sum for
Returns:str – md5sum of passed file
ouroboros.tools.pproject.utils.run_in_bash(command)[source]

Executes a passed command in bash.

Parameters:command (str) – command to be executed inside bash
Returns:result (str) – Result for executed command

ouroboros.tools.pproject.validators module

Copyright (C) 2018 Simon Kallfass

Provides validators used in the pproject-module (project-, config- and meta.yaml-validations).

class ouroboros.tools.pproject.validators.SBuild(only=(), exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]

Bases: ouroboros.tools.pproject.validators.SToasted

The schema-class for the build-section used as nested-field in SMetaYaml.

build

str

preserve_egg_dir

bool

entry_points

list

opts = <marshmallow.schema.SchemaOpts object>
class ouroboros.tools.pproject.validators.SConfig(only=(), exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]

Bases: ouroboros.tools.pproject.validators.SToasted

The schema-class for the pproject-config.

conda_folder

str

meta_yaml_path

str

meta_yaml_md5_path

str

environment_yaml_path

str

pproject_env

str

skeleton_repo

str

company

str

gitlab_url

str

gitlab_api

str

gitlab_token_path

str

gitlab_ssh

str

conda_repo_userathost

str

conda_repo_pkgs_path

str

conda_repo_conda_bin

str

pytest_arguments

list

opts = <marshmallow.schema.SchemaOpts object>
class ouroboros.tools.pproject.validators.SExtra(only=(), exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]

Bases: ouroboros.tools.pproject.validators.SToasted

The schema-class for the extra-section used as nested-field in SMetaYaml.

maintainer

str

pythonversion

str

opts = <marshmallow.schema.SchemaOpts object>
class ouroboros.tools.pproject.validators.SMetaYaml(only=(), exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]

Bases: ouroboros.tools.pproject.validators.SToasted

The schema-class to use for meta.yaml-contents used in pproject.

package

marshmallow.fields.Nested

source

marshmallow.fields.Nested

build

marshmallow.fields.Nested

requirements

marshmallow.fields.Nested

test

marshmallow.fields.Nested

about

dict

extra

marshmallow.fields.Nested

opts = <marshmallow.schema.SchemaOpts object>
class ouroboros.tools.pproject.validators.SPackage(only=(), exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]

Bases: ouroboros.tools.pproject.validators.SToasted

The schema-class for the package-section used as nested-field in SMetaYaml.

name

str

version

str

opts = <marshmallow.schema.SchemaOpts object>
class ouroboros.tools.pproject.validators.SProject(only=(), exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]

Bases: ouroboros.tools.pproject.validators.SToasted

The schema-class for pproject-projects.

company

str

namespace

str

project

str

pythonversion

str

username

str

email

str

year

str

today

str

version

str

environment

str

opts = <marshmallow.schema.SchemaOpts object>
class ouroboros.tools.pproject.validators.SRequirements(only=(), exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]

Bases: ouroboros.tools.pproject.validators.SToasted

The schema-class for the requirements-section used as nested-field in SMetaYaml.

build

list

run

list

opts = <marshmallow.schema.SchemaOpts object>
class ouroboros.tools.pproject.validators.SSource(only=(), exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]

Bases: ouroboros.tools.pproject.validators.SToasted

The schema-class for the source-section used as nested-field in SMetaYaml.

path

str

opts = <marshmallow.schema.SchemaOpts object>
class ouroboros.tools.pproject.validators.STest(only=(), exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]

Bases: ouroboros.tools.pproject.validators.SToasted

The schema-class for the test-section used as nested-field in SMetaYaml.

imports

list

commands

list

opts = <marshmallow.schema.SchemaOpts object>
class ouroboros.tools.pproject.validators.SToasted(only=(), exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]

Bases: marshmallow.schema.Schema

The base-Schema-class to use for all other schemata in this module. Using toastedmarshmallow.Jit speeds up validation.

class Meta[source]

Bases: object

Meta-class used to speed up marshmallow-validation.

jit

alias of toastedmarshmallow.Jit

opts = <marshmallow.schema.SchemaOpts object>
ouroboros.tools.pproject.validators.validate_environmentname(environment)[source]

Validates if the passed environment is valid.

Parameters:environment (str) – The environment-name to validate.
Raises:marshmallow.ValidationError – If environment isn’t valid, raises a marshmallow.ValidationError.
ouroboros.tools.pproject.validators.validate_path_exists(path)[source]

Validates if the passed path exists.

Parameters:path (str) – The path to check.
Raises:marshmallow.ValidationError – If path doesn’t exist, raises a marshmallow.ValidationError.
ouroboros.tools.pproject.validators.validate_url(url)[source]

Validates if the passed url is valid.

Parameters:url (str) – The url to validate.
Raises:marshmallow.ValidationError – If passed url isn’t valid, raises a marshmallow.ValidationError.
ouroboros.tools.pproject.validators.validate_version(version)[source]

Validates if the passed version is valid (form and semantic-versioning-style).

Parameters:version (str) – The version to validate.
Raises:marshmallow.ValidationError – If version isn’t valid, raises a marshmallow.ValidationError.

Module contents


© Copyright 2018, Simon Kallfass.

Impressum

This site was generated using Sphinx and the Sphinx-Bootstrap-Theme