Skip to content

Commit c4fe63c

Browse files
authored
Merge pull request #20 from Yancey1989/fluid_ci
Enable Python linters on CI
2 parents b37df3c + 17c3a68 commit c4fe63c

11 files changed

Lines changed: 109 additions & 27 deletions

File tree

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: pylint
5+
name: pylint
6+
entry: bash ./scripts/pylint.sh
7+
language: system
8+
files: \.py$
9+
verbose: true

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
dist: xenial
2+
cache: pip
3+
branches:
4+
only:
5+
- master
6+
- develop
7+
# https://docs.travis-ci.com/user/customizing-the-build/#safelisting-or-blocklisting-branches
8+
# safe list can prevent tag building, add rexp to detect tag
9+
- "/^v\\d+\\.\\d+(\\.\\d+)?(-\\S*)?$/"
10+
11+
language: python
12+
python:
13+
- 3.6
14+
15+
install:
16+
- pip install -r requirements.txt
17+
- python setup.py bdist_wheel
18+
- pip install dist/*whl
19+
20+
script:
21+
- bash ./scripts/pylint.sh
22+
- pytest .

fluid/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
from fluid.pyfunc import *
1+
# -*- coding: utf-8 -*-
2+
'''This module expose Fluid API for users to write Fluid program
3+
'''
4+
5+
from . import pyfunc
6+
from .pyfunc import * # noqa
7+
from . import version
8+
from .version import __version__ # noqa
9+
10+
__all__ = pyfunc.__all__ + version.__all__

fluid/pyfunc.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
import fluid.tekton as tekton
1414
import fluid.k8s as k8s
1515

16+
__all__ = [
17+
'Secret', 'FluidSyntaxError', 'dump_yaml', 'task', 'step', 'git_resource',
18+
'image_resource', 'service_account'
19+
]
20+
1621

1722
def dump_yaml(content):
1823
'''Pretty print a Python dictionary as a YAML'''
@@ -35,7 +40,9 @@ class FluidSyntaxError(Exception):
3540

3641

3742
def _resources_before_params(func):
38-
'''Check annotated params (resources) are all before non-annoted params'''
43+
'''Check annotated params (resources)
44+
are all before non-annoted params
45+
'''
3946
seen_param = False
4047
argspec = inspect.getfullargspec(func)
4148
for i, arg in enumerate(argspec.args):
@@ -46,7 +53,8 @@ def _resources_before_params(func):
4653
_resource_has_no_default(i, arg, anno, argspec)
4754
_resources_annotation_io_type(arg, anno)
4855
if seen_param:
49-
raise FluidSyntaxError(f"{arg} is annotated and is after a non-annotated param")
56+
raise FluidSyntaxError(f"{arg} is annotated and is \
57+
after a non-annotated param")
5058

5159

5260
def _resource_has_no_default(i, arg, anno, argspec):

fluid/tekton.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def task_params(argspec):
3939
if argspec.annotations.get(arg) is None: # is param
4040
_ps.append(task_param(
4141
arg,
42-
None if i < first_default else argspec.defaults[i-first_default]))
42+
None if i < first_default else argspec.defaults[
43+
i-first_default]))
4344
return _ps
4445

4546

@@ -107,7 +108,7 @@ def task_run(func, args):
107108
"outputs": {
108109
"resources": _or,
109110
}})
110-
global SERVICE_ACCOUNT_NAME
111+
global SERVICE_ACCOUNT_NAME # pylint: disable=global-statement
111112
if SERVICE_ACCOUNT_NAME is not None:
112113
_r["spec"]["serviceAccountName"] = SERVICE_ACCOUNT_NAME
113114
return _r
@@ -161,23 +162,24 @@ def task_run_resource(param, arg):
161162
}}
162163

163164

164-
class FakeGitResource:
165+
class FakeGitResource: # pylint: disable=too-few-public-methods
165166
'''Used in dry-run a Task function, which might call res_param.revision'''
166167

167168
def __init__(self, io, arg):
168169
self.url = f"$({io}s.resources.{k8s.safe_name(arg)}.url)"
169170
self.revision = f"$({io}s.resources.{k8s.safe_name(arg)}.revision)"
170171

171172

172-
class FakeImageResource:
173+
class FakeImageResource: # pylint: disable=too-few-public-methods
173174
'''Used in dry-run a Task function, which might call res_param.url'''
174175

175176
def __init__(self, io, arg):
176177
self.url = f"$({io}s.resources.{k8s.safe_name(arg)}.url)"
177178

178179

179180
def _fake_resource(_io, _typ, arg):
180-
return FakeGitResource(_io, arg) if _typ == "git" else FakeImageResource(_io, arg)
181+
return FakeGitResource(_io, arg) \
182+
if _typ == "git" else FakeImageResource(_io, arg)
181183

182184

183185
STEPS = [] # For holding steps of a Task.
@@ -194,7 +196,7 @@ def task_steps(func):
194196
else:
195197
fake_args.append(f"$(inputs.params.{k8s.safe_name(arg)})")
196198

197-
global STEPS
199+
global STEPS # pylint: disable=global-statement
198200
STEPS = []
199201
func(*fake_args)
200202
return STEPS
@@ -210,12 +212,14 @@ def add_step(name, image, cmd, args, env):
210212
}
211213
if env is not None:
212214
_s["env"] = step_env(env)
213-
global STEPS
215+
global STEPS # pylint: disable=global-statement
214216
STEPS.append(_s)
215217

216218

217219
def step_env(env):
218-
'''For the convenience of Fluid users, env is a dict; Tekton requires a list'''
220+
'''For the convenience of Fluid users, env is a dict;
221+
Tekton requires a list
222+
'''
219223
return [{"name": k, "value": v} for i, (k, v) in enumerate(env.items())]
220224

221225

@@ -229,7 +233,8 @@ def _resource(name, typ, params):
229233
},
230234
"spec": {
231235
"type": typ,
232-
"params": [{"name": k, "value": v} for i, (k, v) in enumerate(params.items())]}}
236+
"params": [{"name": k, "value": v} for i, (k, v) in enumerate(
237+
params.items())]}}
233238

234239

235240
def git_resource(name, url, revision):

fluid/version.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# -*- coding: utf-8 -*-
2+
'''This module version presentents Fluid version
3+
'''
4+
5+
__all__ = ['__version__']
26

37
VERSION = (0, 0, 1, 'dev')
48

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pylint
2+
flake8
3+
pytest

scripts/pylint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
changed_py_files=$(git diff --cached --name-only --diff-filter=ACMR | grep '\.py$')
4+
echo $changed_py_files
5+
if [[ $changed_py_files == "" ]]; then
6+
exit 0
7+
fi
8+
9+
pylint $changed_py_files
10+
flake8 $changed_py_files

setup.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
2+
'''This module packages and distributes Fluid'''
33
import io
44
import os
55

@@ -15,8 +15,8 @@
1515
VERSION = None
1616

1717
# What packages are required for this module to be executed?
18-
SETUP_REQUIRED = ['pytest-runner']
19-
TEST_REQUIRED = [
18+
REQUIRES = ['pyyaml']
19+
TEST_REQUIRED = REQUIRES + [
2020
'pytest',
2121
]
2222

@@ -26,39 +26,40 @@
2626
# The rest you shouldn't have to touch too much :)
2727
# ------------------------------------------------
2828
# Except, perhaps the License and Trove Classifiers!
29-
# If you do change the License, remember to change the Trove Classifier for that!
29+
# If you do change the License, remember to change the Trove Classifier
30+
# for that!
3031

31-
here = os.path.abspath(os.path.dirname(__file__))
32+
HERE = os.path.abspath(os.path.dirname(__file__))
3233

3334
# Import the README and use it as the long-description.
3435
# Note: this will only work if 'README.md' is present in your MANIFEST.in file!
3536
try:
36-
with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
37-
long_description = '\n' + f.read()
37+
with io.open(os.path.join(HERE, 'README.md'), encoding='utf-8') as f:
38+
LONG_DESCRIPTION = '\n' + f.read()
3839
except FileNotFoundError:
39-
long_description = DESCRIPTION
40+
LONG_DESCRIPTION = DESCRIPTION
4041

4142
# Load the package's version.py module as a dictionary.
42-
about = {}
43+
ABOUT = {}
4344
if not VERSION:
44-
with open(os.path.join(here, NAME, 'version.py')) as f:
45-
exec(f.read(), about)
45+
with open(os.path.join(HERE, NAME, 'version.py')) as f:
46+
exec(f.read(), ABOUT) # pylint: disable=exec-used
4647
else:
47-
about['__version__'] = VERSION
48+
ABOUT['__version__'] = VERSION
4849

4950
# Where the magic happens:
5051
setup(
5152
name=NAME,
52-
version=about['__version__'],
53+
version=ABOUT['__version__'],
5354
description=DESCRIPTION,
54-
long_description=long_description,
55+
long_description=LONG_DESCRIPTION,
5556
long_description_content_type='text/markdown',
5657
author=AUTHOR,
5758
author_email=EMAIL,
5859
python_requires=REQUIRES_PYTHON,
5960
url=URL,
6061
packages=find_packages(exclude=('tests', )),
61-
setup_requires=SETUP_REQUIRED,
62+
install_requires=REQUIRES,
6263
tests_require=TEST_REQUIRED,
6364
extras_require=EXTRAS,
6465
license='Apache License 2.0',

tests/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# -*- coding: utf-8 -*-
2+
'''This module includes Fluid unit test cases'''

0 commit comments

Comments
 (0)