Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit 2c3d54f

Browse files
committed
docs: ext: consoletest: Check pip install for correct invocation
Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
1 parent 0fa3f05 commit 2c3d54f

File tree

10 files changed

+56
-38
lines changed

10 files changed

+56
-38
lines changed

.ci/dffml-install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if [ "x${DFFML_RELEASE}" == "xmaster" ]; then
77
pip install -e .
88
dffml service dev install
99
elif [ "x${DFFML_RELEASE}" == "xlatest" ]; then
10-
pip install dffml[all]
10+
pip install --use-feature=2020-resolver dffml[all]
1111
else
12-
pip install "dffml[all]==${DFFML_RELEASE}"
12+
pip install --use-feature=2020-resolver "dffml[all]==${DFFML_RELEASE}"
1313
fi

docs/_ext/consoletest.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -552,11 +552,36 @@ async def run(self, ctx):
552552
await super().run(ctx)
553553

554554

555+
class PipNotRunAsModule(Exception):
556+
"""
557+
Raised when a pip install command was not prefixed with python -m to run pip
558+
as a module. Pip sometimes complains when this is not done.
559+
"""
560+
561+
562+
class PipMissingUseFeature2020Resolver(Exception):
563+
"""
564+
Raised when a pip install command isn't upgrading pip and doesn't have
565+
--use-feature=2020-resolver
566+
"""
567+
568+
555569
class PipInstallCommand(ConsoleCommand):
556570
def __init__(self, cmd: List[str]):
557571
super().__init__(cmd)
558572
self.directories: List[str] = []
559573
self.fix_dffml_packages()
574+
# Ensure that we are running pip using it's module invocation
575+
if self.cmd[:2] != ["python", "-m"]:
576+
raise PipNotRunAsModule(cmd)
577+
# Ensure command have --use-feature=2020-resolver
578+
# If we are installing pip then we may or may not be upgrading from
579+
# a version that has it, so don't raise an excption
580+
if (
581+
not (self.cmd.count("pip") == 2 and "-U" in self.cmd)
582+
and "--use-feature=2020-resolver" not in self.cmd
583+
):
584+
raise PipMissingUseFeature2020Resolver(cmd)
560585

561586
def fix_dffml_packages(self):
562587
"""
@@ -590,19 +615,7 @@ def fix_dffml_packages(self):
590615
self.cmd.insert(i, "-e")
591616
self.directories.append(directory)
592617

593-
async def pip_has_use_feature(self, ctx):
594-
with tempfile.TemporaryFile() as stdout:
595-
with contextlib.redirect_stdout(stdout):
596-
await run_commands([["python", "-m", "pip", "-h"]], ctx)
597-
stdout.seek(0)
598-
return "--use-feature" in stdout.read().decode()
599-
600618
async def run(self, ctx):
601-
# Add --use-feature=2020-resolver to pip if it has it
602-
if await self.pip_has_use_feature(ctx):
603-
self.cmd.insert(
604-
self.cmd.index("install") + 1, "--use-feature=2020-resolver"
605-
)
606619

607620
await super().run(ctx)
608621

docs/examples/integration.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ Make sure to update ``pip`` in case it's old, and install ``setuptools`` and
103103
.. code-block:: console
104104
:test:
105105
106-
$ python3 -m venv .venv
106+
$ python -m venv .venv
107107
$ . .venv/bin/activate
108-
$ pip install -U pip setuptools wheel
108+
$ python -m pip install -U pip setuptools wheel
109109
110110
Download the Python client libraries for MySQL.
111111

112112
.. code-block:: console
113113
:test:
114114
115-
$ pip install -U \
115+
$ python -m pip install --use-feature=2020-resolver -U \
116116
https://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-8.0.21.tar.gz
117117
118118
Start MariaDB (functionally very similar to MySQL which its a fork of).
@@ -152,7 +152,7 @@ MariaDB/MySQL with DFFML.
152152
.. code-block:: console
153153
:test:
154154
155-
$ pip install -U dffml-source-mysql
155+
$ python -m pip install --use-feature=2020-resolver -U dffml-source-mysql
156156
157157
To get our dummy data, we'll be using the GitHub v4 API to search for "todo".
158158
The search should return repos implementing a TODO app.
@@ -278,7 +278,7 @@ configs than ``json``.
278278
.. code-block:: console
279279
:test:
280280
281-
$ pip install -U dffml-feature-git dffml-config-yaml
281+
$ python -m pip install --use-feature=2020-resolver -U dffml-feature-git dffml-config-yaml
282282
283283
The git operations / features rely on ``tokei``. We need to download and install
284284
it first.
@@ -408,7 +408,7 @@ another separate Python package from DFFML which we can install via ``pip``.
408408
.. code-block:: console
409409
:test:
410410
411-
$ pip install -U dffml-model-tensorflow
411+
$ python -m pip install --use-feature=2020-resolver -U dffml-model-tensorflow
412412
413413
The model is a generic wrapper around Tensorflow's DNN estimator. We can use it
414414
to train on our dataset.

docs/installation.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ First make sure you have the latest versions of ``pip``, ``setuptools``, and
2020
.. code-block:: console
2121
:test:
2222
23-
$ python3 -m pip install -U pip setuptools wheel
23+
$ python -m pip install -U pip setuptools wheel
2424
2525
.. group-tab:: Windows
2626

@@ -43,13 +43,13 @@ package.
4343
.. code-block:: console
4444
:test:
4545
46-
$ python3 -m pip install -U dffml
46+
$ python -m pip install --use-feature=2020-resolver -U dffml
4747
4848
.. group-tab:: Windows
4949

5050
.. code-block:: console
5151
52-
(.venv) C:\Users\username> python -m pip install -U dffml
52+
(.venv) C:\Users\username> python -m pip install --use-feature=2020-resolver -U dffml
5353
5454
If you want to install all of the machine learning model plugins that are
5555
maintained as a part of the core repository, you can append ``[models]``.
@@ -60,13 +60,13 @@ maintained as a part of the core repository, you can append ``[models]``.
6060

6161
.. code-block:: console
6262
63-
$ python3 -m pip install -U dffml[models]
63+
$ python -m pip install --use-feature=2020-resolver -U dffml[models]
6464
6565
.. group-tab:: Windows
6666

6767
.. code-block:: console
6868
69-
(.venv) C:\Users\username> python -m pip install -U dffml[models]
69+
(.venv) C:\Users\username> python -m pip install --use-feature=2020-resolver -U dffml[models]
7070
7171
If you want to install all of the machine learning model plugins and all the
7272
data sources and DataFlow operations that are maintained as a part of the core
@@ -78,13 +78,13 @@ repository, you can append ``[all]``.
7878

7979
.. code-block:: console
8080
81-
$ python3 -m pip install -U dffml[all]
81+
$ python -m pip install --use-feature=2020-resolver -U dffml[all]
8282
8383
.. group-tab:: Windows
8484

8585
.. code-block:: console
8686
87-
(.venv) C:\Users\username> python -m pip install -U dffml[all]
87+
(.venv) C:\Users\username> python -m pip install --use-feature=2020-resolver -U dffml[all]
8888
8989
If you want to stay on the bleeding edge of bug fixes, etc. You can install from
9090
the master branch.
@@ -96,13 +96,13 @@ the master branch.
9696
.. code-block:: console
9797
:test:
9898
99-
$ python3 -m pip install -U "https://github.com/intel/dffml/archive/master.zip#egg=dffml"
99+
$ python -m pip install --use-feature=2020-resolver -U "https://github.com/intel/dffml/archive/master.zip#egg=dffml"
100100
101101
.. group-tab:: Windows
102102

103103
.. code-block:: console
104104
105-
(.venv) C:\Users\username> python -m pip install -U "https://github.com/intel/dffml/archive/master.zip#egg=dffml"
105+
(.venv) C:\Users\username> python -m pip install --use-feature=2020-resolver -U "https://github.com/intel/dffml/archive/master.zip#egg=dffml"
106106
107107
You can also install the bleeding edge version of any plugin. To get the
108108
subdirectory you should use, take the package name on PyPi and remove ``dffml-``
@@ -115,14 +115,14 @@ and replace ``-`` with ``/``.
115115
.. code-block:: console
116116
:test:
117117
118-
$ python3 -m pip install -U "https://github.com/intel/dffml/archive/master.zip#egg=dffml" \
118+
$ python -m pip install --use-feature=2020-resolver -U "https://github.com/intel/dffml/archive/master.zip#egg=dffml" \
119119
"https://github.com/intel/dffml/archive/master.zip#egg=dffml-feature-git&subdirectory=feature/git"
120120
121121
.. group-tab:: Windows
122122

123123
.. code-block:: console
124124
125-
(.venv) C:\Users\username> python -m pip install -U "https://github.com/intel/dffml/archive/master.zip#egg=dffml" ^
125+
(.venv) C:\Users\username> python -m pip install --use-feature=2020-resolver -U "https://github.com/intel/dffml/archive/master.zip#egg=dffml" ^
126126
"https://github.com/intel/dffml/archive/master.zip#egg=dffml-feature-git&subdirectory=feature/git"
127127
128128
There's an online IDE based on Theia (similar to VS Code) called GitPod that

docs/tutorials/models/iris.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ the ``dffml-model-tensorflow`` plugin.
1212
.. code-block:: console
1313
:test:
1414
15-
$ python -m pip install dffml-model-tensorflow
15+
$ python -m pip install --use-feature=2020-resolver dffml-model-tensorflow
1616
1717
Iris Dataset
1818
------------

docs/tutorials/models/package.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ package.
5959

6060
.. code-block:: console
6161
62-
$ pip install -e .
62+
$ python -m pip install --use-feature=2020-resolver -e .
6363
6464
Testing
6565
-------
@@ -215,7 +215,7 @@ And remember that any time we modify the **setup.py**, we have to re-install.
215215
.. code-block:: console
216216
:test:
217217
218-
$ pip install -e .
218+
$ python -m pip install --use-feature=2020-resolver -e .
219219
220220
Command Line Usage
221221
------------------

docs/tutorials/models/slr.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ information on the HTTP service.
266266
.. code-block:: console
267267
:test:
268268
269-
$ pip install -U dffml-service-http
269+
$ python -m pip install --use-feature=2020-resolver -U dffml-service-http
270270
271271
We start the HTTP service and tell it that we want to make our model accessable
272272
via the HTTP :ref:`plugin_service_http_api_model` API.

docs/tutorials/sources/complex.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ The following command installs your new source.
8080

8181
.. code-block:: console
8282
83-
$ python -m pip install -e .
83+
$ python -m pip install --use-feature=2020-resolver -e .
8484
8585
Write the tests
8686
---------------

docs/tutorials/sources/file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ To install your new source run
206206
.. code-block:: console
207207
:test:
208208
209-
$ python -m pip install -e .
209+
$ python -m pip install --use-feature=2020-resolver -e .
210210
211211
CLI Usage
212212
---------

tests/docs/test_consoletest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,11 @@ class TestPipInstallCommand(unittest.TestCase):
120120
def test_fix_dffml_packages(self):
121121
command = consoletest.PipInstallCommand(
122122
[
123+
"python",
124+
"-m",
123125
"pip",
124126
"install",
127+
"--use-feature=2020-resolver",
125128
"-U",
126129
"dffml",
127130
"-e",
@@ -130,12 +133,14 @@ def test_fix_dffml_packages(self):
130133
"aiohttp",
131134
]
132135
)
133-
command.fix_dffml_packages()
134136
self.assertListEqual(
135137
command.cmd,
136138
[
139+
"python",
140+
"-m",
137141
"pip",
138142
"install",
143+
"--use-feature=2020-resolver",
139144
"-U",
140145
"-e",
141146
os.path.abspath(ROOT_DIR),

0 commit comments

Comments
 (0)