From 20b67b294c7df551e4671c1de3afc5f6865d6819 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Mon, 30 Mar 2020 16:36:11 +0800 Subject: [PATCH] ci(python): add format and lint check for python GitOrigin-RevId: d8d106b92720b2b5c7231ff9930bea3c54ddb409 --- python_module/megengine/functional/nn.py | 8 +++-- .../megengine/random/distribution.py | 10 +++--- python_module/requires-style.txt | 4 +++ python_module/requires-test.txt | 2 ++ python_module/requires.txt | 7 ++++ python_module/setup.py | 32 ++++++------------- python_module/test/run.sh | 3 +- 7 files changed, 35 insertions(+), 31 deletions(-) create mode 100644 python_module/requires-style.txt create mode 100644 python_module/requires-test.txt create mode 100644 python_module/requires.txt diff --git a/python_module/megengine/functional/nn.py b/python_module/megengine/functional/nn.py index 64021b2d6..2fe462a58 100644 --- a/python_module/megengine/functional/nn.py +++ b/python_module/megengine/functional/nn.py @@ -114,7 +114,7 @@ def max_pool2d( :param stride: The stride of the window. If not provided, its value is set to ``kernel_size``. Default: None :param padding: Implicit zero padding to be added on both sides. Default: 0 - + Refer to :class:`~.MaxPool2d` for more information. """ @@ -615,7 +615,7 @@ def interpolate( :param mode: interpolation methods, acceptable values are: 'bilinear'(default), 'linear', 'nearest' (todo), 'cubic' (todo), 'area' (todo) - + Examples: @@ -743,7 +743,9 @@ def dropout(inp: Tensor, drop_prob: float, rescale: bool = True) -> Tensor: import numpy as np from megengine import tensor import megengine.functional as F + from megengine.random import manual_seed + manual_seed(0) data = tensor(np.ones(10, dtype=np.float32)) out = F.dropout(data, 1./3.) print(out.numpy()) @@ -767,7 +769,7 @@ def dropout(inp: Tensor, drop_prob: float, rescale: bool = True) -> Tensor: @wrap_io_tensor def identity(inp: Tensor) -> Tensor: """applies an identity transform to the input tensor. - + :param inp: The input tensor """ return mgb.opr.identity(inp) diff --git a/python_module/megengine/random/distribution.py b/python_module/megengine/random/distribution.py index 5d07b5acf..cd5130ab0 100644 --- a/python_module/megengine/random/distribution.py +++ b/python_module/megengine/random/distribution.py @@ -42,13 +42,14 @@ def gaussian( import megengine as mge import megengine.random as rand + rand.manual_seed(0) x = rand.gaussian((2, 2), mean=0, std=1) print(x.numpy()) .. testoutput:: - [[ 0.2925366 -0.718359 ] - [ 0.09999694 -0.3931978 ]] + [[-0.20235455 -0.6959438 ] + [-1.4939808 -1.5824696 ]] """ comp_node, comp_graph = _use_default_if_none(comp_node, comp_graph) @@ -78,13 +79,14 @@ def uniform( import megengine as mge import megengine.random as rand + rand.manual_seed(0) x = rand.uniform((2, 2)) print(x.numpy()) .. testoutput:: - [[0.74021935 0.9209938 ] - [0.03902049 0.9689629 ]] + [[0.76901674 0.70496535] + [0.09365904 0.62957656]] """ comp_node, comp_graph = _use_default_if_none(comp_node, comp_graph) diff --git a/python_module/requires-style.txt b/python_module/requires-style.txt new file mode 100644 index 000000000..899aac527 --- /dev/null +++ b/python_module/requires-style.txt @@ -0,0 +1,4 @@ +black==19.10b0 +isort==4.3.21 +pylint==2.4.3 +mypy==0.750 diff --git a/python_module/requires-test.txt b/python_module/requires-test.txt new file mode 100644 index 000000000..0bd28419d --- /dev/null +++ b/python_module/requires-test.txt @@ -0,0 +1,2 @@ +pytest==5.3.0 +pytest-sphinx==0.2.2 diff --git a/python_module/requires.txt b/python_module/requires.txt new file mode 100644 index 000000000..5ebb52a3b --- /dev/null +++ b/python_module/requires.txt @@ -0,0 +1,7 @@ +numpy>=1.17 +opencv-python +pyarrow +requests +tabulate +tqdm +redispy diff --git a/python_module/setup.py b/python_module/setup.py index 43e72d7aa..f590322b2 100644 --- a/python_module/setup.py +++ b/python_module/setup.py @@ -55,6 +55,13 @@ package_data += [ os.path.join('module', 'pytorch', 'torch_mem_fwd.cpp') ] +with open('requires.txt') as f: + requires = f.read().splitlines() +with open('requires-style.txt') as f: + requires_style = f.read().splitlines() +with open('requires-test.txt') as f: + requires_test = f.read().splitlines() + setup_kwargs = dict( name=package_name, version=__version__, @@ -67,29 +74,10 @@ setup_kwargs = dict( 'megengine': package_data, }, ext_modules=[PrecompiledExtesion('megengine._internal._mgb')], - install_requires=[ - 'numpy>=1.17', - 'opencv-python', - 'pyarrow', - 'requests', - 'tabulate', - 'tqdm', - ], + install_requires=requires, extras_require={ - 'dev': [ - 'black==19.10b0', - 'isort==4.3.21', - 'pylint==2.4.3', - 'mypy==0.750', - 'pytest==5.3.0', - 'pytest-sphinx==0.2.2', - ], - 'data': [ - 'scipy', - ], - 'ci': [ - 'pytest==5.3.0', - ], + 'dev': [*requires_style, *requires_test], + 'ci': requires_test, }, cmdclass={'build_ext': build_ext}, ) diff --git a/python_module/test/run.sh b/python_module/test/run.sh index 95729bb45..08d0abbff 100755 --- a/python_module/test/run.sh +++ b/python_module/test/run.sh @@ -1,13 +1,12 @@ #!/bin/bash -e pushd $(dirname "${BASH_SOURCE[0]}")/.. >/dev/null - pytest -xv -m 'not internet'\ + pytest -xv -m 'not internet' \ --ignore test/unit/module/test_pytorch.py \ --ignore test/pytorch_comparison \ --ignore test/unit/hub/test_hub.py \ --ignore test/unit/data \ --ignore test/integration/manual \ - --ignore megengine/docs/ \ --ignore megengine/module/pytorch \ megengine test popd >/dev/null -- GitLab