Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/2003.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Optionally skip VCS ignore directive for entire virtualenv directory, using option :option:`no-vcs-ignore`, by default ``False``.
4 changes: 3 additions & 1 deletion docs/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
12 changes: 11 additions & 1 deletion src/virtualenv/create/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VIRTUALENV_NO_VCS_IGNORE and no_vcs_ignore will be the names as documented under https://virtualenv.pypa.io/en/latest/cli_interface.html#environment-variables. The destination variable doesn't matter only the CLI flag.

dest="no_vcs_ignore",
action="store_true",
help="don't create VCS ignore directive in the destination directory",
default=False,
)

@abstractmethod
def create(self):
Expand Down Expand Up @@ -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()
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/create/test_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down