aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-03-03 19:45:46 -0800
committerGravatar MarkKoz <[email protected]>2020-03-03 19:46:27 -0800
commit93f29f8bfee77957770dab3dd9adc1dac62d0bb2 (patch)
tree349daa827b6936155b967fe9b1cfcfae2e6af801
parentCI: add a restore key for the pre-commit cache (diff)
CI: mock the pipenv binary
The mock gets used by the flake8 pre-commit hook, which invokes flake8 via `pipenv run flake8`. It's normally useful to use pipenv here cause it ensures flake8 is invoked within the context of the venv. However, in CI, there is no venv - dependencies are installed directly to the system site-packages. `pipenv run` does not work in such case because it tries to create a new venv if one doesn't exist (it doesn't consider the system interpreter to be a venv). This workaround (okay, it's a hack) creates an executable shell script which replaces the original pipenv binary. The shell script simply ignores the first argument (i.e. ignores `run` in `pipenv run`) and executes the rest of the arguments as a command. It essentially makes `pipenv run flake8` equivalent to just having ran `flake8`. When pre-commit executes pipenv, the aforementioned script is what will run.
-rw-r--r--azure-pipelines.yml10
1 files changed, 10 insertions, 0 deletions
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index fa85e6045..280f11a36 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -29,6 +29,16 @@ jobs:
- script: pipenv install --dev --deploy --system
displayName: 'Install project using pipenv'
+ # Create an executable shell script which replaces the original pipenv binary.
+ # The shell script ignores the first argument and executes the rest of the args as a command.
+ # It makes the `pipenv run flake8` command in the pre-commit hook work by circumventing
+ # pipenv entirely, which is too dumb to know it should use the system interpreter rather than
+ # creating a new venv.
+ - script: |
+ printf '%s\n%s' '#!/bin/bash' '"${@:2}"' > $(PythonVersion.pythonLocation)/bin/pipenv \
+ && chmod +x $(PythonVersion.pythonLocation)/bin/pipenv
+ displayName: 'Mock pipenv binary'
+
- task: Cache@2
displayName: 'Restore pre-commit environment'
inputs: