Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions docs/changelog/2003.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Optionally skip generation of ``.gitignore`` with * directive in virtualenv
directory, using command line option :option:`no-gitignore`.
Default behavior is to generate the file as before.
Comment thread
compwiztobe marked this conversation as resolved.
Outdated
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-gitignore` command line 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.gitignore = options.gitignore
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),
("gitignore", self.gitignore),
]

@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-gitignore",
dest="gitignore",
action="store_false",
help="skip creation of coverall .gitignore in destination directory",
default=True,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does this break convention and more importantly the CLI option-environment variable interop, by renaming the argument? I wasn't aware of the config-file/env-var pathway to set these, and now it's not clear to me if those will expect a value at no_vcs_ignore/VIRTUALENV_NO_VCS_IGNORE or vcs_ignore/VIRTUALENV_VCS_IGNORE or some combo.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So if you put:

[virtualenv]
no_vcs_ignore = false

in your users virtualenv.ini file you enabled this flag always on your machine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Perfect

)

@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()
Comment thread
compwiztobe marked this conversation as resolved.
if self.gitignore:
self.setup_ignore_vcs()

def set_pyenv_cfg(self):
self.pyenv_cfg.content = OrderedDict()
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/create/test_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,19 @@ def test_create_gitignore_exists(tmp_path):
assert git_ignore.read_text() == "magic"


def test_create_gitignore_override(tmp_path):
git_ignore = tmp_path / ".gitignore"
cli_run([str(tmp_path), "--without-pip", "--no-gitignore", "--activators", ""])
assert not git_ignore.exists()


def test_create_gitignore_exists_override(tmp_path):
git_ignore = tmp_path / ".gitignore"
git_ignore.write_text("magic")
cli_run([str(tmp_path), "--without-pip", "--no-gitignore", "--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