Closed thehug0naut closed 7 years ago
Added the changes you asked for.
My mkproject code has had a serious update to bring the coding style in line with the mkvirtualenv code. As far as I can tell my code doesn't care about spaces in paths, so if the updated mkvirtualenv code works with spaces it should all run smoothly.
Spaces are horrible little creatures :-)
Take this simple piece of code (inspired by line 13):
set "PROJECT_HOME=%CD%"
set "PROJ_DIR=%PROJECT_HOME%\%1"
set PROJ
i.e. set project home to current dir, set proj dir with the argument being passed in, and finally print all env vars starting with PROJ.
Now, assume the user has spaces in his home dir and runs the above with a simple argument (without spaces):
w:\github\virtualenvwrapper-win\foo bar> projdirtst spaceless
Here's what happens:
w:\github\virtualenvwrapper-win\foo bar> set "PROJECT_HOME=w:\github\virtualenvwrapper-win\foo bar"
w:\github\virtualenvwrapper-win\foo bar> set "PROJ_DIR=w:\github\virtualenvwrapper-win\foo bar\spaceless"
w:\github\virtualenvwrapper-win\foo bar> set PROJ
PROJECT_HOME=w:\github\virtualenvwrapper-win\foo bar
PROJ_DIR=w:\github\virtualenvwrapper-win\foo bar\spaceless
whoops, PROJ_DIR contains a directory string with a space, but without quotes. This isn't bad (in fact it is what you want), but if you try to
mkdir %PROJ_DIR%
this it will try to create two directories (mkdir a b
creates both a
and b
as directories).
If you quote the variable things will work correctly:
mkdir "%PROJ_DIR%"
Unfortunately, if you pass a parameter containing spaces through the above, you end up with:
...> projdirtst "with spaces"
...
...> PROJ_DIR=w:\github\virtualenvwrapper-win\foo bar\"with space"
and if you run mkdir "%PROJ_DIR%"
on that you'll end up with a directory name containing quotes.
The solution here, and in many other cases, is to keep variable contents without quotes, de-quote input parameters, and add quotes when using them, e.g.:
mkdir "%PROJECT_HOME%\%~1"
%PROJECT_HOME%
can have spaces in the above, but as long as it doesn't have quotes everything will be ok.
Here's an instance (my favorite space-in-path issue so far) of why #89 isn't fixed yet..
usagetst.bat:
@echo off
if [%1]==[] (
echo EMPTY
) else (
echo FOUND-ARG
)
Output (the last line is relevant if you e.g. have created a variable that happens to be empty, but you need to quote it before calling another script):
>usagetst
EMPTY
>usagetst arg
FOUND-ARG
>usagetst "arg with spaces"
FOUND-ARG
>usagetst ""
FOUND-ARG
The solution is similar to before:
if "%~1"=="" (...
Previously I had replicated the mkproject functionality from the main virtualenvwrapper repo but the batch script was not being installed by setup.py as I hadn't added it there. This fixes that omission.
Also I've brought the default project directory (PROJECT_HOME) in line with the default WORKON_HOME