Skip to content

Commit 66816a3

Browse files
authored
Merge pull request #87 from rth/simplfy-example
Lint examples/simple-extension and try to simplify setup.py
2 parents a2700a1 + 29b99d5 commit 66816a3

File tree

5 files changed

+10
-33
lines changed

5 files changed

+10
-33
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ before_install:
3939
- source ./ci/travis/setup.sh
4040

4141
install:
42-
- pip install setuptools-rust pytest pytest-benchmark tox numpy
42+
- pip install setuptools-rust pytest pytest-benchmark \
43+
tox numpy flake8
4344

4445
script:
46+
- flake8 examples/
4547
- ./ci/travis/test.sh
4648

4749
deploy:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .rust_ext import *
1+
from .rust_ext import * # noqa

examples/simple-extension/setup.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
1-
import os
2-
import subprocess
31
import sys
42
from setuptools import find_packages, setup
5-
from setuptools.command.test import test as TestCommand
63
from setuptools_rust import RustExtension
74

8-
class PyTest(TestCommand):
9-
user_options = []
10-
def run(self):
11-
self.run_command("test_rust")
12-
import subprocess
13-
errno = subprocess.call(['pytest', 'tests'])
14-
raise SystemExit(errno)
155

16-
17-
def get_cfg_flags():
18-
version = sys.version_info[0:2]
19-
if version[0] == 2:
20-
return ['--cfg=Py_2']
21-
else:
22-
return ['--cfg=Py_3']
23-
24-
def get_features():
25-
version = sys.version_info[0:2]
26-
if version[0] == 2:
27-
return ['numpy/python2']
28-
else:
29-
return ['numpy/python3']
6+
PYTHON_MAJOR_VERSION = sys.version_info[0]
307

318
setup_requires = ['setuptools-rust>=0.6.0']
329
install_requires = ['numpy']
@@ -39,13 +16,12 @@ def get_features():
3916
rust_extensions=[RustExtension(
4017
'rust_ext.rust_ext',
4118
'./Cargo.toml',
42-
rustc_flags=get_cfg_flags(),
43-
features=get_features(),
19+
rustc_flags=['--cfg=Py_{}'.format(PYTHON_MAJOR_VERSION)],
20+
features=['numpy/python{}'.format(PYTHON_MAJOR_VERSION)],
4421
)],
4522
install_requires=install_requires,
4623
setup_requires=setup_requires,
4724
test_requires=test_requires,
4825
packages=find_packages(),
4926
zip_safe=False,
50-
cmdclass=dict(test=PyTest)
5127
)

examples/simple-extension/tests/test_ext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22
from rust_ext import axpy, mult
3-
import pytest
3+
44

55
def test_axpy():
66
x = np.array([1.0, 2.0, 3.0])
@@ -12,8 +12,8 @@ def test_axpy():
1212
z = axpy(3.0, x, y)
1313
np.testing.assert_array_almost_equal(z, np.array([6.0, 9.0, 12.0, 15.0]))
1414

15+
1516
def test_mult():
1617
x = np.array([1.0, 2.0, 3.0])
1718
mult(3.0, x)
1819
np.testing.assert_array_almost_equal(x, np.array([3.0, 6.0, 9.0]))
19-

examples/simple-extension/tox.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ skip_missing_interpreters = true
1010
description = Run the unit tests under {basepython}
1111
deps = -rrequirements-dev.txt
1212
usedevelop = True
13-
commands = pip install -e .
14-
pytest
13+
commands = pytest

0 commit comments

Comments
 (0)