diff --git a/docs/changelog/2003.feature.rst b/docs/changelog/2003.feature.rst new file mode 100644 index 000000000..76fc3bbaa --- /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 ad826550e..05bb60399 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 45075dae9..1b4ea69f6 100644 --- a/src/virtualenv/create/creator.py +++ b/src/virtualenv/create/creator.py @@ -44,6 +44,7 @@ def __init__(self, options, interpreter): 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 @@ def _args(self): return [ ("dest", ensure_text(str(self.dest))), ("clear", self.clear), + ("no_vcs_ignore", self.no_vcs_ignore), ] @classmethod @@ -90,6 +92,13 @@ def add_parser_arguments(cls, parser, interpreter, meta, app_data): 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 @@ def run(self): 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 747d7935b..7184517f4 100644 --- a/tests/unit/create/test_creator.py +++ b/tests/unit/create/test_creator.py @@ -242,13 +242,26 @@ def list_to_str(iterable): 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"):