8.4.7. pymodaq_utils.environment module

class pymodaq_utils.environment.EnvironmentBackupManager[source]

Bases: object

A class to manage rotating backups of python environments, controlled by entries in [backup] section of the configuration.

Methods

save_backup()

Save the current environment if there is no backup or if it's different from the oldest one.

save_backup()[source]

Save the current environment if there is no backup or if it’s different from the oldest one.

Also, remove the oldest one(s) if there’s more than the limit defined in configuration.

class pymodaq_utils.environment.PythonEnvironment(filename=None)[source]

Bases: object

A class to represent a python environment and creates/delete backups.

Preferably, it is instanciated using one the following static method:
  • from_freeze: to perform a pip freeze and allowing to save it

  • from_file: to read a file and allowing to delete it

Methods

date()

Gets the date at which this environment was created from its filename.

extend(packages)

Add packages to the environment.

from_file(filename)

Loads a PythonEnvironment from a text file in a pip recognized format

from_freeze()

Loads a PythonEnvironment by performing a pip freeze

remove()

Remove the backup file associated with this environment, if it exists.

save()

Save the backup file associated with this environment, if it does not exists.

static from_file(filename)[source]

Loads a PythonEnvironment from a text file in a pip recognized format

Parameters:

filename (str) – A Path to the file to load

Returns:

the PythonEnvironment representation of the file represented by filename

Return type:

PythonEnvironment

static from_freeze()[source]

Loads a PythonEnvironment by performing a pip freeze

Returns:

the PythonEnvironment representation of all installed packages in the current environment

Return type:

PythonEnvironment

date()[source]

Gets the date at which this environment was created from its filename. If not possible it fallbacks to its creation/modification date (depending on the OS) If still not possible it fallbacks to now.

It allows to sort them by date, without having to declare comparison operators that aren’t consistant with __eq__.

Returns:

The date associated with this environment

Return type:

datetime

extend(packages)[source]

Add packages to the environment. (This does not install them)

Parameters:

packages ([str]) – an iterable containing the different packages, preferably in a “<name>==<version>” format

remove()[source]

Remove the backup file associated with this environment, if it exists.

save()[source]

Save the backup file associated with this environment, if it does not exists.

DATE_FORMAT = '%Y%m%d%H%M%S'
pymodaq_utils.environment.guess_virtual_environment()[source]

Try to guess the current python environment used.

Returns:

str

Return type:

str