Skip to content

[Lint] Add Lint and move metadata from setup.py to pyproject.toml #120

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

Merged
merged 35 commits into from
Sep 23, 2022
Merged

[Lint] Add Lint and move metadata from setup.py to pyproject.toml #120

merged 35 commits into from
Sep 23, 2022

Conversation

titaiwangms
Copy link
Contributor

@titaiwangms titaiwangms commented Sep 16, 2022

This PR basically migrates the lint and CI from ONNX to here.

  1. Add lint: black, isort, mypy, and flake8

    • flake8 remains basic setting as main branch.
    • auto-formatter will be introduced in the next PR ([Lint] Apply lint #126 )
  2. Add pyproject.toml (includes what was in requirements.txt, setup.cfg, and metadata in setup.py)

    • Avoiding parsing documents in setup.py can reduce bugs (version_str was -0.1-)
    • Put metadata all in one file (pyproject.toml )
    • benefit: toml becomes more important in python, check here
  3. Add lint CI to align coding style

    • Lint / Enforce style (pull_request) CI utilizes style.sh to do the test
    • We can only make Lint / Enforce style (pull_request) as required after a reasonable transition time period
  4. Continue work (actually apply lint on files) on [Lint] Apply lint #126

fixes #105

@titaiwangms titaiwangms changed the title [WIP][Lint] Add Lint and move metadata from setup.py to pyproject.toml [Lint] Add Lint and move metadata from setup.py to pyproject.toml Sep 20, 2022
@titaiwangms titaiwangms added the enhancement New feature or request label Sep 20, 2022
@gramalingam
Copy link
Collaborator

A generic question (on the broader topic): Is there any way for a reviewer to turn off the github warning messages in the UI? They seem appropriate for the person who created the PR, but takes up a lot of screen space for the reviewer.

@@ -0,0 +1,33 @@
#!/usr/bin/env bash
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume that this is only for checking? How many of these can be fixed automatically? Can we create a utility for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will see if I can include some useful auto-formatter and put them into a bash script.

@titaiwangms
Copy link
Contributor Author

titaiwangms commented Sep 20, 2022

A generic question (on the broader topic): Is there any way for a reviewer to turn off the github warning messages in the UI? They seem appropriate for the person who created the PR, but takes up a lot of screen space for the reviewer.

Sorry, that's my fault that I used ONNX setting, but didn't include pylint for now (since it warns a lot.). Ususally the warning message wouldn't be this much. The warning message are all about pylint, and I haven't adjusted that (In normal case, you get the warning in local, and address it). But some checks I would suggest we keep it on UI, like misspelling. I will add pylint in the next commit.

- name: Setup Python
uses: actions/[email protected]
with:
python-version: "3.10"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can install all dev dependencies to help pylint find onnx etc.

@@ -59,10 +60,6 @@ steps:
pytest -v onnxscript --cov=onnxscript --cov-report term-missing
displayName: 'pytest'

- script: |
python -m flake8 onnxscript --max-line-length 95 --exclude "**test/models/*.py,**onnx_backend_test_code/*.py"
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be irrelevant to this PR: does anyone know why these files are ignored for formatter?

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 guess the tests are about how you can use onnx_script, and those writings doesn't have to follow formatting as it's "user-side code". but cc @gramalingam


jobs:
lint-python:
name: Lint Python
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried an easy fix with permission - read only on PR didn't work.
track #127

Copy link
Collaborator

Choose a reason for hiding this comment

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

SG. Can be another pr imo

@titaiwangms titaiwangms mentioned this pull request Sep 21, 2022
@titaiwangms
Copy link
Contributor Author

cc @gramalingam for final review.

@@ -0,0 +1,25 @@
#!/usr/bin/env bash
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible to add something for windows? That would be great, thanks!

Copy link
Contributor Author

@titaiwangms titaiwangms Sep 23, 2022

Choose a reason for hiding this comment

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

I will have .bat version in another PR. #127

.flake8 Outdated
@@ -0,0 +1,16 @@
# flake8 is currebtly not yet supported by pyproject.toml.
Copy link
Member

Choose a reason for hiding this comment

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

misspelling

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

pyproject.toml Outdated
"License :: OSI Approved :: Apache Software License",
]
# NOTE: replace requirements.txt
dependencies = ["numpy==1.21.5", "protobuf<4", "onnx"]
Copy link
Member

Choose a reason for hiding this comment

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

maybe we can replace == by >= ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@titaiwangms titaiwangms merged commit a48de87 into microsoft:main Sep 23, 2022
titaiwangms added a commit that referenced this pull request Sep 23, 2022
Should be merged after #120 
fixes #125 

1. add `auto-formatter` **lint.sh** (feel free to add on others)
2. flake8, black, and isort formatting is clean now
3. pylint and mypy is a lot of work to address - need everyone address
these step by step (also take them out from style.sh, and make
style_optional.sh CI test for them.)
4. relative path addressed (import module instead of class and function)
5. We should enable Lint/Enforce as mandatory
6. Move debuginfo stand alone as it caused circular import.

NOTE: I hope this one can be quickly merged, as there are PRs being
merged constantly which means endless merge conflict for this one.

Co-authored-by: Ubuntu <titaiwang@titaiwanglinuxcpudev.y3zdd0j2xrqelnmezcgpqgmnte.jx.internal.cloudapp.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set up linters for the project
5 participants