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:
Родитель
a0a145a855
Коммит
5be32481b1
|
@ -0,0 +1,13 @@
|
|||
# SuperBench
|
||||
outputs
|
||||
*.tar.gz
|
||||
|
||||
# Python
|
||||
__pycache__
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
|
||||
# Git
|
||||
.git
|
||||
.github
|
|
@ -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
|
|
@ -0,0 +1,6 @@
|
|||
[flake8]
|
||||
inline-quotes = single
|
||||
multiline-quotes = double
|
||||
docstring-quotes = double
|
||||
docstring-convention = google
|
||||
max-complexity = 10
|
|
@ -0,0 +1,5 @@
|
|||
* text=auto eol=lf
|
||||
|
||||
# Source files
|
||||
bin/* text
|
||||
*.py text diff=python
|
|
@ -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 .
|
|
@ -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/
|
|
@ -0,0 +1,7 @@
|
|||
[mypy]
|
||||
ignore_missing_imports = True
|
||||
scripts_are_modules = True
|
||||
|
||||
[superbench]
|
||||
warn_return_any = True
|
||||
disallow_untyped_defs = True
|
|
@ -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
|
|
@ -0,0 +1,4 @@
|
|||
[style]
|
||||
based_on_style = pep8
|
||||
spaces_before_comment = 4
|
||||
blank_line_before_module_docstring = True
|
|
@ -0,0 +1 @@
|
|||
include LICENSE README.md
|
|
@ -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,
|
||||
},
|
||||
)
|
|
@ -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 && \
|
||||
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
|
||||
WORKDIR /superbench
|
||||
COPY . /superbench
|
||||
|
||||
# Check code format using flake8
|
||||
RUN python3 -m flake8
|
||||
# Upgrade pip and install dependencies
|
||||
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.
|
||||
# Licensed under the MIT license.
|
||||
|
||||
# content of test_sample.py
|
||||
# get it from https://docs.pytest.org/en/stable/
|
||||
"""Test example.
|
||||
|
||||
Get it from https://docs.pytest.org/en/stable/.
|
||||
"""
|
||||
|
||||
|
||||
def inc(x):
|
||||
"""Increase an integer.
|
||||
|
||||
Args:
|
||||
x (int): Input value.
|
||||
|
||||
Returns:
|
||||
int: Increased value.
|
||||
"""
|
||||
return x + 1
|
||||
|
||||
|
||||
def test_answer():
|
||||
"""Test inc function."""
|
||||
assert inc(3) == 4
|
||||
|
|
Загрузка…
Ссылка в новой задаче