Skip to content

Commit 8112a1f

Browse files
authored
refine codes by flake8 (#2766)
1 parent 1762656 commit 8112a1f

9 files changed

Lines changed: 82 additions & 77 deletions

File tree

python/couler/couler/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
from ._version import __version__
14+
from ._version import __version__ # noqa: F401

python/couler/couler/argo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import atexit
1515
import copy
1616
import types
17+
import uuid
1718
from collections import OrderedDict
1819

1920
import couler.pyfunc as pyfunc

python/couler/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
# The rest you shouldn't have to touch too much :)
4444
# ------------------------------------------------
4545
# Except, perhaps the License and Trove Classifiers!
46-
# If you do change the License, remember to change the Trove Classifier for that!
46+
# If you do change the License, remember to change
47+
# the Trove Classifier for that!
4748

4849
here = os.path.abspath(os.path.dirname(__file__))
4950

python/plotille_text_backend.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
import io
1515

1616
from matplotlib._pylab_helpers import Gcf
17-
from matplotlib.backend_bases import (FigureCanvasBase, FigureManagerBase,
18-
RendererBase, _Backend)
17+
from matplotlib.backend_bases import FigureManagerBase
1918
from matplotlib.backends.backend_agg import FigureCanvasAgg, RendererAgg
2019
from PIL import Image
2120
from plotille import Canvas
@@ -89,7 +88,8 @@ def to_txt(self):
8988
if center == (255, 255, 255):
9089
continue
9190
if x in range(1, w - 1) and y in range(1, h - 1):
92-
# Use the most deepest color in a 3x3 area as the center color
91+
# Use the most deepest color in a 3x3 area as
92+
# the center color
9393
surrounding = i.getpixel((x, y - 1)) # upper
9494
center = surrounding if grayscale(center) > grayscale(
9595
surrounding) else center
@@ -140,7 +140,8 @@ def set_text(canvas, x, y, text):
140140
color_map = {}
141141

142142

143-
# Convert RGB to grayscale, see https://www.tutorialspoint.com/dip/grayscale_to_rgb_conversion.htm
143+
# Convert RGB to grayscale, see
144+
# https://www.tutorialspoint.com/dip/grayscale_to_rgb_conversion.htm
144145
def grayscale(rgb):
145146
return 0.3 * rgb[0] + 0.59 * rgb[1] + 0.11 * rgb[2]
146147

python/sql_data.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# limitations under the License.
1313

1414
import tensorflow as tf
15-
from MySQLdb import connect
15+
from MySQLdb import connect as mysql_connect
1616

1717

1818
def connect(user, passwd, host, port):
@@ -23,10 +23,11 @@ def connect(user, passwd, host, port):
2323
user: Specifies the MySQL user name.
2424
passwd : Specify the MySQL password.
2525
host : The host name or IP address.
26-
port : Specifies the port number that attempts to connect to the MySQL server.
26+
port : Specifies the port number that attempts to connect
27+
to the MySQL server.
2728
2829
"""
29-
return connect(user=user, passwd=passwd, host=host, port=port)
30+
return mysql_connect(user=user, passwd=passwd, host=host, port=port)
3031

3132

3233
def load(db, slct, label, features):
@@ -49,10 +50,10 @@ def load(db, slct, label, features):
4950
f = [i[0] for i in cursor.description] # get field names.
5051
c = list(zip(*cursor.fetchall())) # transpose rows into columns.
5152
d = dict(zip(f, c)) # dict from field names to columns.
52-
l = d.pop(label)
53-
if features != None:
53+
label = d.pop(label)
54+
if features is not None:
5455
d = dict((k, d[k]) for k in features)
55-
return d, l
56+
return d, label
5657

5758

5859
def feature_columns(features):

python/test_magic.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
import sys
1514
import unittest
16-
from io import StringIO
1715

1816
from IPython import get_ipython
1917

@@ -23,16 +21,16 @@
2321
class TestSQLFlowMagic(unittest.TestCase):
2422
import random
2523
random.seed()
26-
temp_database = "e2e_{}".format(random.randint(0, 1 << 32))
24+
tmp_db = "e2e_{}".format(random.randint(0, 1 << 32))
2725
# the standard SQL statement
2826
create_database_statement = "create database if not exists {}".format(
29-
temp_database)
30-
create_statement = "create table {}.test_table_float_fea (features float, label int)".format(
31-
temp_database)
32-
insert_statement = "insert into {}.test_table_float_fea (features,label) values(1.0, 0), (2.0, 1)".format(
33-
temp_database)
27+
tmp_db)
28+
create_statement = "create table {}.test_table_float_fea " \
29+
"(features float, label int)".format(tmp_db)
30+
insert_statement = "insert into {}.test_table_float_fea (features,label)" \
31+
" values(1.0, 0), (2.0, 1)".format(tmp_db)
3432
select_statement = "select * from {}.test_table_float_fea limit 1;".format(
35-
temp_database)
33+
tmp_db)
3634

3735
def setUp(self):
3836
ipython.run_cell_magic("sqlflow", "", self.create_database_statement)

python/test_magic_elasticdl.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
import sys
1514
import unittest
16-
from io import StringIO
1715

1816
from IPython import get_ipython
1917

@@ -22,39 +20,41 @@
2220

2321
class TestSQLFlowMagic(unittest.TestCase):
2422
train_statement = """SELECT * FROM iris.train
25-
TO TRAIN ElasticDLKerasClassifier
26-
WITH
27-
model.num_classes = 10,
28-
train.shuffle = 120,
29-
train.epoch = 2,
30-
train.grads_to_wait = 2,
31-
train.tensorboard_log_dir = "",
32-
train.checkpoint_steps = 0,
33-
train.checkpoint_dir = "",
34-
train.keep_checkpoint_max = 0,
35-
eval.steps = 0,
36-
eval.start_delay_secs = 100,
37-
eval.throttle_secs = 0,
38-
eval.checkpoint_filename_for_init = "",
39-
engine.docker_image_prefix = "",
40-
engine.master_resource_request = "cpu=1,memory=4096Mi,ephemeral-storage=10240Mi",
41-
engine.worker_resource_request = "cpu=1,memory=4096Mi,ephemeral-storage=10240Mi",
42-
engine.minibatch_size = 10,
43-
engine.num_workers = 2,
44-
engine.volume = "",
45-
engine.image_pull_policy = "Always",
46-
engine.restart_policy = "Never",
47-
engine.extra_pypi_index = "",
48-
engine.namespace = "default",
49-
engine.master_pod_priority = "",
50-
engine.cluster_spec = "",
51-
engine.num_minibatches_per_task = 10,
52-
engine.docker_image_repository = "",
53-
engine.envs = ""
54-
COLUMN
55-
sepal_length, sepal_width, petal_length, petal_width
56-
LABEL class
57-
INTO trained_elasticdl_keras_classifier;
23+
TO TRAIN ElasticDLKerasClassifier
24+
WITH
25+
model.num_classes = 10,
26+
train.shuffle = 120,
27+
train.epoch = 2,
28+
train.grads_to_wait = 2,
29+
train.tensorboard_log_dir = "",
30+
train.checkpoint_steps = 0,
31+
train.checkpoint_dir = "",
32+
train.keep_checkpoint_max = 0,
33+
eval.steps = 0,
34+
eval.start_delay_secs = 100,
35+
eval.throttle_secs = 0,
36+
eval.checkpoint_filename_for_init = "",
37+
engine.docker_image_prefix = "",
38+
engine.master_resource_request =
39+
"cpu=1,memory=4096Mi,ephemeral-storage=10240Mi",
40+
engine.worker_resource_request =
41+
"cpu=1,memory=4096Mi,ephemeral-storage=10240Mi",
42+
engine.minibatch_size = 10,
43+
engine.num_workers = 2,
44+
engine.volume = "",
45+
engine.image_pull_policy = "Always",
46+
engine.restart_policy = "Never",
47+
engine.extra_pypi_index = "",
48+
engine.namespace = "default",
49+
engine.master_pod_priority = "",
50+
engine.cluster_spec = "",
51+
engine.num_minibatches_per_task = 10,
52+
engine.docker_image_repository = "",
53+
engine.envs = ""
54+
COLUMN
55+
sepal_length, sepal_width, petal_length, petal_width
56+
LABEL class
57+
INTO trained_elasticdl_keras_classifier;
5858
"""
5959

6060
def test_elasticdl(self):

python/test_sql_data.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,35 @@
1313

1414
import unittest
1515

16+
import runtime.testing as testing
1617
import sql_data
17-
from runtime.db_test import testing_mysql_cfg
18+
from runtime.db import parseMySQLDSN
1819

1920

2021
class TestSQLData(unittest.TestCase):
2122
def __init__(self, *args, **kwargs):
2223
super(TestSQLData, self).__init__(*args, **kwargs)
23-
user, password, host, port, database = testing_mysql_cfg()
24-
self.db = sql_data.connect(user, password, host, int(port))
24+
dsn = testing.get_mysql_dsn()
25+
user, passwd, host, port, _, _ = parseMySQLDSN(dsn)
26+
self.db = sql_data.connect(user, passwd, host, int(port))
2527
self.assertIsNotNone(self.db)
2628

2729
def test_load(self):
28-
f, l = sql_data.load(self.db, 'SELECT * FROM iris.train LIMIT 3',
29-
'class', None)
30+
f, label = sql_data.load(self.db, 'SELECT * FROM iris.train LIMIT 3',
31+
'class', None)
3032
self.assertEqual(4, len(f.keys())) # 4 features
31-
self.assertEqual(3, len(l)) # label column length
33+
self.assertEqual(3, len(label)) # label column length
3234

3335
def test_load_with_filter(self):
3436
fs = ['sepal_length', 'petal_width']
35-
f, l = sql_data.load(self.db, 'SELECT * FROM iris.train LIMIT 3',
36-
'class', fs)
37+
f, label = sql_data.load(self.db, 'SELECT * FROM iris.train LIMIT 3',
38+
'class', fs)
3739
self.assertEqual(len(fs), len(f))
38-
self.assertEqual(3, len(l)) # label column length
40+
self.assertEqual(3, len(label)) # label column length
3941

4042
def test_feature_columns(self):
41-
f, l = sql_data.load(self.db, 'SELECT * FROM iris.train LIMIT 3',
42-
'class', None)
43+
f, label = sql_data.load(self.db, 'SELECT * FROM iris.train LIMIT 3',
44+
'class', None)
4345
c = sql_data.feature_columns(f)
4446
self.assertEqual(4, len(c)) # 4 features
4547

scripts/pre-commit/copyright.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313

1414
import argparse
1515
import io
16-
import os
17-
import platform
1816
import re
1917
import subprocess
20-
import sys
2118

2219
COPYRIGHT = '''
2320
Copyright 2020 The SQLFlow Authors. All rights reserved.
@@ -42,7 +39,7 @@
4239

4340
NEW_LINE_MARK = '\n'
4441
COPYRIGHT_HEADER = COPYRIGHT.split(NEW_LINE_MARK)[1]
45-
p = re.search('(\d{4})', COPYRIGHT_HEADER).group(0)
42+
p = re.search('(\d{4})', COPYRIGHT_HEADER).group(0) # noqa: W605
4643
process = subprocess.Popen(["date", "+%Y"], stdout=subprocess.PIPE)
4744
date, err = process.communicate()
4845
date = date.decode("utf-8").rstrip("\n")
@@ -59,7 +56,8 @@ def generate_copyright(template, lang='go'):
5956
BLANK = " "
6057
ans = LANG_COMMENT_MARK + BLANK + COPYRIGHT_HEADER + NEW_LINE_MARK
6158
for lino, line in enumerate(lines):
62-
if lino == 0 or lino == 1 or lino == len(lines) - 1: continue
59+
if lino == 0 or lino == 1 or lino == len(lines) - 1:
60+
continue
6361
if len(line) == 0:
6462
BLANK = ""
6563
else:
@@ -99,16 +97,19 @@ def main(argv=None):
9997
second_line = fd.readline()
10098
third_line = fd.readline()
10199
# check for 3 head lines
102-
if "COPYRIGHT " in first_line.upper(): continue
103-
if "COPYRIGHT " in second_line.upper(): continue
104-
if "COPYRIGHT " in third_line.upper(): continue
100+
if "COPYRIGHT " in first_line.upper():
101+
continue
102+
if "COPYRIGHT " in second_line.upper():
103+
continue
104+
if "COPYRIGHT " in third_line.upper():
105+
continue
105106
skip_one = False
106107
skip_two = False
107108
if first_line.startswith("#!"):
108109
skip_one = True
109-
if PYTHON_ENCODE.match(second_line) != None:
110+
if PYTHON_ENCODE.match(second_line) is not None:
110111
skip_two = True
111-
if PYTHON_ENCODE.match(first_line) != None:
112+
if PYTHON_ENCODE.match(first_line) is not None:
112113
skip_one = True
113114

114115
original_content_lines = io.open(filename,

0 commit comments

Comments
 (0)