module pycode.venv_helper
¶
Classes¶
class | truncated documentation |
---|---|
NotImplementedErrorFromVirtualEnvironment |
defines an exception when a function does not work in a virtual environment .. versionadded:: 1.3 |
VirtualEnvError |
exception raised by the function implemented in this file |
Functions¶
function | truncated documentation |
---|---|
build_venv_cmd |
builds the command line for virtual env |
check_readme_syntax |
check the syntax of the file readme.rst which describes a python project |
compare_module_version |
compare two versions |
create_virtual_env |
|
is_virtual_environment |
tells if the script is run from a virtual environment |
numeric_module_version |
convert a string into a tuple with numbers whever possible |
run_venv_script |
run a script on a vritual environment (the script should be simple |
venv_install |
install a package or a list of packages in a virtual environment |
Documentation¶
Helpers for virtualenv
New in version 1.2.
-
exception
pyquickhelper.pycode.venv_helper.
NotImplementedErrorFromVirtualEnvironment
[source]¶ Bases:
NotImplementedError
defines an exception when a function does not work in a virtual environment
New in version 1.3.
-
exception
pyquickhelper.pycode.venv_helper.
VirtualEnvError
[source]¶ Bases:
Exception
exception raised by the function implemented in this file
-
pyquickhelper.pycode.venv_helper.
build_venv_cmd
(params, posparams)[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 at 0x00000210845D3950>)[source]¶ check 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.
New in version 1.3.
-
pyquickhelper.pycode.venv_helper.
compare_module_version
(num, vers)[source]¶ compare two versions
Parameters: - num – first version
- vers – second version
Returns: -1, 0, 1
Changed in version 1.3: Fix a bug (do not use ModuleInstall)
-
pyquickhelper.pycode.venv_helper.
create_virtual_env
(where, symlinks=False, system_site_packages=False, clear=True, packages=None, fLOG=<function noLOG at 0x00000210845D3950>, temp_folder=None)[source]¶ create 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
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]¶ tells if the script is run from a virtual environment
Returns: boolean New in version 1.3.
-
pyquickhelper.pycode.venv_helper.
numeric_module_version
(vers)[source]¶ convert a string into a tuple with numbers whever possible
Parameters: vers – string Returns: tuple
-
pyquickhelper.pycode.venv_helper.
run_venv_script
(venv, script, fLOG=<function noLOG at 0x00000210845D3950>, file=False, is_cmd=False, skip_err_if=None)[source]¶ run 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
Returns: output
The function does not work from a virtual environment.
-
pyquickhelper.pycode.venv_helper.
venv_install
(venv, packages, fLOG=<function noLOG at 0x00000210845D3950>, temp_folder=None)[source]¶ install 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
Returns: standard output
The function does not work from a virtual environment.