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

Python: Add tox commands for code format and type checking #3282 #3423

Merged
merged 1 commit into from
Nov 2, 2021

Conversation

cabhishek
Copy link
Contributor

@cabhishek cabhishek commented Oct 29, 2021

  • This PR adds tox commands to automate code formatting and type checking.
  • tox uses following
  • black for code formatting
  • isort for import ordering
  • autoflake for removing unused imports
  • mypy for static type checking
  • Core tox commands
  • tox will run tests and linters (code format and type checks). This is the central command that'll be most used.
  • tox -e linters will check if the code adheres to the standard and passes type checking
  • tox -e format automates code reformatting
  • Future enhancements
  • Add tox commands for documentation creation
  • Perhaps add git pre-recommit hooks to make it more seamless?
  • We'll need a follow PR to run these commands over the codebase.

@cabhishek
Copy link
Contributor Author

cabhishek commented Oct 29, 2021

One open question: Should we pin black and isort to a version to ensure we don't constantly introduce newer formatting rule changes that are unrelated to PRs? We could periodically upgrade versions and open PR specific to formatting changes. This will ensure we don't mix logic change vs pure formatting.

@samredai
Copy link
Collaborator

@cabhishek I think pinning makes sense!

Copy link
Collaborator

@jun-he jun-he left a comment

Choose a reason for hiding this comment

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

Yep, I think we should have a requirements file for pinning.

python/setup.cfg Outdated
@@ -33,6 +33,7 @@ license_files =
classifiers =
License :: OSI Approved :: Apache Software License
Operating System :: OS Independent
Programming Language :: Python :: 3.6
Copy link
Collaborator

Choose a reason for hiding this comment

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

QQ, wondering if we should support 3.6? Per recent sync meeting, the plan is to support just py37,py38,py39 or higher versions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would vote that we don't support 3.6 unless someone really feels we should. Looking at endoflife.date/python shows that python 3.6 security support ends in a little over a month.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we discussed this in one of the python syncs and we agreed that supporting 3.6 was a bad idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted changes and dropped 3.6 support.

Copy link
Collaborator

@samredai samredai left a comment

Choose a reason for hiding this comment

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

One small nit comment that I don't think needs to block merging this PR. LGTM! Thanks @cabhishek

python/tox.ini Outdated
commands =
bandit --ini tox.ini -r src
mypy src
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Should we add --no-implicit-optional here? This will require the explicit x: Optional[int] = None and will fail on x: int = None. The latter always reads odd to me, "must be an int, but by default it's None". The Optional type hint feels clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the flag. And given how common it is to have code like x: int = None I guess the future version of mypy will make that flag the default.

@rdblue rdblue merged commit 4464c78 into apache:master Nov 2, 2021
@rdblue
Copy link
Contributor

rdblue commented Nov 2, 2021

Thanks, @cabhishek!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants