pynball.pynball

Utility script to help manage Development with various versions of Python in conjunction with Virtual Environments and the pyenv module.

Attributes

_PLATFORM

_IDLEMODE

_ENV_VARIABLES

_ENVIRONMENT

_USER_KEY

_USER_SUBKEY

_SYSTEM_KEY

_SYSTEM_SUBKEY

config

_WORKON_HOME

_PROJECT_HOME

_PYENV_HOME

Functions

get_environ(→ pathlib.Path)

Return the Path given the environment variable name

cli(→ None)

Utility script to help manage development with various versions of Python

del_rw(action, name, exc)

Change the access permissions for a file object to writeable and delete it

_feedback(→ None)

A utility method to generate formatted messages appropriate to the

_file_word_replace(→ Any)

Open the given file and replace old word with a new word

_execute(→ Any)

A utility method to run command line tools

_check_virtual_env(→ int)

Check if Virtual Environment Wrapper is configured by checking environment

_check_pyenv(→ int)

Check if pyenv is configured by checking environment variables.

_setenv(→ None)

sets an environment variable given a scope, variable name and a value.

_getenv(→ Any)

Gets an environment variable given a scope and key name.

_delenv(→ None)

A utility method to delete an environment variable key from the named scope.

_set_pynball(→ None)

Accepts and converts a dictionary object, then writes to the registry.

_get_pynball(→ Any)

Reads the environment variable 'PYNBALL' from the user scope as a string.

_get_system_path(→ tuple[list, list])

Returns Python system Interpreter if set and corresponding Pynball 'name' if set.

add(→ None)

Adds a name / path of an installation of Python.

addall(→ None)

Add all versions to the Pynball configuration.

delete(→ None)

Deletes a name / path of an installation of Python.

reset(→ None)

Deletes all names / paths

version(→ None)

Display details about the system Python Interpreter.

versions(→ None)

Lists the names / paths of the configured Python installations

system(→ None)

Changes the system Python Interpreter version.

pyenv(→ None)

Automatically include the pyenv versions in Pynball

mkproject(→ None)

Creates a Virtual Environment from a specific Python version.

rmproject(→ None)

Deletes a Virtual Environment.

lsproject(→ None)

Displays all Virtual Environment projects

mvproject(→ None)

Renames an existing project.

exportconf(→ None)

Creates a configuration file backup.

importconf(→ None)

Creates a configuration from a file backup

Module Contents

pynball.pynball._PLATFORM = 'linux'
pynball.pynball._IDLEMODE = 1
pynball.pynball._ENV_VARIABLES
pynball.pynball._ENVIRONMENT = 'posix'
pynball.pynball._USER_KEY
pynball.pynball._USER_SUBKEY = 'Environment'
pynball.pynball._SYSTEM_KEY
pynball.pynball._SYSTEM_SUBKEY = 'System\\CurrentControlSet\\Control\\Session Manager\\Environment'
pynball.pynball.config
pynball.pynball.get_environ(env_name: str) pathlib.Path

Return the Path given the environment variable name

pynball.pynball._WORKON_HOME
pynball.pynball._PROJECT_HOME
pynball.pynball._PYENV_HOME
pynball.pynball.cli() None

Utility script to help manage development with various versions of Python in conjunction with Virtual Environments and optionally the pyenv module.

pynball.pynball.del_rw(action, name, exc)

Change the access permissions for a file object to writeable and delete it

pynball.pynball._feedback(message: str, feedback_type: str) None

A utility method to generate formatted messages appropriate to the environment.

Parameters:
  • message – Text to be echoed.

  • feedback_type – identifies type of message to display.

pynball.pynball._file_word_replace(filepath: pathlib.Path, old_word: str, new_word: str) Any

Open the given file and replace old word with a new word

pynball.pynball._execute(*args: Any, supress_exception: bool = False) Any

A utility method to run command line tools

Parameters:

*args – The commands typically entered at the command line. e.g. “virtualenv”, f”-p={version_path}python.exe”, str(new_path)

pynball.pynball._check_virtual_env() int

Check if Virtual Environment Wrapper is configured by checking environment variables.

Returns:

Indicates virtualenvwrapper is not configured 0: Indicates virtualenvwrapper is configured correctly

Return type:

1

pynball.pynball._check_pyenv() int

Check if pyenv is configured by checking environment variables.

Returns:

Indicates pyenv is not configured 0: Indicates pyenv is configured correctly

Return type:

1

pynball.pynball._setenv(scope: str, name: str, value: str) None

sets an environment variable given a scope, variable name and a value.

Parameters:
  • scope – Must be either ‘user’ or ‘system’.

  • name – The registry key name.

  • value – The registry key value.

Returns:

message if scope is neither ‘user’ nor ‘system’. None: If registry write is successful.

Return type:

error

pynball.pynball._getenv(scope: str, name: str) Any

Gets an environment variable given a scope and key name.

Note

No need to open the key as they are one of the predefined HKEY_* constants.

Parameters:
  • scope – Must be either ‘user’ or ‘system’

  • name – The registry key name

Returns:

Message if scope is neither ‘user’ nor ‘system’. value: Registry key value on successful read None: Read failed.

Return type:

error

Raises:

FileNotFoundError – When the key is not found

pynball.pynball._delenv(scope: str, name: str) None

A utility method to delete an environment variable key from the named scope.

Note

No need to open the key as they are one of the predefined HKEY_* constants.

Parameters:
  • scope – Must be either ‘user’ or ‘system’.

  • name – The registry key name.

Returns:

Message if scope is neither ‘user’ nor ‘system’.

Return type:

error

Raises:

OSError – If the deletion failed.

pynball.pynball._set_pynball(dict_object: dict[str, pathlib.Path], varname: str) None

Accepts and converts a dictionary object, then writes to the registry.

Parameters:

dict_object – The dictionary. Format: {“name: str”: “path to version”: Path,}

pynball.pynball._get_pynball(returntype: str, varname: str) Any

Reads the environment variable ‘PYNBALL’ from the user scope as a string.

The string is then converted to the data structure specified by the returntype

Parameters:

returntype – The data structure and values to be returned

Returns:

If the returntype is not recognised. str: If returntype is ‘string’ dict: If return type is ‘dict’ or ‘dict_path_object’ list: if return type is ‘names’ or ‘paths’

Return type:

error

pynball.pynball._get_system_path() tuple[list, list]

Returns Python system Interpreter if set and corresponding Pynball ‘name’ if set.

Returns:

list, Pynball ‘name’: list

Return type:

System Interpreter

pynball.pynball.add(name: str, version_path: str) None

Adds a name / path of an installation of Python.

 :param name: Friendly name of a python installation. Can be any string.

e.g. 3.6

Parameters:

version_path – The path to the python interpreter e.g. /PYTHON/python3.6

pynball.pynball.addall(ctx: Any) None

Add all versions to the Pynball configuration.

pynball.pynball.delete(name: str) None

Deletes a name / path of an installation of Python.

 .. note:

This only deletes the name / path in the Pynball configuration.
It does not delete the Python installation.

 :param name: Friendly name of a python installation configured in Pynball.

e.g. 3.6

pynball.pynball.reset() None

Deletes all names / paths

pynball.pynball.version() None

Display details about the system Python Interpreter.

pynball.pynball.versions() None

Lists the names / paths of the configured Python installations

pynball.pynball.system(ctx: Any, name: str) None

Changes the system Python Interpreter version.

 :param name: The Pynball friendly name of the Python Installation :param ctx: The click context - Implementation detail that enables this

command to call another click command. (click says this is quite naughty. But I still did it anyway)

pynball.pynball.pyenv(ctx: Any, use_pyenv: str, use_force: str) None

Automatically include the pyenv versions in Pynball

 :param -u –use: Include pyenv versions :param -f –force: Pyenv versions override manual versions if the name is the same :param use_force: Pyenv versions override manual versions :param use_pyenv: Include pyenv versions :param ctx: The click context - Implementation detail that enables this

command to call another click command. (click says this is quite naughty. But I still did it anyway)

pynball.pynball.mkproject(create_all: str, name: str, project_name: str) None

Creates a Virtual Environment from a specific Python version.  Options:

-n, –noall: Only create the virtual environment. Skips project area.

 :param name: The Pynball friendly version name. :param project_name: The project name only. Not the path. :param create_all: Determines if the project folder gets created.

pynball.pynball.rmproject(delete_all: str, project_name: str) None

Deletes a Virtual Environment.

 Options:

-a, –all: Delete both the ‘DEV’ and ‘VENV’ directories

 :param project_name: The project name to be deleted. This is not the path. :param delete_all: Determines whether the ‘dev’ directory gets deleted.

pynball.pynball.lsproject() None

Displays all Virtual Environment projects

pynball.pynball.mvproject(ctx: Any, old_name: str, new_name: str) None

Renames an existing project.

 :param old_name: The existing project to rename. :param new_name: The new project name. :param ctx: The click context - Implementation detail that enables this

command to call another click command. (click says this is quite naughty. But I still did it anyway)

pynball.pynball.exportconf() None

Creates a configuration file backup.

pynball.pynball.importconf(config_path: str) None

Creates a configuration from a file backup

Parameters:

config_path – The commands typically entered at the command line.