Setup: Init - Initialize setup.py and basic configs (#4)

Initialize setup.py and basic configurations for this project.

Major revisions:

- initialize setup.py for Python package
- add gitignore and dockerignore
- add editorconfig for editors
- configure yapf for auto formating
- configure mypy for type hint
- configure flake8 for lint, including quotes and docstrings
- add pre-commit check for `git commit`
- add spelling check in GitHub Actions
- format existing files according to configured rules

Example usage:

    # install dependencies
    $ python3 -m pip install -e .[dev,test]
    $ pre-commit install

    # format code automatically
    $ python3 setup.py format

    # lint code
    $ python3 setup.py lint

    # test code
    $ python3 setup.py test
This commit is contained in:
Yifan Xiong 2021-01-28 21:01:28 +08:00 коммит произвёл GitHub
Родитель a0a145a855
Коммит 5be32481b1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
17 изменённых файлов: 468 добавлений и 40 удалений

13
.dockerignore Normal file
Просмотреть файл

@ -0,0 +1,13 @@
# SuperBench
outputs
*.tar.gz
# Python
__pycache__
*.pyc
*.pyo
*.pyd
# Git
.git
.github

19
.editorconfig Normal file
Просмотреть файл

@ -0,0 +1,19 @@
root = true
[*]
indent_style = space
indent_size = 4
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
[*.py]
max_line_length = 79
[*.yaml]
indent_size = 2
[*.json]
indent_size = 2
insert_final_newline = false

6
.flake8 Normal file
Просмотреть файл

@ -0,0 +1,6 @@
[flake8]
inline-quotes = single
multiline-quotes = double
docstring-quotes = double
docstring-convention = google
max-complexity = 10

5
.gitattributes поставляемый Normal file
Просмотреть файл

@ -0,0 +1,5 @@
* text=auto eol=lf
# Source files
bin/* text
*.py text diff=python

21
.github/workflows/lint.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,21 @@
name: Lint
on:
pull_request:
branches:
- main
- dev
jobs:
spelling:
name: Spelling check
runs-on: ubuntu-16.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: |
curl -L https://git.io/misspell | sudo bash -s -- -b /bin
- name: Check spelling
run: |
misspell -error .

144
.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,144 @@
# Created by https://github.com/github/gitignore
# SuperBench tmp files
outputs/
*.tar.gz
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/

7
.mypy.ini Normal file
Просмотреть файл

@ -0,0 +1,7 @@
[mypy]
ignore_missing_imports = True
scripts_are_modules = True
[superbench]
warn_return_any = True
disallow_untyped_defs = True

33
.pre-commit-config.yaml Normal file
Просмотреть файл

@ -0,0 +1,33 @@
# Run `pre-commit install` to install
# See https://pre-commit.com for more information
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-added-large-files
- id: check-docstring-first
- id: check-json
- id: check-yaml
- id: detect-private-key
- id: double-quote-string-fixer
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.30.0
hooks:
- id: yapf
name: Format code using yapf
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.800
hooks:
- id: mypy
name: Check type hint using mypy
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
name: Lint code using flake8
additional_dependencies:
- flake8-quotes
- flake8-docstrings

4
.style.yapf Normal file
Просмотреть файл

@ -0,0 +1,4 @@
[style]
based_on_style = pep8
spaces_before_comment = 4
blank_line_before_module_docstring = True

1
MANIFEST.in Normal file
Просмотреть файл

@ -0,0 +1 @@
include LICENSE README.md

Просмотреть файл

@ -26,8 +26,8 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio
## Trademarks ## Trademarks
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
trademarks or logos is subject to and must follow trademarks or logos is subject to and must follow
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies. Any use of third-party trademarks or logos are subject to those third-party's policies.

Просмотреть файл

@ -14,7 +14,7 @@ Instead, please report them to the Microsoft Security Response Center (MSRC) at
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc). If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
@ -38,4 +38,4 @@ We prefer all communications to be in English.
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd). Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd).
<!-- END MICROSOFT SECURITY.MD BLOCK --> <!-- END MICROSOFT SECURITY.MD BLOCK -->

Просмотреть файл

@ -1,25 +1,25 @@
# TODO: The maintainer of this repo has not yet edited this file # TODO: The maintainer of this repo has not yet edited this file
**REPO OWNER**: Do you want Customer Service & Support (CSS) support for this product/project? **REPO OWNER**: Do you want Customer Service & Support (CSS) support for this product/project?
- **No CSS support:** Fill out this template with information about how to file issues and get help. - **No CSS support:** Fill out this template with information about how to file issues and get help.
- **Yes CSS support:** Fill out an intake form at [aka.ms/spot](https://aka.ms/spot). CSS will work with/help you to determine next steps. More details also available at [aka.ms/onboardsupport](https://aka.ms/onboardsupport). - **Yes CSS support:** Fill out an intake form at [aka.ms/spot](https://aka.ms/spot). CSS will work with/help you to determine next steps. More details also available at [aka.ms/onboardsupport](https://aka.ms/onboardsupport).
- **Not sure?** Fill out a SPOT intake as though the answer were "Yes". CSS will help you decide. - **Not sure?** Fill out a SPOT intake as though the answer were "Yes". CSS will help you decide.
*Then remove this first heading from this SUPPORT.MD file before publishing your repo.* *Then remove this first heading from this SUPPORT.MD file before publishing your repo.*
# Support # Support
## How to file issues and get help ## How to file issues and get help
This project uses GitHub Issues to track bugs and feature requests. Please search the existing This project uses GitHub Issues to track bugs and feature requests. Please search the existing
issues before filing new issues to avoid duplicates. For new issues, file your bug or issues before filing new issues to avoid duplicates. For new issues, file your bug or
feature request as a new Issue. feature request as a new Issue.
For help and questions about using this project, please **REPO MAINTAINER: INSERT INSTRUCTIONS HERE For help and questions about using this project, please **REPO MAINTAINER: INSERT INSTRUCTIONS HERE
FOR HOW TO ENGAGE REPO OWNERS OR COMMUNITY FOR HELP. COULD BE A STACK OVERFLOW TAG OR OTHER FOR HOW TO ENGAGE REPO OWNERS OR COMMUNITY FOR HELP. COULD BE A STACK OVERFLOW TAG OR OTHER
CHANNEL. WHERE WILL YOU HELP PEOPLE?**. CHANNEL. WHERE WILL YOU HELP PEOPLE?**.
## Microsoft Support Policy ## Microsoft Support Policy
Support for this **PROJECT or PRODUCT** is limited to the resources listed above. Support for this **PROJECT or PRODUCT** is limited to the resources listed above.

153
setup.py Normal file
Просмотреть файл

@ -0,0 +1,153 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""The setuptools based setup module.
Reference:
https://packaging.python.org/guides/distributing-packages-using-setuptools/
"""
import os
import sys
import pathlib
from typing import List, Tuple
from setuptools import setup, find_packages, Command
import superbench
here = pathlib.Path(__file__).parent.resolve()
long_description = (here / 'README.md').read_text(encoding='utf-8')
class Formatter(Command):
"""Cmdclass for `python setup.py format`.
Args:
Command (distutils.cmd.Command):
Abstract base class for defining command classes.
"""
description = 'format the code using yapf'
user_options: List[Tuple[str, str, str]] = []
def initialize_options(self):
"""Set default values for options that this command supports."""
pass
def finalize_options(self):
"""Set final values for options that this command supports."""
pass
def run(self):
"""Fromat the code using yapf."""
errno = os.system(
'python3 -m yapf --in-place --recursive --exclude .git .')
sys.exit(errno)
class Linter(Command):
"""Cmdclass for `python setup.py lint`.
Args:
Command (distutils.cmd.Command):
Abstract base class for defining command classes.
"""
description = 'lint the code using flake8'
user_options: List[Tuple[str, str, str]] = []
def initialize_options(self):
"""Set default values for options that this command supports."""
pass
def finalize_options(self):
"""Set final values for options that this command supports."""
pass
def run(self):
"""Lint the code with yapf, mypy, and flake8."""
errno = os.system(' && '.join([
'python3 -m yapf --diff --recursive --exclude .git .',
'python3 -m mypy .',
'python3 -m flake8',
]))
sys.exit(errno)
class Tester(Command):
"""Cmdclass for `python setup.py test`.
Args:
Command (distutils.cmd.Command):
Abstract base class for defining command classes.
"""
description = 'test the code using pytest'
user_options: List[Tuple[str, str, str]] = []
def initialize_options(self):
"""Set default values for options that this command supports."""
pass
def finalize_options(self):
"""Set final values for options that this command supports."""
pass
def run(self):
"""Run pytest."""
errno = os.system('python3 -m pytest -v')
sys.exit(errno)
setup(
name='superbench',
version=superbench.__version__,
description='Provide hardware and software benchmarks for AI systems.',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/microsoft/superbenchmark',
author=superbench.__author__,
author_email='superbench@microsoft.com',
license='MIT',
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Environment :: GPU',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: MIT License',
'Operating System :: POSIX',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: System :: Benchmark',
'Topic :: System :: Clustering',
'Topic :: System :: Hardware',
],
keywords='benchmark, AI systems',
packages=find_packages(exclude=['tests']),
python_requires='>=3.6, <4',
install_requires=[],
extras_require={
'dev': ['pre-commit'],
'test': [
'yapf',
'mypy',
'flake8',
'flake8-quotes',
'flake8-docstrings',
'pytest',
],
},
package_data={},
entry_points={
'console_scripts': [],
},
cmdclass={
'format': Formatter,
'lint': Linter,
'test': Tester,
},
)

10
superbench/__init__.py Normal file
Просмотреть файл

@ -0,0 +1,10 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""SuperBench Python module.
Provide hardware and software benchmarks for AI systems.
"""
__version__ = '0.0.0'
__author__ = 'Microsoft'

Просмотреть файл

@ -12,16 +12,16 @@ RUN apt-get update && apt-get install -y \
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 && \ RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 && \
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 10 update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 10
# Upgrade pip and instll flake8 and pytest
RUN python3 -m pip install --upgrade pip && \
python3 -m pip install flake8 pytest
# Create workspace # Create workspace
WORKDIR /superbench WORKDIR /superbench
COPY . /superbench COPY . /superbench
# Check code format using flake8 # Upgrade pip and install dependencies
RUN python3 -m flake8 RUN python3 -m pip install --upgrade pip setuptools && \
python3 -m pip install .[test]
# Install library and run pytest
RUN python3 -m pytest -v # Lint code
RUN python3 setup.py lint
# Test code
RUN python3 setup.py test

Просмотреть файл

@ -1,12 +1,24 @@
# Copyright (c) Microsoft Corporation. # Copyright (c) Microsoft Corporation.
# Licensed under the MIT license. # Licensed under the MIT license.
# content of test_sample.py """Test example.
# get it from https://docs.pytest.org/en/stable/
Get it from https://docs.pytest.org/en/stable/.
"""
def inc(x): def inc(x):
"""Increase an integer.
Args:
x (int): Input value.
Returns:
int: Increased value.
"""
return x + 1 return x + 1
def test_answer(): def test_answer():
"""Test inc function."""
assert inc(3) == 4 assert inc(3) == 4