Skip to content
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

make clean removes venv directory in source path unconditionally #159

Open
stweil opened this issue Aug 20, 2020 · 8 comments
Open

make clean removes venv directory in source path unconditionally #159

stweil opened this issue Aug 20, 2020 · 8 comments

Comments

@stweil
Copy link
Collaborator

stweil commented Aug 20, 2020

Ideally it would only remove files created by the build process.

If the user has created the venv directory manually and added own content, removing that directory might be bad.

Makefile could check whether that virtual environment was active outside of make and skip the removal then.

@kba
Copy link
Member

kba commented Aug 21, 2020

Makefile could check whether that virtual environment was active outside of make and skip the removal then.

Sounds reasonable 👍 @bertsky any consequences we're not seeing?

@bertsky
Copy link
Collaborator

bertsky commented Aug 21, 2020

make clean removes venv directory in source path unconditionally
Ideally it would only remove files created by the build process.

If the user has created the venv directory manually and added own content, removing that directory might be bad.

In the current rule definition, clean only cleanes the path ocrd_all uses by default to create a new venv of its own. It does not use VIRTUAL_ENV from the environment (which might be user-defined).

If both coincide, then it is removed. So you want to back out of that decision?

Makefile could check whether that virtual environment was active outside of make and skip the removal then.

What do you propose? Replace the VIRTUAL_ENV ?= with some form of ifdef?

@stweil
Copy link
Collaborator Author

stweil commented Aug 21, 2020

What do you propose?

--- a/Makefile
+++ b/Makefile
@@ -69,7 +69,7 @@ check:
 
 clean: # add more prerequisites for clean below
        $(RM) -r $(SUB_VENV)/*
-       $(RM) -r $(CURDIR)/venv # deliberately not using VIRTUAL_ENV here
+       if ! command -v activate; then $(RM) -r $(VIRTUAL_ENV; fi
        $(RM) -r $(HOME)/.parallel/semaphores/id-ocrd_all_git/
 
 define HELP

Maybe a comment can also be added: "Remove virtual environment only if it was not active outside of the make context.".

@kba
Copy link
Member

kba commented Aug 21, 2020

  •   if ! command -v activate; then $(RM) -r $(VIRTUAL_ENV; fi
    

I don't think activate will be detected as a command because while in $PATH if $VIRTUAL_ENV is activated it is not executable.

Wrong, it does work, should have checked.

@stweil
Copy link
Collaborator Author

stweil commented Aug 21, 2020

Improved version:

diff --git a/Makefile b/Makefile
index d10e36a..cd7751c 100644
--- a/Makefile
+++ b/Makefile
@@ -69,7 +69,8 @@ check:
 
 clean: # add more prerequisites for clean below
        $(RM) -r $(SUB_VENV)/*
-       $(RM) -r $(CURDIR)/venv # deliberately not using VIRTUAL_ENV here
+       # Remove virtual environment only if it was not active outside of the make context.
+       command -v activate >/dev/null || $(RM) -r $(VIRTUAL_ENV)
        $(RM) -r $(HOME)/.parallel/semaphores/id-ocrd_all_git/
 
 define HELP

@stweil
Copy link
Collaborator Author

stweil commented Aug 21, 2020

Wrong, it does work, should have checked.

I was also surprised about that.

@bertsky
Copy link
Collaborator

bertsky commented Aug 21, 2020

-       $(RM) -r $(CURDIR)/venv # deliberately not using VIRTUAL_ENV here
+       # Remove virtual environment only if it was not active outside of the make context.
+       command -v activate >/dev/null || $(RM) -r $(VIRTUAL_ENV)

That's not correct. This would even snatch away an externally controlled venv passed in via VIRTUAL_ENV (either from shell variable or by make argument or in local.mk). You should at least use $(CURDIR)/venv. But a better criterion than activate (which could be anything) is the ifdef approach suggested above.

@stweil
Copy link
Collaborator Author

stweil commented Aug 21, 2020

Well, it does not snatch if the external VIRTUAL_ENV was active when make clean was called.

But I agree that using macros which come from outside with $(RM) -r can be dangerous, so feel free to use $(CURDIR)/venv to avoid trouble coming from someone running make clean VIRTUAL_ENV=/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants