Skip to content

Commit 0edbe4e

Browse files
authored
remove the python package reuse example (#4262)
1 parent d06b727 commit 0edbe4e

File tree

1 file changed

+3
-108
lines changed

1 file changed

+3
-108
lines changed

reference/tools/system/pipenv.rst

Lines changed: 3 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,19 @@ PipEnv
88

99
.. important::
1010

11-
This is **only** for executable Python packages.
12-
This approach doesn't work for Python library packages that you would typically use via ``import``.
11+
This is **only** for executable Python packages and its Python dependencies.
12+
This approach doesn't work for Python library packages that you would typically use via ``import`` inside your recipe.
1313

1414
The ``PipEnv`` helper installs executable Python packages with **pip** inside a dedicated virtual environment (**venv**),
1515
keeping them isolated so they don't interfere with system packages or the Conan package itself.
16+
It is designed to use a Python CLI tool inside a recipe during the build step.
1617

1718
.. currentmodule:: conan.tools.system
1819

1920
.. autoclass:: PipEnv
2021
:members:
2122
:inherited-members:
2223

23-
It is designed to be used in two different ways:
24-
25-
1. Using a Python CLI tool inside a recipe.
26-
2. Use a tool installed as a Python package locally and reuse it in other recipes.
27-
2824
Using a Python package in a recipe
2925
----------------------------------
3026

@@ -82,104 +78,3 @@ If we run a ``conan build`` we can see how our Python package is installed when
8278
conanfile.py (pip_install/0.1): Calling build()
8379
conanfile.py (pip_install/0.1): RUN: meson --version
8480
1.9.1
85-
86-
87-
Use a tool installed as a Python package and reuse it in other recipes
88-
----------------------------------------------------------------------
89-
90-
In this case, we want to locally embed the installation of a tool using pip and reuse it as a conan recipe.
91-
92-
To do this, we need to install our tool using ``PipEnv.install()``, but in this case we will specify that we want it
93-
to create the virtualenv in the ``package_folder``.
94-
95-
In this case, we don't need to call the ``PipEnv.generate()`` method because we're not going to use the tool within this recipe.
96-
We just want to make it reusable.
97-
98-
When creating a recipe to encapsulate a tool installed with Python, several things must be taken into account:
99-
100-
- The packages are installed in the `finalize()` method. This ensures that the contents of the package folder do not change when the installed tools are run,
101-
because Python packages normally generate certain files when executed.
102-
- We will add the properties ``build_policy = "missing"`` and ``upload_policy = "skip"`` to the recipe to ensure that it is only used locally
103-
and the resulting package will not be uploaded. This is important because **the generated package only works on the machine on which it was generated**
104-
due to how Python virtual environments work.
105-
106-
.. code-block:: python
107-
:caption: conanfile.py
108-
109-
from conan import ConanFile
110-
from conan.tools.system import PipEnv
111-
from conan.tools.layout import basic_layout
112-
113-
114-
class MesonPipPackage(ConanFile):
115-
name = "pip_meson"
116-
version = "0.1"
117-
build_policy = "missing"
118-
upload_policy = "skip"
119-
120-
def layout(self):
121-
basic_layout(self)
122-
123-
def finalize(self):
124-
PipEnv(self, self.package_folder).install(["meson==1.9.1"])
125-
126-
def package_info(self):
127-
python_env_bin = PipEnv(self, self.package_folder).bin_dir
128-
self.buildenv_info.prepend_path("PATH", python_env_bin)
129-
130-
.. code-block:: bash
131-
132-
$ conan create . --version 0.1
133-
134-
-------- Installing package pip_meson/0.1 (1 of 1) --------
135-
...
136-
pip_meson/0.1: Calling finalize()
137-
pip_meson/0.1: RUN: /Users/user/.conan2/p/b/pip_m19e45e29ec612/f/pip_venv_pip_meson/bin/python -m pip install --disable-pip-version-check meson==1.9.1
138-
Collecting meson==1.9.1
139-
Using cached meson-1.9.1-py3-none-any.whl.metadata (1.8 kB)
140-
Using cached meson-1.9.1-py3-none-any.whl (1.0 MB)
141-
Installing collected packages: meson
142-
Successfully installed meson-1.9.1
143-
144-
.. code-block:: python
145-
:caption: conanfile.py
146-
147-
from conan import ConanFile
148-
149-
150-
class PipBuildPackage(ConanFile):
151-
name = "reuse_pip"
152-
version = "0.1"
153-
154-
def requirements(self):
155-
self.tool_requires("pip_meson/0.1")
156-
157-
def build(self):
158-
self.run("meson --version")
159-
160-
.. code-block:: bash
161-
162-
$ conan build .
163-
164-
======== Computing dependency graph ========
165-
Graph root
166-
conanfile.py (reuse_pip/0.1): /Users/user/reuse_pip/conanfile.py
167-
Build requirements
168-
pip_meson/0.1#0f1f4d0fc28b2ef5951f42131ede4f99 - Cache
169-
170-
======== Computing necessary packages ========
171-
Build requirements
172-
pip_meson/0.1#0f1f4d0fc28b2ef5951f42131ede4f99:da39a3ee5e6b4b0d3255bfef95601890afd80709#0ba8627bd47edc3a501e8f0eb9a79e5e - Cache
173-
174-
======== Installing packages ========
175-
pip_meson/0.1: Already installed! (1 of 1)
176-
pip_meson/0.1: Finalized folder /Users/user/.conan2/p/b/pip_m19e45e29ec612/f
177-
178-
======== Finalizing install (deploy, generators) ========
179-
conanfile.py (reuse_pip/0.1): Generating aggregated env files
180-
conanfile.py (reuse_pip/0.1): Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
181-
182-
======== Calling build() ========
183-
conanfile.py (reuse_pip/0.1): Calling build()
184-
conanfile.py (reuse_pip/0.1): RUN: meson --version
185-
1.9.1

0 commit comments

Comments
 (0)