Skip to content

Commit 62bfaf8

Browse files
committed
add VIRTUALENVWRAPPER_PROJECT_FILENAME; resolves issue 120
1 parent 6495c52 commit 62bfaf8

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

docs/en/history.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ dev
1313
- Shortcut initialization if it has run before.
1414
- Set hook log file permissions to be group-writable. (:bbissue:`62`
1515
reported by :bbuser:`hedgeddown`)
16+
- Add ``VIRTUALENVWRAPPER_PROJECT_FILENAME`` variable so the
17+
``.project`` file used to link a virtualenv to a project can be
18+
renamed to avoid conflicts with other tools. (:bbissue:`120`
19+
reported by :bbuser:`arthuralvim`)
1620

1721
2.10.1
1822

docs/en/install.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,19 @@ The variable ``PROJECT_HOME`` tells virtualenvwrapper where to place
154154
your project working directories. The variable must be set and the
155155
directory created before :ref:`command-mkproject` is used.
156156

157+
.. seealso::
158+
159+
* :ref:`project-management`
160+
161+
.. _variable-VIRTUALENVWRAPPER_PROJECT_FILENAME:
162+
163+
Project Linkage Filename
164+
------------------------
165+
166+
The variable ``VIRTUALENVWRAPPER_PROJECT_FILENAME`` tells
167+
virtualenvwrapper how to name the file linking a virtualenv to a
168+
project working directory. The default is ``.project``.
169+
157170
.. seealso::
158171

159172
* :ref:`project-management`

docs/en/projects.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ site, combine the :ref:`templates-bitbucket` and
3434
.. seealso::
3535

3636
* :ref:`extensions-templates`
37+
* :ref:`variable-PROJECT_HOME`
38+
* :ref:`variable-VIRTUALENVWRAPPER_PROJECT_FILENAME`

tests/test_project_mk.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,12 @@ test_same_workon_and_project_home () {
8181
PROJECT_HOME="$old_project_home"
8282
}
8383

84+
test_alternate_linkage_filename () {
85+
export VIRTUALENVWRAPPER_PROJECT_FILENAME=".not-project"
86+
mkproject myproject6 >/dev/null 2>&1
87+
assertSame "myproject6" $(basename "$VIRTUAL_ENV")
88+
assertSame "$PROJECT_HOME/myproject6" "$(cat $VIRTUAL_ENV/.not-project)"
89+
export VIRTUALENVWRAPPER_PROJECT_FILENAME=".project"
90+
}
91+
8492
. "$test_dir/shunit2"

virtualenvwrapper.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ then
6565
VIRTUALENVWRAPPER_ENV_BIN_DIR="Scripts"
6666
fi
6767

68+
# Let the user override the name of the file that holds the project
69+
# directory name.
70+
if [ "$VIRTUALENVWRAPPER_PROJECT_FILENAME" = "" ]
71+
then
72+
export VIRTUALENVWRAPPER_PROJECT_FILENAME=".project"
73+
fi
74+
6875
function virtualenvwrapper_derive_workon_home {
6976
typeset workon_home_dir="$WORKON_HOME"
7077

@@ -806,7 +813,7 @@ function setvirtualenvproject {
806813
prj="$(pwd)"
807814
fi
808815
echo "Setting project for $(basename $venv) to $prj"
809-
echo "$prj" > "$venv/.project"
816+
echo "$prj" > "$venv/$VIRTUALENVWRAPPER_PROJECT_FILENAME"
810817
}
811818

812819
# Show help for mkproject
@@ -911,9 +918,9 @@ function mkproject {
911918
function cdproject {
912919
virtualenvwrapper_verify_workon_home || return 1
913920
virtualenvwrapper_verify_active_environment || return 1
914-
if [ -f "$VIRTUAL_ENV/.project" ]
921+
if [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" ]
915922
then
916-
project_dir=$(cat "$VIRTUAL_ENV/.project")
923+
project_dir=$(cat "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME")
917924
if [ ! -z "$project_dir" ]
918925
then
919926
cd "$project_dir"
@@ -922,7 +929,7 @@ function cdproject {
922929
return 1
923930
fi
924931
else
925-
echo "No project set in $VIRTUAL_ENV/.project" 1>&2
932+
echo "No project set in $VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" 1>&2
926933
return 1
927934
fi
928935
return 0

virtualenvwrapper/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ def post_activate_source(args):
5656
#
5757
# Change to the project directory
5858
#
59-
[ -f "$VIRTUAL_ENV/.project" ] && cd "$(cat \"$VIRTUAL_ENV/.project\")"
59+
[ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" ] && cd "$(cat \"$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME\")"
6060
"""

0 commit comments

Comments
 (0)