-
-
Notifications
You must be signed in to change notification settings - Fork 848
Only print make venv
message when needed.
#867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The message can be useful as a prompt when the $ make check
venv already exists.
To recreate it, remove it first with `make clean-venv'.
# Ignore the tools and venv dirs and check that the default role is not used.
./venv/bin/sphinx-lint -i tools -i ./venv --enable default-role
No problems found.
my-new-tool
make: my-new-tool: No such file or directory
make: *** [check] Error 1 |
Always printing that message is confusing since it says that the "venv already exists." (stating a fact) and suggests instructions to recreate it (just a tip), and this can easily be misinterpreted as a problem that must be addressed by running the suggested command. The fact that it's printed for all the commands, with no apparent connection to the venv, makes it even more confusing. Adding new tools is a corner case that doesn't happen often. In that case the author can probably figure out that the venv needs to be updated/recreated, and |
How about keeping ensure-venv:
@if [ ! -d $(VENVDIR) ] ; then \
$(PYTHON) -m venv $(VENVDIR); \
$(VENVDIR)/bin/python3 -m pip install --upgrade pip; \
$(VENVDIR)/bin/python3 -m pip install -r requirements.txt; \
echo "The venv has been created in the $(VENVDIR) directory"; \
fi And have venv:
@if [ -d $(VENVDIR) ] ; then \
echo "venv already exists."; \
echo "To recreate it, remove it first with \`make clean-venv'."; \
else \
$(MAKE) ensure-venv; \
fi |
Is using I tried to call |
Yes:
https://www.gnu.org/software/make/manual/make.html#MAKE-Variable We use it at https://github.com/python-pillow/Pillow/blob/main/Makefile and it's widely used in https://github.com/python/cpython/blob/main/Makefile.pre.in and https://github.com/python/cpython/blob/main/Doc/Makefile. Actually, I don't get any |
Weird, with the code from the first message (with Not sure why it works like this, but it seems to work. I'll run a few more tests locally and then update the PR. |
The |
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.
Thank you!
We could do something similar in https://github.com/python/cpython/blob/main/Doc/Makefile
* Only print `make venv` message when needed. * Remove duplicated code.
When
make venv
is calledmake clean-venv
This was added in #856, but because of this change, all other targets that have the
venv
target as a dependency now print the message saying that the venv exist.If
venv
is removed from the. PHONY
list it doesn't get reevaluated and doesn't print the message, but this also applies when it's invoked directly, making the message that suggestsmake clean-venv
useless since it's never printed.I wrestled with
Makefile
for a while, and this PR is the best I came up with. It's intelligible, but has some repetition. I tried to get rid of the repetition by creating a Makefile function:but I couldn't find a way to call it from the other target, since they use a bash
if
/else
that can't be used to call makefile functions.Another option is to create a target instead of the function, and call it with
make target
:this works, but it launches another instance of
make
and prints some extra messages likemake[1]: Entering/Leaving directory '/home/user/devguide'
-- not very elegant.There are other solutions that I explored, including conditional functions or conditional syntax. There are also other ways of detecting dirs and acting upon their presence/absence, but the intelligibility of all these solutions goes downhill pretty quickly.
So the options are:
create-venv
target with nestedmake
callsif
/else
from thevenv
target, documentmake clean-venv
, and hope people figure it out by reading the help