Skip to content
This repository was archived by the owner on May 23, 2024. It is now read-only.

Commit 3119f7e

Browse files
author
Jonathan Esterhazy
committed
add tox, pylint, flake8, jshint
1 parent a27e1f9 commit 3119f7e

File tree

6 files changed

+173
-10
lines changed

6 files changed

+173
-10
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
__pycache__
2+
.tox/
13
log.txt

.jshintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"asi": true
3+
}

.pylintrc

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
[MASTER]
2+
3+
ignore=
4+
tensorflow_serving
5+
6+
[MESSAGES CONTROL]
7+
8+
disable=
9+
C, # convention
10+
R, # refactor
11+
too-many-arguments, # We should fix the offending ones soon.
12+
too-many-lines, # Some files are too big, we should fix this too
13+
too-few-public-methods,
14+
too-many-instance-attributes,
15+
too-many-locals,
16+
len-as-condition, # Nice to have in the future
17+
bad-indentation,
18+
line-too-long, # We let Flake8 take care of this
19+
logging-format-interpolation,
20+
useless-object-inheritance, # We still support python2 so inheriting from object is ok
21+
invalid-name,
22+
import-error,
23+
logging-not-lazy,
24+
fixme,
25+
no-self-use,
26+
attribute-defined-outside-init,
27+
protected-access,
28+
invalid-all-object,
29+
arguments-differ,
30+
abstract-method,
31+
signature-differs
32+
33+
[REPORTS]
34+
# Set the output format. Available formats are text, parseable, colorized, msvs
35+
# (visual studio) and html
36+
output-format=colorized
37+
38+
# Tells whether to display a full report or only the messages
39+
# CHANGE: No report.
40+
reports=no
41+
42+
[FORMAT]
43+
# Maximum number of characters on a single line.
44+
max-line-length=100
45+
# Maximum number of lines in a module
46+
#max-module-lines=1000
47+
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 tab).
48+
indent-string=' '
49+
50+
[BASIC]
51+
52+
# Required attributes for module, separated by a comma
53+
#required-attributes=
54+
# List of builtins function names that should not be used, separated by a comma.
55+
# XXX: Should we ban map() & filter() for list comprehensions?
56+
# exit & quit are for the interactive interpreter shell only.
57+
# https://docs.python.org/3/library/constants.html#constants-added-by-the-site-module
58+
bad-functions=
59+
apply,
60+
exit,
61+
input,
62+
quit,
63+
64+
[SIMILARITIES]
65+
# Minimum lines number of a similarity.
66+
min-similarity-lines=5
67+
# Ignore comments when computing similarities.
68+
ignore-comments=yes
69+
# Ignore docstrings when computing similarities.
70+
ignore-docstrings=yes
71+
72+
[VARIABLES]
73+
# Tells whether we should check for unused import in __init__ files.
74+
init-import=no
75+
# A regular expression matching the beginning of the name of dummy variables
76+
# (i.e. not used).
77+
dummy-variables-rgx=_|unused_
78+
79+
# List of additional names supposed to be defined in builtins. Remember that
80+
# you should avoid to define new builtins when possible.
81+
#additional-builtins=
82+
83+
[LOGGING]
84+
# Apply logging string format checks to calls on these modules.
85+
logging-modules=
86+
logging
87+
88+
[TYPECHECK]
89+
ignored-modules=
90+
distutils

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ development machine:
3030

3131
For testing, you will also need:
3232

33-
- [Python 3.5+](https://www.python.org/)
34-
- [pytest](https://docs.pytest.org/en/latest/)
35-
- The Python [requests](http://docs.python-requests.org/en/master/) library
33+
- [Python 3.6](https://www.python.org/)
34+
- [tox](https://tox.readthedocs.io/en/latest/)
35+
- [npm](https://npmjs.org/)
36+
- [jshint](https://jshint.com/about/)
3637

3738
To test GPU images locally, you will also need:
3839

@@ -97,11 +98,12 @@ Additional `curl` examples can be found in `./scripts/curl.sh`.
9798

9899
## Running the tests
99100

100-
The package includes some automated unit and integration tests. These tests use Docker to run
101-
your image locally, and do not access resources in AWS. You can run them using `pytest`:
101+
The package includes automated tests and code checks. The tests use Docker to run the container
102+
image locally, and do not access resources in AWS. You can run the tests and static code
103+
checkers using `tox`:
102104

103105
```bash
104-
pytest ./test
106+
tox
105107
```
106108

107109
## Contributing

container/sagemaker/serve.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def __init__(self):
3737
low = int(parts[0])
3838
hi = int(parts[1])
3939
if low + 1 > hi:
40-
raise ValueError('not enough ports available in SAGEMAKER_SAFE_PORT_RANGE ({})',
41-
port_range)
40+
raise ValueError('not enough ports available in SAGEMAKER_SAFE_PORT_RANGE ({})'
41+
.format(port_range))
4242
self._tfs_grpc_port = str(low)
4343
self._tfs_rest_port = str(low + 1)
4444
else:
@@ -76,7 +76,7 @@ def _find_models(self):
7676
models = []
7777
for f in self._find_saved_model_files(base_path):
7878
parts = f.split('/')
79-
if len(parts) >= 6 and re.match('^\d+$', parts[-2]):
79+
if len(parts) >= 6 and re.match(r'^\d+$', parts[-2]):
8080
model_path = '/'.join(parts[0:-2])
8181
if model_path not in models:
8282
models.append(model_path)
@@ -140,7 +140,7 @@ def _log_version(self, command, message):
140140
except subprocess.CalledProcessError:
141141
log.warning('failed to run command: %s', command)
142142

143-
def _stop(self, *args):
143+
def _stop(self, *args): # pylint: disable=W0613
144144
self._state = 'stopping'
145145
log.info('stopping services')
146146
try:

tox.ini

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Tox (http://tox.testrun.org/) is a tool for running tests
2+
# in multiple virtualenvs. This configuration file will run the
3+
# test suite on all supported python versions. To use it, "pip install tox"
4+
# and then run "tox" from this directory.
5+
6+
[tox]
7+
skipsdist = True
8+
skip_missing_interpreters = False
9+
envlist = py36,flake8,pylint,jshint
10+
11+
[flake8]
12+
max-line-length = 100
13+
exclude =
14+
build/
15+
.github/
16+
.pytest_cache/
17+
.git
18+
.tox
19+
tests/resources/
20+
max-complexity = 10
21+
ignore =
22+
FI10,
23+
FI12,
24+
FI13,
25+
FI14,
26+
FI15,
27+
FI16,
28+
FI17,
29+
FI50,
30+
FI51,
31+
FI52,
32+
FI53,
33+
FI54,
34+
FI55,
35+
FI56,
36+
FI57,
37+
W503
38+
39+
require-code = True
40+
41+
[testenv]
42+
# {posargs} can be passed in by additional arguments specified when invoking tox.
43+
# Can be used to specify which tests to run, e.g.: tox -- -s
44+
basepython = python3
45+
commands =
46+
python -m pytest {posargs}
47+
deps =
48+
pytest
49+
requests
50+
51+
[testenv:flake8]
52+
deps =
53+
flake8
54+
commands = flake8 container/
55+
56+
[testenv:pylint]
57+
deps =
58+
pylint
59+
commands =
60+
python -m pylint --rcfile=.pylintrc container/
61+
62+
[testenv:jshint]
63+
whitelist_externals =
64+
jshint
65+
commands =
66+
jshint container/

0 commit comments

Comments
 (0)