mork package¶
-
class
mork.
VirtualEnv
(prefix=None, base_working_set=None, is_venv=True)[source]¶ Bases:
object
-
activated
(include_extras=True, extra_dists=[])[source]¶ A context manager which activates the virtualenv.
Parameters: extra_dists (list) – Paths added to the context after the virtualenv is activated. - This context manager sets the following environment variables:
- PYTHONUSERBASE
- VIRTUAL_ENV
- PYTHONIOENCODING
- PYTHONDONTWRITEBYTECODE
In addition, it activates the virtualenv inline by calling activate_this.py.
-
base_paths
¶ Returns the context appropriate paths for the environment.
Returns: A dictionary of environment specific paths to be used for installation operations Return type: dict Note
The implementation of this is borrowed from a combination of pip and virtualenv and is likely to change at some point in the future.
>>> from pipenv.core import project >>> from pipenv.environment import Environment >>> env = Environment(prefix=project.virtualenv_location, is_venv=True, sources=project.sources) >>> import pprint >>> pprint.pprint(env.base_paths) {'PATH': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW/bin::/bin:/usr/bin', 'PYTHONPATH': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW/lib/python3.7/site-packages', 'data': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW', 'include': '/home/hawk/.pyenv/versions/3.7.1/include/python3.7m', 'libdir': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW/lib/python3.7/site-packages', 'platinclude': '/home/hawk/.pyenv/versions/3.7.1/include/python3.7m', 'platlib': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW/lib/python3.7/site-packages', 'platstdlib': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW/lib/python3.7', 'prefix': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW', 'purelib': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW/lib/python3.7/site-packages', 'scripts': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW/bin', 'stdlib': '/home/hawk/.pyenv/versions/3.7.1/lib/python3.7'}
-
classmethod
from_project_path
(path)[source]¶ Utility for finding a virtualenv location based on a project path
-
get_distributions
()[source]¶ Retrives the distributions installed on the library path of the virtualenv
Returns: A set of distributions found on the library path Return type: iterator
-
get_monkeypatched_pathset
()[source]¶ Returns a monkeypatched UninstallPathset for using to uninstall packages from the virtualenv
Returns: A patched UninstallPathset which enables uninstallation of venv packages Return type: pip._internal.req.req_uninstall.UninstallPathset
-
get_setup_install_args
(pkgname, setup_py, develop=False)[source]¶ Get setup.py install args for installing the supplied package in the virtualenv
Parameters: Returns: The installation arguments to pass to the interpreter when installing
Return type:
-
classmethod
get_sys_path
(python_path)[source]¶ Get the
sys.path
data for a given python executable.Parameters: python_path (str) – Path to a specific python executable. Returns: The system path information for that python runtime. Return type: list
-
get_working_set
()[source]¶ Retrieve the working set of installed packages for the virtualenv.
Returns: The working set for the virtualenv Return type: pkg_resources.WorkingSet
-
initial_working_set
¶
-
install
(req, editable=False, sources=[])[source]¶ Install a package into the virtualenv
Parameters: Returns: A return code, 0 if successful
Return type:
-
is_installed
(pkgname)[source]¶ Given a package name, returns whether it is installed in the virtual environment
Parameters: pkgname (str) – The name of a package Returns: Whether the supplied package is installed in the environment Return type: bool
-
libdir
¶
-
paths
¶
-
python
¶ Path to the environment python
-
python_version
¶
-
pyversion
¶
-
classmethod
resolve_dist
(dist, working_set)[source]¶ Given a local distribution and a working set, returns all dependencies from the set.
Parameters: - dist (
pkg_resources.Distribution
) – A single distribution to find the dependencies of - working_set (
pkg_resources.WorkingSet
) – A working set to search for all packages
Returns: A set of distributions which the package depends on, including the package
Return type: set(
pkg_resources.Distribution
)- dist (
-
run
(cmd, cwd='.')[source]¶ Run a command with
Popen
in the context of the virtualenvParameters: Returns: A finished command object
Return type:
-
run_py
(cmd, cwd='.')[source]¶ Run a python command in the virtualenv context.
Parameters: Returns: A finished command object
Return type:
-
safe_import
(name)[source]¶ Helper utility for reimporting previously imported modules while inside the venv
-
script_basedir
¶ Path to the environment scripts dir
-
scripts_dir
¶
-
setuptools_install
(chdir_to, pkg_name, setup_py_path=None, editable=False)[source]¶ Install an sdist or an editable package into the virtualenv
Parameters:
-
sys_path
¶ The system path inside the environment
Returns: The sys.path
from the environmentReturn type: list
-
sys_prefix
¶ The prefix run inside the context of the environment
Returns: The python prefix inside the environment Return type: sys.prefix
-
system_paths
¶
-
uninstall
(pkgname, *args, **kwargs)[source]¶ A context manager which allows uninstallation of packages from the virtualenv
Parameters: pkgname (str) – The name of a package to uninstall >>> venv = VirtualEnv("/path/to/venv/root") >>> with venv.uninstall("pytz", auto_confirm=True, verbose=False) as uninstaller: cleaned = uninstaller.paths >>> if cleaned: print("uninstalled packages: %s" % cleaned)
-