From f42fcaa2b8b4a3be4bf08c25bd4f38881bb56338 Mon Sep 17 00:00:00 2001 From: Jeremy Fleischman Date: Thu, 6 Jan 2022 22:17:44 -0800 Subject: [PATCH 1/2] Misc doc updates (mostly around running tests) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds and documents a workaround for https://github.com/pypa/pipenv/issues/4909. It feels a bit weird to pretend to be CI just to run the test suite, though. Maybe we can do something about that later. I ran into a lot of trouble trying to get the tests to run when working on https://github.com/pypa/pipenv/pull/4908, and that was largely because the instructions in this CONTRIBUTING.md file seem to have rotted. 1. The bit about "can be run very simply" is bogus. It's unfortunately not that simple right now. 2. `make test` (the docker approach) fails for me with this error: ```bash $ make test docker-compose up [+] Running 1/0 ⠿ Container pipenv-pipenv-tests-1 Recreated 0.1s Attaching to pipenv-pipenv-tests-1 pipenv-pipenv-tests-1 | Collecting certifi pipenv-pipenv-tests-1 | Downloading https://files.pythonhosted.org/packages/37/45/946c02767aabb873146011e665728b680884cd8fe70dde973c640e45b775/certifi-2021.10.8-py2.py3-none-any.whl (149kB) pipenv-pipenv-tests-1 | Installing collected packages: certifi pipenv-pipenv-tests-1 | Successfully installed certifi-2021.10.8 pipenv-pipenv-tests-1 | Path: /root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin pipenv-pipenv-tests-1 | Installing Pipenv... pipenv-pipenv-tests-1 | Obtaining file:///pipenv pipenv-pipenv-tests-1 | Complete output from command python setup.py egg_info: pipenv-pipenv-tests-1 | Traceback (most recent call last): pipenv-pipenv-tests-1 | File "", line 1, in pipenv-pipenv-tests-1 | File "/pipenv/setup.py", line 55 pipenv-pipenv-tests-1 | print(f"\033[1m{s}\033[0m") pipenv-pipenv-tests-1 | ^ pipenv-pipenv-tests-1 | SyntaxError: invalid syntax pipenv-pipenv-tests-1 | pipenv-pipenv-tests-1 | ---------------------------------------- pipenv-pipenv-tests-1 | Command "python setup.py egg_info" failed with error code 1 in /pipenv/ pipenv-pipenv-tests-1 exited with code 1 ``` The docker image it relies upon (https://hub.docker.com/r/kennethreitz/pipenv-tests) hasn't been updated in 4 years, so I assume it's just not something people use anymore? 3. Relatedly, there was a `Dockerfile` at the root of this repo that appears to be unused. Let me know if it's used somewhere I'm not realizing, I can add it back! 4. https://kennethreitz.org/essays/be-cordial-or-be-on-your-way seems to be a broken link now. I found https://kennethreitz.org/essays/2013/01/27/be-cordial-or-be-on-your-way on Google. 5. `./run-tests.sh` doesn't work for me. It's failing for the same reason described by @ncoghlan here: https://github.com/pypa/pip/issues/7953#issuecomment-611928262. He said something about a `PIPENV_BOOTSTRAP` environment variable, but I can't find any information about that. --- .dockerignore | 11 ----------- CONTRIBUTING.md | 22 +++++++++------------- Dockerfile | 39 --------------------------------------- MANIFEST.in | 3 +-- Makefile | 2 -- docker-compose.yml | 7 ------- pipenv/core.py | 2 ++ tests/conftest.py | 5 +++++ 8 files changed, 17 insertions(+), 74 deletions(-) delete mode 100644 .dockerignore delete mode 100644 Dockerfile delete mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index c9efdaeab1..0000000000 --- a/.dockerignore +++ /dev/null @@ -1,11 +0,0 @@ -./examples -./tests -./docs -./news -./pipenv -./.git -./.buildkite -./peeps -./.github -./tasks -./.azure-pipelines diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 332423f86a..2582484591 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,7 +29,7 @@ General Guidelines Pipenv has one very important rule governing all forms of contribution, including reporting bugs or requesting features. This golden rule is \"[be cordial or be on your -way](https://www.kennethreitz.org/essays/be-cordial-or-be-on-your-way)\". +way](https://kennethreitz.org/essays/2013/01/27/be-cordial-or-be-on-your-way)\". **All contributions are welcome**, as long as everyone involved is treated with respect. @@ -87,7 +87,7 @@ When contributing code, you\'ll want to follow this checklist: 6. Make your change. 7. Run the entire test suite again, confirming that all tests pass *including the ones you just added*. -8. Send a GitHub Pull Request to the main repository\'s `master` +8. Send a GitHub Pull Request to the main repository\'s `main` branch. GitHub Pull Requests are the expected method of code collaboration on this project. @@ -115,13 +115,9 @@ details. ### Testing -Tests are written in `pytest` style and can be run very simply: +Tests are written in `pytest` style. -``` {.sh} -pytest -``` - -This will run all Pipenv tests, which can take awhile. To run a subset +Running all tests can take awhile. To run a subset of the tests, the standard pytest filters are available, such as: - provide a directory or file: `pytest tests/unit` or @@ -218,11 +214,11 @@ following things when filing bug reports: Run the tests ------------- -Three ways of running the tests are as follows: +Two ways of running the tests are as follows: -1. `make test` (which uses `docker`) -2. `./run-tests.sh` or `run-tests.bat` -3. Using pipenv: +1. `./run-tests.sh` or `run-tests.bat` + - NOTE: `./run-tests.sh` is not working right now due to [this issue](https://github.com/pypa/pip/issues/7953#issuecomment-611928262). +2. Using pipenv: ``` {.console} $ git clone https://github.com/pypa/pipenv.git @@ -232,7 +228,7 @@ $ pipenv install --dev $ pipenv run pytest ``` -For the last two, it is important that your environment is setup +To run tests, it is important that your environment is setup correctly, and this may take some work, for example, on a specific Mac installation, the following steps may be needed: diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 96ecfdeb67..0000000000 --- a/Dockerfile +++ /dev/null @@ -1,39 +0,0 @@ -FROM heroku/heroku:18-build - -ENV DEBIAN_FRONTEND noninteractive -ENV LC_ALL C.UTF-8 -ENV LANG C.UTF-8 -# Python, don't write bytecode! -ENV PYTHONDONTWRITEBYTECODE 1 - -# -- Install Pipenv: -RUN apt update && apt install python3.7-dev libffi-dev -y -RUN curl --silent https://bootstrap.pypa.io/get-pip.py | python3.7 - -# Backwards compatility. -RUN rm -fr /usr/bin/python3 && ln /usr/bin/python3.7 /usr/bin/python3 - -RUN pip3 install pipenv - -# -- Install Application into container: -RUN set -ex && mkdir /app - -WORKDIR /app - -# -- Adding Pipfiles -ONBUILD COPY Pipfile Pipfile -ONBUILD COPY Pipfile.lock Pipfile.lock - -# -- Install dependencies: -ONBUILD RUN set -ex && pipenv install --deploy --system - -# -------------------- -# - Using This File: - -# -------------------- - -# FROM kennethreitz/pipenv - -# COPY . /app - -# -- Replace with the correct path to your app's main executable -# CMD python3 main.py diff --git a/MANIFEST.in b/MANIFEST.in index bea07b5d19..75fc739c1a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,5 @@ include LICENSE README.md CONTRIBUTING.md CHANGELOG.rst NOTICES HISTORY.txt -include Makefile pyproject.toml get-pipenv.py .dockerignore *.yml +include Makefile pyproject.toml get-pipenv.py *.yml include examples/Pipfil* include *.md recursive-include pipenv LICENSE LICENSE* *LICENSE* *COPYING* t32.exe t64.exe w32.exe w64.exe cacert.pem @@ -20,7 +20,6 @@ include pipenv/pipenv.1 exclude .gitmodules exclude .editorconfig .travis.yml .env appveyor.yml tox.ini pytest.ini exclude Pipfile* CHANGELOG.draft.rst -exclude docker-compose.yml Dockerfile exclude run-tests.sh run-tests.bat recursive-include docs Makefile *.rst *.py *.bat diff --git a/Makefile b/Makefile index 0d8ecfe96a..eb0220c381 100644 --- a/Makefile +++ b/Makefile @@ -23,8 +23,6 @@ piptools-checkout-dir = $(get_checkout_dir)/patch-piptools format: black pipenv/*.py -test: - docker-compose up .PHONY: install install: diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 1fede25aae..0000000000 --- a/docker-compose.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: '3' -services: - pipenv-tests: - image: kennethreitz/pipenv-tests - command: bash /pipenv/run-tests.sh - volumes: - - .:/pipenv diff --git a/pipenv/core.py b/pipenv/core.py index 6ce17bf315..420dbf5684 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -2496,6 +2496,8 @@ def do_run(project, command, args, three=None, python=False, pypi_mirror=None): click.echo("Can't run script {0!r}-it's empty?", err=True) run_args = [project, script] run_kwargs = {'env': env} + # We're using `do_run_nt` on CI (even if we're running on a non-nt machine) + # as a workaround for https://github.com/pypa/pipenv/issues/4909. if os.name == "nt" or environments.PIPENV_IS_CI: run_fn = do_run_nt else: diff --git a/tests/conftest.py b/tests/conftest.py index fc75b6b572..a07377194a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,9 @@ import pytest +import os + +def pytest_sessionstart(session): + # CI=1 is necessary as a workaround for https://github.com/pypa/pipenv/issues/4909 + os.environ['CI'] = '1' @pytest.fixture() From 08a7fcf1cd8285683c47140b36b3d181e9448273 Mon Sep 17 00:00:00 2001 From: Jeremy Fleischman Date: Fri, 7 Jan 2022 00:12:15 -0800 Subject: [PATCH 2/2] Oops, set the `CI` environment variable even earlier. If I do something like `pytest tests/integration/test_cli.py`, something about the ordering of imports means that `pipenv.environments` gets loaded *before* `pytest_sessionstart` runs, which means that `pipenv.environments.PIPENV_IS_CI` ends up false. --- tests/conftest.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index a07377194a..13778403e4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,14 @@ import pytest import os +# Note that we have to do this *before* `pipenv.environments` gets imported, +# which is why we're doing it here as a side effect of importing this module. +# CI=1 is necessary as a workaround for https://github.com/pypa/pipenv/issues/4909 +os.environ['CI'] = '1' + def pytest_sessionstart(session): - # CI=1 is necessary as a workaround for https://github.com/pypa/pipenv/issues/4909 - os.environ['CI'] = '1' + import pipenv.environments + assert pipenv.environments.PIPENV_IS_CI @pytest.fixture()