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

[docs] Mention exclude_dirs option available in TOML and YAML #876

Merged
merged 2 commits into from
Aug 11, 2022
Merged

[docs] Mention exclude_dirs option available in TOML and YAML #876

merged 2 commits into from
Aug 11, 2022

Conversation

bittner
Copy link
Contributor

@bittner bittner commented Apr 3, 2022

As discovered in #488 (latest comments) and reported in #528.

Also attempts to improve the documentation code by aligning code block indenting replacing simple code blocks (::) with source code markup code blocks in reStructuredText.

Side Notes

  • Despite the name, exclude_dirs also recognizes single files, not only directories.
  • In the long run it may make sense to consolidate the two options exclude and exclude_dirs.

@bittner
Copy link
Contributor Author

bittner commented Apr 5, 2022

Can we merge these changes, so developers can have it easier finding information about how to configure Bandit?

@TreeKat71
Copy link

TreeKat71 commented Apr 8, 2022

This is what I am looking for and it is the missing part in the document.
exclude is not working in the pyproject.toml
I think it does help developer can find information easier.

@bittner
Copy link
Contributor Author

bittner commented Apr 11, 2022

Please, review and merge!

@bittner
Copy link
Contributor Author

bittner commented Apr 25, 2022

Rebased the PR to resolve conflicts after #868 was merged, yesterday.

@ericwb Can you review and merge this PR, please?

@bittner
Copy link
Contributor Author

bittner commented Aug 3, 2022

@gdalmau Thanks for your approval! I rebased the PR and resolved the conflict that had been introduced since I opened it. Can you approve again, please? And maybe merge?

@gdalmau
Copy link

gdalmau commented Aug 3, 2022

@bittner Sorry I'm not a member of PyCQA nor bandit. I just checked the changes and they looked good to me so I approved if that means anything to the members of this project :)

I will recheck the changes and approve (or not) so hopefully we can see this PR merged.

Comment on lines +28 to +32
If you want to include TOML support, install it with the `toml` extras:

.. code-block:: console

pip install bandit[toml]
Copy link

Choose a reason for hiding this comment

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

I just noticed that tomli is required if you use a pyproject.toml. In my case our CI didn't break because it was installed via other packages, but a bare install makes it indeed not work.

Since the setup.cfg file seems to also have an extra for yaml files:

bandit/setup.cfg

Lines 30 to 34 in caae4ee

[extras]
yaml =
PyYAML
toml =
tomli>=1.1.0; python_version < "3.11"

Should we mention it as well in here? Or does a .bandit YAML file work with just installing pip install bandit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I'm confused. 🤔 Installing the toml extra, that's what the pip install bandit[toml] does. Anything else needed from your point of view in addition to those instructions?

Copy link

Choose a reason for hiding this comment

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

What I mean is that in order to make bandit process a pyproject.toml file it needs to be installed via pip install bandit[toml]. Does it need to be installed via pip install bandit[yaml] for yaml files? If so, it should probably be in this docs as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand! So, "If you want to include TOML support" is not clear enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Argh, YAML! Now I understand. Let me verify this locally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can confirm, the latest version of PyYAML (not the one in requirements.txt) is installed as a dependency when you install Bandit via pip install bandit.

I'm a bit puzzled: I absolutely can't see in the source code where the dependencies being installed are defined.

@bittner
Copy link
Contributor Author

bittner commented Aug 3, 2022

@ericwb @lukehinds @sigmavirus24 Could you approve and merge, please?

Copy link
Member

@sigmavirus24 sigmavirus24 left a comment

Choose a reason for hiding this comment

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

@bittner there's way more here than just mentioning that option. You've reformatted large swaths of text and many of these things we simply won't accept in what should be a relatively small patch.

Case-in-point: pre-commit formats the hooks in exactly the way we have them formatted. If you look at it's documentation, all hooks are written exactly as we wrote ours.

@bittner
Copy link
Contributor Author

bittner commented Aug 3, 2022

You've reformatted large swaths of text and many of these things we simply won't accept in what should be a relatively small patch.

Please note that the PR has 2 separate commits, dedicated to changes with their own scope.

With respect to the formatting, I attempt to modernize the reStructuredText syntax, with a uniform use of .. code-block:: and non-inlined hyperlinks. Isn't this fair to be included in what is a change to the documentation?

Case-in-point: pre-commit formats the hooks in exactly the way we have them formatted. If you look at it's documentation, all hooks are written exactly as we wrote ours.

Fair point. I didn't know. I'd have to adapt the pre-commit hook configuration with those changes, fair enough. That would certainly warrant a dedicated PR,—Let me revert those changes. I apologize.

@bittner
Copy link
Contributor Author

bittner commented Aug 7, 2022

I reverted the changes to the displayed source code that apparently gets reformatted by the pre-commit hook, when installed.

The PR description now mentions the reformatting of the documentation code (which affects the code portions modified in this PR and is hence difficult to contribute independently in parallel). I hope you see the value in the change. If there's anything you want adapted in addition, please let me know.

@ericwb @lukehinds @sigmavirus24 Could you approve and merge now, please?

doc/source/config.rst Outdated Show resolved Hide resolved
@bittner bittner requested review from sigmavirus24 and ericwb and removed request for ghugo August 9, 2022 13:50
@sigmavirus24
Copy link
Member

With respect to the formatting, I attempt to modernize the reStructuredText syntax, with a uniform use of .. code-block:: and non-inlined hyperlinks. Isn't this fair to be included in what is a change to the documentation

The project has a history of separating these out. A switch to code-blocks should be a fast merge but there are also formatting changes to the docs last I checked with line wrapping, etc.

Non-inlined URLs are my preference and again standardizing s hour be easy to review. Finally, this change which is important should have been easy to merge but was allowed down by the additional noise making it harder to review with confidence something else wasn't missed. It's a matter of opinion but every comment you've left recently had been instructing people to merge it. That might have happened years ago if there had been less noise making the important change (documenting this option) easier to see and comment on with the shit tools available to the maintainers (because separate commits do not in fact improve the review experience on GitHub)

Make configuration examples easier to understand and use

Explain how to install TOML support

As discovered in #488 and reported in #528.
@bittner
Copy link
Contributor Author

bittner commented Aug 11, 2022

Ian, thanks for taking the time to comment. I think the situation has now improved.

  • The line wrapping has been undone
  • Hyperlinks are non-inline, following your preference
  • Code blocks provide syntax highlighting, which improves the reading experience with different file types (INI, YAML, TOML)

The documentation benefits from a nicer reading experience, and the documentation code has been modernized with related changes. While I second your concerns of the review experience, the benefits hopefully speak in favor of this larger-than-bare-minimum PR.

@sigmavirus24 sigmavirus24 enabled auto-merge (squash) August 11, 2022 16:13
@sigmavirus24 sigmavirus24 merged commit ebd168a into PyCQA:main Aug 11, 2022
@bittner bittner deleted the docs/explain-exclude-dirs-option branch August 11, 2022 17:33
@bittner
Copy link
Contributor Author

bittner commented Aug 11, 2022

Thanks for merging! 👍

kevinoid added a commit to kevinoid/python-project-template that referenced this pull request Mar 17, 2023
Move the list of excluded files from --exclude in tox.ini to
exclude_dirs in pyproject.toml to centralize configuration in
pyproject.toml and make it accessible to tools and bandit invocations
outside of tox.

- Remove the comment that exclude is ignored by bandit 1.6.3+, which was
  fixed by PyCQA/bandit#722 in bandit 1.7.1.
- Change exclude (which only works for INI files) to exclude_dirs (which
  only works for TOML and YAML files), as described in
  PyCQA/bandit#876
- Add /.git/ and /__pycache__/ to exclude_dirs to match --exclude.
- Remove --exclude from invocation in tox.ini

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
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.

5 participants