|
| 1 | +:orphan: |
| 2 | + |
1 | 3 | .. _conan_tools_system_pipenv: |
2 | 4 |
|
3 | 5 |
|
4 | 6 | PipEnv |
5 | 7 | ====== |
6 | 8 |
|
7 | | -.. include:: ../../../common/experimental_warning.inc |
8 | | - |
9 | | -.. important:: |
10 | | - |
11 | | - This is **only** for: |
12 | | - - **Executable Python packages and its Python dependencies.** (for example, meson build system) |
13 | | - - **Python package used during the source build process.** (for example, html5lib as a build dependency) |
14 | | - This approach doesn't work for Python library packages that you would typically use via ``import`` inside your recipe. |
15 | | - |
16 | | -The ``PipEnv`` helper installs executable Python packages with **pip** inside a dedicated virtual environment (**venv**), |
17 | | -keeping them isolated so they don't interfere with system packages or the Conan package itself. |
18 | | -It is designed to use a Python CLI tool inside a recipe during the build step. |
19 | | - |
20 | | -By default, it attempts to create the virtualenv using the Python you have set on your system Path. |
21 | | -To use a different one, you can set a Python path in the ``tools.system.pipenv:python_interpreter`` :ref:`configuration<reference_config_files_global_conf>`. |
22 | | - |
23 | | - |
24 | | -.. currentmodule:: conan.tools.system |
25 | | - |
26 | | -.. autoclass:: PipEnv |
27 | | - :members: |
28 | | - :inherited-members: |
29 | | - |
30 | | -Using a Python package in a recipe |
31 | | ----------------------------------- |
32 | | - |
33 | | -To install a python package or use a tool installed with Python, we have to install it using the ``PipEnv.install()`` method. |
34 | | -We also have to call the ``PipEnv.generate()`` method to create a **Conan Environment** that adds the **Python virtualenv path** to the system path. |
35 | | - |
36 | | -These two steps appear in the following recipe in the ``generate()`` method. |
37 | | -Calling it in this method ensures that the **Python package** and the **Conan Environment** will be available in the following steps. |
38 | | -In this case, in the build step, which is where we will use the installed tool. |
39 | | - |
40 | | -.. code-block:: python |
41 | | - :caption: conanfile.py |
42 | | -
|
43 | | - from conan import ConanFile |
44 | | - from conan.tools.system import PipEnv |
45 | | - from conan.tools.layout import basic_layout |
46 | | -
|
47 | | -
|
48 | | - class PipPackage(ConanFile): |
49 | | - name = "pip_install" |
50 | | - version = "0.1" |
51 | | -
|
52 | | - def layout(self): |
53 | | - basic_layout(self) |
54 | | -
|
55 | | - def generate(self): |
56 | | - PipEnv(self).install(["meson==1.9.1"]) |
57 | | - PipEnv(self).generate() |
58 | | -
|
59 | | - def build(self): |
60 | | - self.run("meson --version") |
61 | | -
|
62 | | -If we run a ``conan build`` we can see how our Python package is installed when the generate step, and how it is called in the build step as if it were installed on the system. |
63 | | - |
64 | | -.. code-block:: bash |
65 | | -
|
66 | | - $ conan build . |
67 | | -
|
68 | | - ... |
69 | | -
|
70 | | - ======== Finalizing install (deploy, generators) ======== |
71 | | - conanfile.py (pip_install/0.1): Calling generate() |
72 | | - conanfile.py (pip_install/0.1): Generators folder: /Users/user/pip_install/build/conan |
73 | | - conanfile.py (pip_install/0.1): RUN: /Users/user/pip_install/build/pip_venv_pip_install/bin/python -m pip install --disable-pip-version-check meson==1.9.1 |
74 | | - Collecting meson==1.9.1 |
75 | | - Using cached meson-1.9.1-py3-none-any.whl.metadata (1.8 kB) |
76 | | - Using cached meson-1.9.1-py3-none-any.whl (1.0 MB) |
77 | | - Installing collected packages: meson |
78 | | - Successfully installed meson-1.9.1 |
79 | | -
|
80 | | - conanfile.py (pip_install/0.1): Generating aggregated env files |
81 | | - conanfile.py (pip_install/0.1): Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh'] |
| 9 | +.. warning:: |
82 | 10 |
|
83 | | - ======== Calling build() ======== |
84 | | - conanfile.py (pip_install/0.1): Calling build() |
85 | | - conanfile.py (pip_install/0.1): RUN: meson --version |
86 | | - 1.9.1 |
| 11 | + Starting with Conan version 2.25.0, `PipEnv`` is deprecated and has been renamed to `PyEnv`. |
| 12 | + Please update your recipes to use `PyEnv`` to ensure future compatibility. You can find |
| 13 | + the :ref:`complete documentantion about PyEnv here <conan_tools_system_pyenv>`. |
0 commit comments