Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a .gitignore in work_dir and info file directories #3145

Closed

Conversation

kurtmckee
Copy link
Contributor

@kurtmckee kurtmckee commented Oct 30, 2023

NOTE:

Tests, and possibly documentation, are still needed for this work. Please confirm the implementation is acceptable (for example, perhaps a helper function is desirable).

This PR introduces blanket .gitignore files that are created in the following locations:

  • In the work_dir (such as .tox/)
  • Wherever an info JSON file is written

This addresses several issues I found when running tox under the following circumstances:

# Create a completely empty directory, then initialize git.
mkdir test-tox
cd test-tox
git init

# Run `tox` with an environment for an interpreter that IS NOT installed.
# RESULT: `.tox/py40/.tox-info.json` visible to git
tox -e py40

# Run `tox devenv` with an environment for an interpreter that IS NOT installed.
# RESULT: `venv/.tox-info.json` visible to git
tox devenv -e py40

# Run `tox devenv` with an environment for an interpreter that IS installed.
# RESULT: `.tox/py/log/1-install_package.log` is visible to git
tox devenv -e py

The changes introduced in this PR address the visibility of these files in git.

Closes #2530

  • ran the linter to address style issues (tox -e fix)
  • wrote descriptive pull request text

Still to do:

  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

Copy link
Member

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

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

Test, changelog, etc.

Comment on lines +416 to +418
if not self._state.conf.core["work_dir"].exists():
self._state.conf.core["work_dir"].mkdir()
(self._state.conf.core["work_dir"] / ".gitignore").write_text("*", encoding="utf-8")
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In what way? The conditional? The .mkdir() lacking arguments? The parenthetical grouping and then calling .write_text()? I'm very open to additional guidance here! 👍

It appeared to resolve issues locally, but perhaps I made a change after initial testing...

Copy link
Member

@gaborbernat gaborbernat Oct 30, 2023

Choose a reason for hiding this comment

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

I meant this entire 3 lines should not be here. This is a selection module, not business logic. Why did you duplicate logic here and src/tox/tox_env/info.py?

Copy link
Contributor Author

@kurtmckee kurtmckee Oct 30, 2023

Choose a reason for hiding this comment

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

Ah, I see.

I put the code here because the very next line contains a call to self._env_name_to_active(), which ends up creating the work_dir if it doesn't already exist. I considered putting the code in execute(), but that function wasn't consistently called in the tox subcommands I tested (or, at least, it wasn't consistently called depending on whether a requested interpreter could be found). ensure_only_run_env_is_active() was called consistently for the tox subcommands I tested.

The code is duplicated because info.py creates a directory and a file that isn't necessarily in the work_dir (see the .tox/ vs venv/ files listed in the text I posted above). Duplicating the code ensured that a .gitignore file existed when the info file wasn't put in a subdirectory of work_dir.

Comment on lines +66 to +67
if not (self._path.parent / ".gitignore").exists():
(self._path.parent / ".gitignore").write_text("*", encoding="utf-8")
Copy link
Member

Choose a reason for hiding this comment

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

This looks ok-ish 🤔

@gaborbernat gaborbernat marked this pull request as draft October 30, 2023 15:29
@gaborbernat
Copy link
Member

Stalled.

@kurtmckee
Copy link
Contributor Author

Oh! I thought I was waiting on additional feedback.

@kurtmckee kurtmckee deleted the create-gitignore-issue-2530 branch November 28, 2023 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatic .gitignore
2 participants