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

Install yamllint and the Python libraries used for code linting and formatting for developers #202

Closed
wants to merge 2 commits into from

Conversation

jsf9k
Copy link
Member

@jsf9k jsf9k commented Jun 27, 2024

🗣 Description

This pull request installs yamllint and the Python libraries we use for code linting and formatting.

💭 Motivation and context

We can expect developers to install non-Python tools locally via their system's package manager, but the Python-based tools are a different case. We provide requirements*.txt files to encourage developers to set up a local Python virtual environment (venv), and many editors will make use of that venv when performing syntax checking and the like. It therefore makes sense to go ahead and include in requirements-dev.txt any Python tools that we use for formatting and linting of code.

  • Including yamllint is useful because there are a lot of YML files in an Ansible role. Including yamllint in the virtual environment for developers will allow their editors to syntax-check these files.
  • Including the Python code linting and formatting tools is useful because our Molecule test suites are all written in Python. Including these tools in the virtual environment for developers will allow their editors to automatically lint and format code. It also allows developers to run the tools manually if they wish to do so.

(Note that installing mypy would be even more useful if pytest-testinfra were typed, but that is not yet the case. See pytest-dev/pytest-testinfra#619 for more details about that.)

I noticed that my editor was complaining about trying to use mypy to provide more information but not finding it available, and I verified that installing it in my venv made that complaint go away. That's what started this whole PR effort.

🧪 Testing

All automated tests pass. I noticed that my editor was complaining about trying to use mypy and yamllint to provide more information but not finding them available, and I verified that installing them in my venv made the complaints go away.

✅ Pre-approval checklist

  • This PR has an informative and human-readable title.
  • Changes are limited to a single goal - eschew scope creep!
  • All relevant type-of-change labels have been added.
  • I have read the CONTRIBUTING document.
  • These code changes follow cisagov code standards.
  • All new and existing tests pass.

@jsf9k jsf9k added improvement This issue or pull request will add or improve functionality, maintainability, or ease of use dependencies Pull requests that update a dependency file labels Jun 27, 2024
@jsf9k jsf9k self-assigned this Jun 27, 2024
@jsf9k jsf9k marked this pull request as ready for review June 27, 2024 16:37
@jsf9k jsf9k requested a review from a team June 27, 2024 16:37
Copy link
Member

@dav3r dav3r left a comment

Choose a reason for hiding this comment

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

👍

@jsf9k jsf9k changed the title Install mypy for developers Install mypy and yamllint for developers Jun 27, 2024
@jsf9k jsf9k requested review from dv4harr10 and dav3r June 27, 2024 21:23
Copy link
Member

@dav3r dav3r left a comment

Choose a reason for hiding this comment

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

👍 👍

@jsf9k jsf9k changed the title Install mypy and yamllint for developers Install mypy, yamllint, and black for developers Jun 28, 2024
This is useful because our Molecule test suites are all written in
Python, and we use these tools for Python code formatting.  Including
these tools in the virtual environment for developers will allow their
editors automatically format Python code.  It also allows developers
to run the tools manually if they wish to do so.

This would be even more useful if pytest-testinfra were types, but
that is not yet the case.  See pytest-dev/pytest-testinfra#619 for
more details about that.
This is useful because there are a lot of YML files in an Ansible
role.  Including yamllint in the virtual environment for developers
will allow their editors to syntax-check these files.
@jsf9k jsf9k force-pushed the improvement/install-mypy-for-devs branch from e115ece to 659f26a Compare June 28, 2024 15:47
@jsf9k
Copy link
Member Author

jsf9k commented Jun 28, 2024

Now that I've created this PR, I think that cisagov/skeleton-generic might be a better home for these changes. What do you think @cisagov/vm-dev?

@jsf9k jsf9k changed the title Install mypy, yamllint, and black for developers Install yamllint and the Python libraries used for code linting and formatting for developers Jun 28, 2024
Copy link
Member

@mcdonnnj mcdonnnj left a comment

Choose a reason for hiding this comment

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

I don't really understand the heavy overlap with our pre-commit configuration here. All of these tools (exceptingmypy) can just as effectively be run using pre-commit run --all-files, more specifically pre-commit run <hook name> --all-files, or with pre-commit installed as a git hook it will be run on commit. mypy is a separate case because of how it interacts when living in a Python venv, but everything else would potentially conflict with our pre-commit configuration since there is no version pinning happening here.

@jsf9k
Copy link
Member Author

jsf9k commented Jun 28, 2024

I don't really understand the heavy overlap with our pre-commit configuration here. All of these tools (exceptingmypy) can just as effectively be run using pre-commit run --all-files, more specifically pre-commit run <hook name> --all-files, or with pre-commit installed as a git hook it will be run on commit. mypy is a separate case because of how it interacts when living in a Python venv, but everything else would potentially conflict with our pre-commit configuration since there is no version pinning happening here.

You raise a good point. In the interest of documenting the intent behind this PR, these are the types of problems I was trying to solve:

  1. I'm editing a Python file and my editor wants to provide extra typing information, but it can't because mypy isn't installed in the local venv (which my editor is using).
  2. I'm editing a Python file and my editor wants to provide flake8 warning and error information, but it can't because flake8 isn't installed in the local venv (which my editor is using).
  3. I'm editing a YML file and my editor wants to do some syntax checking with yamllint, but it can't because yamllint isn't installed in the local venv (which my editor is using).
  4. I'm editing a Python file and I know that black will want to make changes. To save time I'd like to go ahead and run black against the file without leaving my editor. I can't do that because black isn't installed in the local venv (which my editor is using).

I will handle these dependencies locally. I thought this addition might be useful for others, but I can see that it would cause headaches.

@jsf9k jsf9k closed this Jun 28, 2024
@jsf9k jsf9k deleted the improvement/install-mypy-for-devs branch June 28, 2024 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file improvement This issue or pull request will add or improve functionality, maintainability, or ease of use
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants