module pycode.venv_helper
¶
Classes¶
class |
truncated documentation |
---|---|
Defines an exception when a function does not work in a virtual environment. |
|
Exception raised by the function implemented in this file. |
Functions¶
function |
truncated documentation |
---|---|
Builds the command line for virtual env. |
|
Checks the syntax of the file |
|
Creates a virtual environment. |
|
Tells if the script is run from a virtual environment. |
|
Runs a script with the original intepreter even if this function is run from a virtual environment. |
|
Runs a script on a vritual environment (the script should be simple). |
|
Installs a package or a list of packages in a virtual environment. |
Documentation¶
Helpers for virtualenv
-
exception
pyquickhelper.pycode.venv_helper.
NotImplementedErrorFromVirtualEnvironment
[source][source]¶ Bases:
NotImplementedError
Defines an exception when a function does not work in a virtual environment.
-
exception
pyquickhelper.pycode.venv_helper.
VirtualEnvError
[source][source]¶ Bases:
Exception
Exception raised by the function implemented in this file.
-
pyquickhelper.pycode.venv_helper.
build_venv_cmd
(params, posparams)[source][source]¶ Builds the command line for virtual env.
- Parameters
params – dictionary of parameters
posparams – positional arguments
- Returns
string
-
pyquickhelper.pycode.venv_helper.
check_readme_syntax
(readme, folder, version='0.8', fLOG=<function noLOG>)[source][source]¶ Checks the syntax of the file
readme.rst
which describes a python project.- Parameters
readme – file to check
folder – location for the virtual environment
version – version of docutils
fLOG – logging function
- Returns
output or SyntaxError exception
pipy server is based on docutils ==0.8. The most simple way to check its syntax is to create a virtual environment, to install docutils==0.8 and to compile the file. This is what this function does.
Unfortunately, this functionality does not work yet from a virtual environment.
-
pyquickhelper.pycode.venv_helper.
create_virtual_env
(where, symlinks=False, system_site_packages=False, clear=True, packages=None, fLOG=<function noLOG>, temp_folder=None, platform=None)[source][source]¶ Creates a virtual environment.
- Parameters
where – location of this virtual environment
symlinks – attempt to symlink rather than copy
system_site_packages – Give the virtual environment access to the system site-packages dir
clear – Delete the environment directory if it already exists. If not specified and the directory exists, an error is raised.
packages – list of packages to install (it will install module pymyinstall).
fLOG – logging function
temp_folder – temporary folder (to download module if needed), by default
<where>/download
platform – platform to use
- Returns
stand output
How to create a virtual environment?
The following example creates a virtual environment. Packages can be added by specifying the parameter package.
from pyquickhelper.pycode import create_virtual_env fold = "my_env" if not os.path.exists(fold): os.mkdir(fold) create_virtual_env(fold)
The function does not work from a virtual environment.
-
pyquickhelper.pycode.venv_helper.
is_virtual_environment
()[source][source]¶ Tells if the script is run from a virtual environment.
- Returns
boolean
-
pyquickhelper.pycode.venv_helper.
run_base_script
(script, fLOG=<function noLOG>, file=False, is_cmd=False, skip_err_if=None, argv=None, platform=None, **kwargs)[source][source]¶ Runs a script with the original intepreter even if this function is run from a virtual environment.
- Parameters
script – script as a string (not a file)
fLOG – logging function
file – is script a file or a string to execute
is_cmd – if True, script is a command line to run (as a list) for python executable
skip_err_if – do not pay attention to standard error if this string was found in standard output
argv – list of arguments to add on the command line
platform – platform (
sys.platform
by default)kwargs – others arguments for function
run_cmd
.
- Returns
output
The function does not work from a virtual environment. The function does not raise an exception if the standard error contains something like:
---------------------------------------------------------------------- Ran 1 test in 0.281s OK
-
pyquickhelper.pycode.venv_helper.
run_venv_script
(venv, script, fLOG=<function noLOG>, file=False, is_cmd=False, skip_err_if=None, platform=None, **kwargs)[source][source]¶ Runs a script on a vritual environment (the script should be simple).
- Parameters
venv – virtual environment
script – script as a string (not a file)
fLOG – logging function
file – is script a file or a string to execute
is_cmd – if True, script is a command line to run (as a list) for python executable
skip_err_if – do not pay attention to standard error if this string was found in standard output
platform – platform (
sys.platform
by default)kwargs – others arguments for function
run_cmd
.
- Returns
output
The function does not work from a virtual environment.
-
pyquickhelper.pycode.venv_helper.
venv_install
(venv, packages, fLOG=<function noLOG>, temp_folder=None, platform=None)[source][source]¶ Installs a package or a list of packages in a virtual environment.
- Parameters
venv – location of the virtual environment
packages – a package (str) or a list of packages(list[str])
fLOG – logging function
temp_folder – temporary folder (to download module if needed), by default
<where>/download
platform – platform (
sys.platform
by default)
- Returns
standard output
The function does not work from a virtual environment.