Update pyenv pyenvinstall Make targets #2517
Conversation
f809980
to
577ab86
Compare
From #2514 (comment) :
The cache contains a copy './local'. It seems the cache is corrupted.
|
ca40751
to
c49efd2
Compare
It should fix the CI. @return42 can you give a look ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comments. All in all it LGTM .. there are two things that bother me a bit.
- I made some test and killed the
make clean pyenv
to get a corrupt/local
.. the pyyaml problem still exists under some circumstance. makefile.python
is abstract, only and handles common python, pip and setuptools issues. This patch adds somepyyaml
aspects and is not an abstract solution.
At the moment I don't have more time and I also don't have a better solution right now. Is it OK for you to wait with merge. Otherwise I can also think about a more abstract solution afterwards.
@@ -119,13 +120,13 @@ quiet_cmd_pyenvuninstall = PYENV uninstall $2 | |||
# $2 path to folder where virtualenv take place | |||
quiet_cmd_virtualenv = PYENV usage: $ source ./$@/bin/activate | |||
cmd_virtualenv = \ | |||
if [ ! -d "./$(PY_ENV)" ];then \ | |||
$(PYTHON) -m venv $(VTENV_OPTS) $2; \ | |||
if [ -d "./$(PY_ENV)" -a -x "./$(PY_ENV_BIN)/python" ]; then \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking the existence of ./$(PY_ENV_BIN)/python"
makes also sense to me. This might help in cases where a previous build of the virtualenv has been failed for any reason.
I thought twice about a more robust criteria but I don't have anything better to suggest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thought: now, with removing $(PY_ENV)/requirements.sha256
before running pip install
and the && sha256sum requirements*.txt > $(PY_ENV)/requirements.sha256
from line 104-105, checking existence of $(PY_ENV)/requirements.sha256
could be a good criteria here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a case where the pyenv
target is invoked but not the pyenvinstall
target ?
- if no, why there are two targets ?
- if yes, then we can't
$(PY_ENV)/requirements.sha256
: each invocation ofpyenv
will reinstall the virtualenv.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These makefiles has been implemented for general use cases. I use them in several projects as boilerplate. The motivation was to have typical development workflows localy at hand, build on simple tools available nearly everywhere.
Back to your question why there are two targets ?
pyenv: builds the environment for development / typically requirements.txt
penvinstall: installs the python package in this environment (pip install -e
) / typically setup.py
In the searx project requirements.txt
and setup.py
include identical requirements but this is not typical for python projects. Beside this you can also think about projects containing more than one package.
Is there a case where the pyenv target is invoked but not the pyenvinstall target ?
With the words above, my answer is: it depends .. But from makefile.python
's POV the answer is : yes
Your questions helped me to sort my thoughts, but for today I am to tired .. tomorrow I have more time, then I'll think about it again ..
- pyyaml in setup.py
- each invocation of pyenv will reinstall the virtualenv
Abstract version:
But:
|
$(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) install -e $2$(PY_SETUP_EXTRAS) ;\ | ||
rm -f $(PY_ENV)/requirements.sha256; \ | ||
$(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) install $$(grep pyyaml ./requirements.txt); \ | ||
$(PY_ENV_BIN)/python -m pip $(PIP_VERBOSE) install -e $2$(PY_SETUP_EXTRAS) &&\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought: if I ignore the git workflow caching issue and have a complete new look at this two lines, I cant understand why line 103 is needed .. or did I lost the overview?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 11 in 71d6697
from searx import brand |
brand is a variable initialized in searx/__init__.py
:
Line 27 in 71d6697
settings, settings_load_message = searx.settings_loader.load_settings() |
searx/searx/settings_loader.py
Line 8 in 71d6697
import yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I am an idiot .. I totally forgot the main problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm .. after thinking again .. pyyaml should already be installed when the virtualenv is build
and this will be installed before pyenvinstall is called:
In #2517 (comment) I described it:
pyenv: builds the environment for development / typically
requirements.txt
penvinstall: installs the python package in this environment (pip install -e
) / typicallysetup.py
The other point you asked:
each invocation of pyenv will reinstall the virtualenv
Our mistake was to build sha256sum requirements*.txt > $(PY_ENV)/requirements.sha256 ;\
in cmd_pyenvinstall
.. this optimizing should take place in cmd_virtualenv
.
Or I am wrong? .. I will give it a try ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm .. after thinking again .. pyyaml should already be installed when the virtualenv is build
cmd_virtualenv seems to fail sometimes on github action:
- in this case, the ./local contains an initialized virtualenv, but without pyyaml
- cmd_virtualenv won't detect that pyyaml is missing (or other dependencies): the virtualenv exists,
...python
is an executable. - then cmd_pyenvinstall fails because pyyaml is missing.
- the cache is updated with a broken virtualenv.
- all new builds on github action fail.
An alternative implementation (without ...grep pyyaml ./requirements.txt)...
) :
- after
$(PY_ENV_BIN)/python -m pip install $(PIP_VERBOSE) -r requirements.txt;
, a file is created (or just a copy of requirements.txt) if [ -d "./$(PY_ENV)" -a -x "./$(PY_ENV_BIN)/python" ]; then
also check if this file exists.- basically it duplicates
if ! cat $(PY_ENV)/requirements.sha256 2>/dev/null | sha256sum --check --status 2>/dev/null; then
in cmd_virtualenv.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I work on a solution .. give me some time this day and I will show you my solution:
An alternative implementation
...
..
All this goes in the right direction to hardening, but instead hardening the installation, we have to hardening the venv build .. I will consider it in my solution / thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aka: ensure that 'make test' works as expected The cache contains a copy './local' which is - under some circumstance - corrupted. It is not possible to clear the cache [1] (see the top of the page). Ensure that 'make test' works as expected [2] even if - the python interpreter is missing - the virtualenv exists but pyyaml is missing To hardening when the workflow cache fails, this patch adds the new target 'travis.test' into the workflow. This target probes to import a python module 'yaml'. If this fails the virtualenv will be completely new build. [1] actions/cache#2 (comment) [2] searx#2517 (comment) Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
"make pyenv" ensures that ./local/py3/bin/python is an executable
Target pip-exe is a prerequisite of the targets: - pyinstall - pyuninstall and was accidentally deleted in commit 9b48ae4. HINT: do not confuse pyinstall with penvinstall pyinstall & pyuninstall Installing into user's HOME using pip from OS, therefore the message is needed. pyenvinstall & pyenvuninstall Installing into virtualenv (./local) using pip which is provided by prerequisite 'pyenv' in the virtualenv. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
aka: ensure that 'make test' works as expected The cache contains a copy './local' which is - under some circumstance - corrupted. It is not possible to clear the cache [1] (see the top of the page). Ensure that 'make test' works as expected [2] even if - the python interpreter is missing - the virtualenv exists but pyyaml is missing To hardening when the workflow cache fails, this patch adds the new target 'travis.test' into the workflow. This target probes to import a python module 'yaml'. If this fails the virtualenv will be completely new build. [1] actions/cache#2 (comment) [2] searx#2517 (comment) Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
aka: ensure that 'make test' works as expected The cache contains a copy './local' which is - under some circumstance - corrupted. It is not possible to clear the cache [1] (see the top of the page). Ensure that 'make test' works as expected [2] even if - the python interpreter is missing - the virtualenv exists but pyyaml is missing To hardening when the workflow cache fails, this patch adds the new target 'travis.test' into the workflow. This target probes to import a python module 'yaml'. If this fails the virtualenv will be completely new build. [1] actions/cache#2 (comment) [2] searx#2517 (comment) Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
What does this PR do?
Change about utils/makefile.python:
make pyenv
makes sure that there is a python executable in the virtualenv, if not the virtualenv is installed again.make pyenvinstall
makes to installpyyaml
before running setup.py (setup.py requires pyyml to read searx/settings.yml)Why is this change important?
searx/.github/workflows/integration.yml
Lines 25 to 32 in 71d6697
make test
works as expected even ifHow to test this PR locally?
Author's checklist
Related issues