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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ce8a00a
modified a line in example
Sep 14, 2022
c1bf7a6
doc inside script
Sep 14, 2022
9486154
[Lint] Add flake8+back+isort
Sep 15, 2022
75e4b0e
[Lint] Add flake8+back+isort
Sep 15, 2022
57101ee
modified .flake8
titaiwangms Sep 16, 2022
7e60bf5
modified .flake8
titaiwangms Sep 16, 2022
b1feb40
CI without install
titaiwangms Sep 16, 2022
fd10719
CI install package
titaiwangms Sep 16, 2022
8763776
__version__ single-source
titaiwangms Sep 16, 2022
8d56a86
add py3.7 __version__ support
titaiwangms Sep 16, 2022
7a742a0
use pip install in CI
titaiwangms Sep 16, 2022
66d284d
importlib.metadata
titaiwangms Sep 16, 2022
0bcca9a
CI-patch1
titaiwangms Sep 16, 2022
87ffeda
CI patch-2
titaiwangms Sep 16, 2022
70d32c6
CI-patch3
titaiwangms Sep 16, 2022
89a904b
CI patch-4
titaiwangms Sep 16, 2022
1554068
CI patch-5
titaiwangms Sep 16, 2022
9d8a0a7
CI patch-6
titaiwangms Sep 16, 2022
2c61dc6
exclude tests
titaiwangms Sep 19, 2022
8dd5314
fix import bugs
titaiwangms Sep 19, 2022
d721a19
input package name
titaiwangms Sep 19, 2022
8d98b63
update README.md with lint
titaiwangms Sep 20, 2022
eb2783d
Merge branch 'main' into titaiwang/add_lint
titaiwangms Sep 20, 2022
1ded058
test on changes
titaiwangms Sep 21, 2022
bbd23c7
add pylint into toml and check importError
titaiwangms Sep 21, 2022
68fb8fa
added pylint into style.sh and test __package__
titaiwangms Sep 21, 2022
01f2312
pylint addressed
titaiwangms Sep 21, 2022
8604e3d
update .flake8 comment
titaiwangms Sep 21, 2022
744090a
modified follow warnings on UI
titaiwangms Sep 21, 2022
83c9409
typo patch-1
titaiwangms Sep 21, 2022
d39b651
format toml and update .flake8
titaiwangms Sep 21, 2022
a223577
update azure-ci
titaiwangms Sep 21, 2022
62d0a9b
Merge branch 'main' into titaiwang/add_lint
titaiwangms Sep 22, 2022
1c79e88
add auto-formatter
titaiwangms Sep 22, 2022
94f4543
minor fixes
titaiwangms Sep 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# flake8 is currently not yet supported by pyproject.toml.
# Please move this into pyproject.toml, when it does.

[flake8]
max-line-length = 95
### DEFAULT IGNORES FOR 4-space INDENTED PROJECTS ###
# W503 talks about operator formatting which is too opinionated.
# E203 is need to support black formatting.
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html
extend-ignore = E203, W503
exclude =
.git,
__pycache__,
.eggs,
**test/models/*.py,
**onnx_backend_test_code/*.py,
86 changes: 86 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Lint

on:
push:
branches:
- main
pull_request:

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

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- 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.

- name: misspell # Check spellings as well
uses: reviewdog/action-misspell@v1
with:
github_token: ${{ secrets.github_token }}
locale: "US"
reporter: github-pr-check
level: info
filter_mode: diff_context
- name: shellcheck # Static check shell scripts
uses: reviewdog/action-shellcheck@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-check
level: info
filter_mode: diff_context

enforce-style:
name: Enforce style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/[email protected]
with:
# Version range or exact version of Python to use, using SemVer's version range syntax. Reads from .python-version if unset.
python-version: "3.10"
- name: Install ONNXScript
run: |
# The code is from azure-pipelines.yml
# Install dependencies
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install -q -r requirements-dev.txt
# Install ONNX
python -m pip uninstall -y onnx-function-experiment
python -m pip uninstall -y ort-function-experiment-nightly
python -m pip install onnx onnxruntime
# install packages
python -m pip install -e .
- name: Run style.sh
run: |
bash tools/style.sh
optional-style:
name: Optional style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/[email protected]
with:
# Version range or exact version of Python to use, using SemVer's version range syntax. Reads from .python-version if unset.
python-version: "3.10"
- name: Install ONNXScript
run: |
# The code is from azure-pipelines.yml
# Install dependencies
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install -q -r requirements-dev.txt
# Install ONNX
python -m pip uninstall -y onnx-function-experiment
python -m pip uninstall -y ort-function-experiment-nightly
python -m pip install onnx onnxruntime
# install packages
python -m pip install -e .
- name: Run style_optional.sh
run: |
bash tools/style_optional.sh
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ include requirements.txt

# exclude from sdist
exclude *.onnx
prune */__pycache__
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer ending all files with a newline.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way to automate this?

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.

I think a temporary solution would be adding "auto-formatter" into a utils.sh (or even extend from style.sh). Some of auto-formatter that I can think of is black (included in CI), isort (included in CI), and autopep8 (required already in dev). And we can make "Linter" a long-term project? (There is also autoflake8 which I am not so familiar with, and these auto-formatter could be contradict to each other. )

53 changes: 39 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@

ONNXScript is a subset of Python that can be used to author ONNX functions (as well as ONNX models).

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.

## Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
Expand Down Expand Up @@ -129,5 +115,44 @@ More examples can be found in folder [docs/examples](docs/examples).

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit [Microsoft CLA](https://cla.opensource.microsoft.com).

When you submit a pull request, a CLA bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.

**Unit Test**

Every change impacting the converter or the eager evaluation must be unit tested with
class `OnnxScriptTestCase` to ensure both systems do return the same results with the same inputs.

**Code Style**

We use flake8, black, isort, and mypy to check code format. You can find their configuration in .flake8 and pyproject.toml, and

run `auto-formatter` by:

```bash
./tools/lint.sh
```

and run `check` by:

```bash
./tools/style.sh
```

optional check:

```bash
./tools/style_optional.sh
```

NOTE: mypy and pylint needs to be manually address

13 changes: 5 additions & 8 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ steps:

- script: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
python -m pip install --upgrade setuptools
python -m pip install -r requirements-dev.txt
displayName: 'Install dependencies'

- script: |
if [ '$(onnx.standard)' == '1' ]
then
pip uninstall -y onnx-function-experiment
pip uninstall -y ort-function-experiment-nightly
pip install onnx onnxruntime
python -m pip uninstall -y onnx-function-experiment
python -m pip uninstall -y ort-function-experiment-nightly
python -m pip install onnx onnxruntime
fi
displayName: 'Install onnx'

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

- script: |
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice change by consolidating configs in the config file 🚀

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

displayName: 'flake8'

- script: |
python setup.py install
displayName: 'install package'
Expand Down
19 changes: 16 additions & 3 deletions onnxscript/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@
# Licensed under the MIT License.
# --------------------------------------------------------------------------

__version__ = '0.1'

import sys
from .main import script, export_onnx_lib, OnnxFunction
from .backend.onnx_export import export2python as proto2python

__all__ = [script, export_onnx_lib, OnnxFunction, proto2python]
if sys.version_info[0:2] >= (3, 8):
import importlib.metadata as importlib_metadata
else:
# TODO: Remove this when Python 3.7 is deprecated
import importlib_metadata

try:
# TODO: should we algin the folder name with package name?
# It's onnxscript and onnx-script now. That way, we can use __package__ here.
__version__ = importlib_metadata.version("onnx-script")
except importlib_metadata.PackageNotFoundError:
__version__ = None


__all__ = ["script", "export_onnx_lib", "OnnxFunction", "proto2python"]
97 changes: 97 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# SPDX-License-Identifier: Apache-2.0

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "onnx-script"
version = "0.1"
description = "Authoring ONNX functions in Python"
authors = [{ name = "Microsoft Corporation", email = "[email protected]" }]
# TODO: put url/longer description into here
# Get rid of longer description seems to require Poetry
readme = "README.md"
requires-python = ">=3.7"
license = { text = 'Apache License v2.0' }
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: Apache Software License",
]
# NOTE: replace requirements.txt
dependencies = ["numpy>=1.21.5", "protobuf<4", "onnx"]

[project.optional-dependencies]
test = ["flake8", "mypy", "black", "isort[colors]", "pylint"]

[tool.distutils.bdist_wheel]
universal = true

[tool.pytest.ini_options]
filterwarnings = ["ignore::UserWarning", "ignore::DeprecationWarning"]

[tool.mypy]
strict_optional = true
warn_return_any = true
warn_no_return = true
# TODO warn_unused_ignores = true
warn_redundant_casts = true
warn_incomplete_stub = true
# TODO disallow_untyped_calls = true
check_untyped_defs = true
disallow_any_generics = true
no_implicit_optional = true
# TODO disallow_incomplete_defs = true
# TODO disallow_subclassing_any = true
disallow_untyped_decorators = true
warn_unused_configs = true
show_error_codes = true
show_column_numbers = true


[[tool.mypy.overrides]]
module = "tools.*"
disallow_untyped_defs = true

# Ignore errors in test
[[tool.mypy.overrides]]
module = [
"setup",
"onnxscript.test.models.*",
"onnxscript.test.onnx_backend_test_code.*",
]
ignore_errors = true

[tool.black]
target-version = ["py37", "py38", "py39", "py310"]
extend-exclude = "^onnxscript/test/models"

[tool.isort]
profile = "black"
extend_skip_glob = ["**test/models/*.py", "**onnx_backend_test_code/*.py"]

[tool.pylint.MASTER]
ignore-paths = [
"^onnxscript/test/models/",
"^onnxscript/test/onnx_backend_test_code/",
]

[tool.pylint.'MESSAGES CONTROL']
disable = [
"missing-docstring",
"import-error",
"no-member",
"line-too-long",
"fixme",
"too-few-public-methods",
"no-name-in-module",
"invalid-name", # TODO: Add naming guidance and enable this check.
]
6 changes: 5 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
autopep8
click
flake8
numpy==1.21.5
matplotlib
--pre -f https://onnxruntimepackages.blob.core.windows.net/$web/onnx-function-experiment.html
Expand All @@ -16,4 +15,9 @@ pytest-cov
pytest-azurepipelines
pytest-subtests
torch
# Lint
flake8
mypy
black
isort[colors]

3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

11 changes: 0 additions & 11 deletions setup.cfg

This file was deleted.

Loading