Repository: microsoft/onnxscript

Issue:
Set up linters for the project
It helps if we set up linters early in the development process (less big PRs for fixes in the future). We may consider: mypy, pylint, black, isort, pydocstyle, flake8, bandit and xdoctest.


Discussion:

Resolving patch:
diff --git a/onnxscript/__init__.py b/onnxscript/__init__.py
--- a/onnxscript/__init__.py
+++ b/onnxscript/__init__.py
@@ -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"]
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -5,55 +5,26 @@
 
 # -*- coding: utf-8 -*-
 
-from distutils.core import setup
-from setuptools import find_packages
 import os
-this = os.path.dirname(__file__)
+import setuptools
 
-with open(os.path.join(this, "requirements.txt"), "r") as f:
-    requirements = [_ for _ in [_.strip("\r\n ")
-                                for _ in f.readlines()] if _ is not None]
+this = os.path.dirname(__file__)
 
-packages = find_packages()
+packages = setuptools.find_packages()
 assert packages
 
-# read version from the package file.
-version_str = '1.0.0'
-with (open(os.path.join(this, 'onnxscript/__init__.py'), "r")) as f:
-    line = [_ for _ in [_.strip("\r\n ")
-                        for _ in f.readlines()] if _.startswith("__version__")]
-    if len(line) > 0:
-        version_str = line[0].split('=')[1].strip('" ')
-
 README = os.path.join(os.getcwd(), "README.md")
-with open(README) as f:
+with open(README, encoding="utf-8") as f:
     long_description = f.read()
     start_pos = long_description.find('## Contributing')
     if start_pos >= 0:
         long_description = long_description[:start_pos]
 
-setup(
-    name='onnx-script',
-    version=version_str,
-    description="Authoring ONNX functions in Python",
+setuptools.setup(
     long_description=long_description,
     long_description_content_type='text/markdown',
-    license='Apache License v2.0',
-    author='Microsoft Corporation',
-    author_email='onnx@microsoft.com',
     url='https://github.com/onnx/onnx-script',
     packages=packages,
     include_package_data=True,
-    install_requires=requirements,
-    classifiers=[
-        'Development Status :: 4 - Beta',
-        'Environment :: Console',
-        'Intended Audience :: Developers',
-        'Operating System :: MacOS :: MacOS X',
-        'Operating System :: Microsoft :: Windows',
-        'Programming Language :: Python',
-        'Programming Language :: Python :: 3.7',
-        'Programming Language :: Python :: 3.8',
-        'Programming Language :: Python :: 3.9',
-        'License :: OSI Approved :: Apache Software License'],
+    package_data={"onnx-script": ["py.typed"], "onnx": ["py.typed"],},
 )


Test patch: