summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAren Siekmeier <aren.siekmeier@ipricegroup.com>2020-11-02 20:32:46 +0900
committerGitHub <noreply@github.com>2020-11-02 11:32:46 +0000
commit9708b54f0f1fe4aad145c12842fae241707d696c (patch)
treedb72031e6e8987ed9ff9fdabb6c9325f8fd579af
parent3ae716faf3969a357b1e2be21adaa1cbd3c533e6 (diff)
downloadvirtualenv-9708b54f0f1fe4aad145c12842fae241707d696c.tar.gz
Optionally skip creation of .gitignore in virtualenv directory (#2004)
-rw-r--r--docs/changelog/2003.feature.rst1
-rw-r--r--docs/user_guide.rst4
-rw-r--r--src/virtualenv/create/creator.py12
-rw-r--r--tests/unit/create/test_creator.py15
4 files changed, 29 insertions, 3 deletions
diff --git a/docs/changelog/2003.feature.rst b/docs/changelog/2003.feature.rst
new file mode 100644
index 0000000..76fc3bb
--- /dev/null
+++ b/docs/changelog/2003.feature.rst
@@ -0,0 +1 @@
+Optionally skip VCS ignore directive for entire virtualenv directory, using option :option:`no-vcs-ignore`, by default ``False``.
diff --git a/docs/user_guide.rst b/docs/user_guide.rst
index ad82655..05bb603 100644
--- a/docs/user_guide.rst
+++ b/docs/user_guide.rst
@@ -27,7 +27,9 @@ The tool works in two phases:
- install activation scripts into the binary directory of the virtual environment (these will allow end user to
*activate* the virtual environment from various shells).
- create files that mark the virtual environment as to be ignored by version control systems (currently we support
- Git only, as Mercurial, Bazaar or SVN does not support ignore files in subdirectories).
+ Git only, as Mercurial, Bazaar or SVN do not support ignore files in subdirectories). This step can be skipped
+ with the :option:`no-vcs-ignore` option.
+
The python in your new virtualenv is effectively isolated from the python that was used to create it.
diff --git a/src/virtualenv/create/creator.py b/src/virtualenv/create/creator.py
index 45075da..1b4ea69 100644
--- a/src/virtualenv/create/creator.py
+++ b/src/virtualenv/create/creator.py
@@ -44,6 +44,7 @@ class Creator(object):
self._debug = None
self.dest = Path(options.dest)
self.clear = options.clear
+ self.no_vcs_ignore = options.no_vcs_ignore
self.pyenv_cfg = PyEnvCfg.from_folder(self.dest)
self.app_data = options.app_data
@@ -57,6 +58,7 @@ class Creator(object):
return [
("dest", ensure_text(str(self.dest))),
("clear", self.clear),
+ ("no_vcs_ignore", self.no_vcs_ignore),
]
@classmethod
@@ -90,6 +92,13 @@ class Creator(object):
help="remove the destination directory if exist before starting (will overwrite files otherwise)",
default=False,
)
+ parser.add_argument(
+ "--no-vcs-ignore",
+ dest="no_vcs_ignore",
+ action="store_true",
+ help="don't create VCS ignore directive in the destination directory",
+ default=False,
+ )
@abstractmethod
def create(self):
@@ -160,7 +169,8 @@ class Creator(object):
safe_delete(self.dest)
self.create()
self.set_pyenv_cfg()
- self.setup_ignore_vcs()
+ if not self.no_vcs_ignore:
+ self.setup_ignore_vcs()
def set_pyenv_cfg(self):
self.pyenv_cfg.content = OrderedDict()
diff --git a/tests/unit/create/test_creator.py b/tests/unit/create/test_creator.py
index 747d793..7184517 100644
--- a/tests/unit/create/test_creator.py
+++ b/tests/unit/create/test_creator.py
@@ -242,13 +242,26 @@ def test_create_no_seed(python, creator, isolated, system, coverage_env, special
assert git_ignore.splitlines() == ["# created by virtualenv automatically", "*"]
-def test_create_gitignore_exists(tmp_path):
+def test_create_vcs_ignore_exists(tmp_path):
git_ignore = tmp_path / ".gitignore"
git_ignore.write_text("magic")
cli_run([str(tmp_path), "--without-pip", "--activators", ""])
assert git_ignore.read_text() == "magic"
+def test_create_vcs_ignore_override(tmp_path):
+ git_ignore = tmp_path / ".gitignore"
+ cli_run([str(tmp_path), "--without-pip", "--no-vcs-ignore", "--activators", ""])
+ assert not git_ignore.exists()
+
+
+def test_create_vcs_ignore_exists_override(tmp_path):
+ git_ignore = tmp_path / ".gitignore"
+ git_ignore.write_text("magic")
+ cli_run([str(tmp_path), "--without-pip", "--no-vcs-ignore", "--activators", ""])
+ assert git_ignore.read_text() == "magic"
+
+
@pytest.mark.skipif(not CURRENT.has_venv, reason="requires interpreter with venv")
def test_venv_fails_not_inline(tmp_path, capsys, mocker):
if hasattr(os, "geteuid"):