OpenQuizz
Une application de gestion des contenus pédagogiques
WorkingSet Class Reference

Public Member Functions

def __init__ (self, entries=None)
 
def add_entry (self, entry)
 
def __contains__ (self, dist)
 
def find (self, req)
 
def iter_entry_points (self, group, name=None)
 
def run_script (self, requires, script_name)
 
def __iter__ (self)
 
def add (self, dist, entry=None, insert=True, replace=False)
 
def resolve (self, requirements, env=None, installer=None, replace_conflicting=False, extras=None)
 
def find_plugins (self, plugin_env, full_env=None, installer=None, fallback=True)
 
def require (self, *requirements)
 
def subscribe (self, callback, existing=True)
 
def __getstate__ (self)
 
def __setstate__ (self, e_k_b_c)
 

Data Fields

 entries
 
 entry_keys
 
 by_key
 
 callbacks
 

Detailed Description

A collection of active distributions on sys.path (or a similar list)

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  entries = None 
)
A collection of active distributions on sys.path (or a similar list)
Create working set from list of path entries (default=sys.path)

Member Function Documentation

◆ __contains__()

def __contains__ (   self,
  dist 
)
True if `dist` is the active distribution for its project

◆ __getstate__()

def __getstate__ (   self)

◆ __iter__()

def __iter__ (   self)
Yield distributions for non-duplicate projects in the working set

The yield order is the order in which the items' path entries were
added to the working set.

◆ __setstate__()

def __setstate__ (   self,
  e_k_b_c 
)

◆ add()

def add (   self,
  dist,
  entry = None,
  insert = True,
  replace = False 
)
Add `dist` to working set, associated with `entry`

If `entry` is unspecified, it defaults to the ``.location`` of `dist`.
On exit from this routine, `entry` is added to the end of the working
set's ``.entries`` (if it wasn't already present).

`dist` is only added to the working set if it's for a project that
doesn't already have a distribution in the set, unless `replace=True`.
If it's added, any callbacks registered with the ``subscribe()`` method
will be called.

◆ add_entry()

def add_entry (   self,
  entry 
)
Add a path item to ``.entries``, finding any distributions on it

``find_distributions(entry, True)`` is used to find distributions
corresponding to the path entry, and they are added.  `entry` is
always appended to ``.entries``, even if it is already present.
(This is because ``sys.path`` can contain the same value more than
once, and the ``.entries`` of the ``sys.path`` WorkingSet should always
equal ``sys.path``.)

◆ find()

def find (   self,
  req 
)
Find a distribution matching requirement `req`

If there is an active distribution for the requested project, this
returns it as long as it meets the version requirement specified by
`req`.  But, if there is an active distribution for the project and it
does *not* meet the `req` requirement, ``VersionConflict`` is raised.
If there is no active distribution for the requested project, ``None``
is returned.

◆ find_plugins()

def find_plugins (   self,
  plugin_env,
  full_env = None,
  installer = None,
  fallback = True 
)
Find all activatable distributions in `plugin_env`

Example usage::

    distributions, errors = working_set.find_plugins(
Environment(plugin_dirlist)
    )
    # add plugins+libs to sys.path
    map(working_set.add, distributions)
    # display errors
    print('Could not load', errors)

The `plugin_env` should be an ``Environment`` instance that contains
only distributions that are in the project's "plugin directory" or
directories. The `full_env`, if supplied, should be an ``Environment``
contains all currently-available distributions.  If `full_env` is not
supplied, one is created automatically from the ``WorkingSet`` this
method is called on, which will typically mean that every directory on
``sys.path`` will be scanned for distributions.

`installer` is a standard installer callback as used by the
``resolve()`` method. The `fallback` flag indicates whether we should
attempt to resolve older versions of a plugin if the newest version
cannot be resolved.

This method returns a 2-tuple: (`distributions`, `error_info`), where
`distributions` is a list of the distributions found in `plugin_env`
that were loadable, along with any other distributions that are needed
to resolve their dependencies.  `error_info` is a dictionary mapping
unloadable plugin distributions to an exception instance describing the
error that occurred. Usually this will be a ``DistributionNotFound`` or
``VersionConflict`` instance.

◆ iter_entry_points()

def iter_entry_points (   self,
  group,
  name = None 
)
Yield entry point objects from `group` matching `name`

If `name` is None, yields all entry points in `group` from all
distributions in the working set, otherwise only ones matching
both `group` and `name` are yielded (in distribution order).

◆ require()

def require (   self,
requirements 
)
Ensure that distributions matching `requirements` are activated

`requirements` must be a string or a (possibly-nested) sequence
thereof, specifying the distributions and versions required.  The
return value is a sequence of the distributions that needed to be
activated to fulfill the requirements; all relevant distributions are
included, even if they were already activated in this working set.

◆ resolve()

def resolve (   self,
  requirements,
  env = None,
  installer = None,
  replace_conflicting = False,
  extras = None 
)
List all distributions needed to (recursively) meet `requirements`

`requirements` must be a sequence of ``Requirement`` objects.  `env`,
if supplied, should be an ``Environment`` instance.  If
not supplied, it defaults to all distributions available within any
entry or distribution in the working set.  `installer`, if supplied,
will be invoked with each requirement that cannot be met by an
already-installed distribution; it should return a ``Distribution`` or
``None``.

Unless `replace_conflicting=True`, raises a VersionConflict exception
if
any requirements are found on the path that have the correct name but
the wrong version.  Otherwise, if an `installer` is supplied it will be
invoked to obtain the correct version of the requirement and activate
it.

`extras` is a list of the extras to be used with these requirements.
This is important because extra requirements may look like `my_req;
extra = "my_extra"`, which would otherwise be interpreted as a purely
optional requirement.  Instead, we want to be able to assert that these
requirements are truly required.

◆ run_script()

def run_script (   self,
  requires,
  script_name 
)
Locate distribution for `requires` and run `script_name` script

◆ subscribe()

def subscribe (   self,
  callback,
  existing = True 
)
Invoke `callback` for all distributions

If `existing=True` (default),
call on all existing ones, as well.

Field Documentation

◆ by_key

by_key

◆ callbacks

callbacks

◆ entries

entries

◆ entry_keys

entry_keys

The documentation for this class was generated from the following file: