Skip to content

Commit 268a0fc

Browse files
authored
ban print (deepmodeling#3415)
Signed-off-by: Jinzhe Zeng <[email protected]>
1 parent 697fde9 commit 268a0fc

20 files changed

+16
-149
lines changed

data/raw/copy_raw.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _main():
8585
)
8686
args = parser.parse_args()
8787

88-
print("# copy the system by %s copies" % args.ncopies)
88+
print("# copy the system by %s copies" % args.ncopies) # noqa: T201
8989
assert np.all(
9090
np.array(args.ncopies, dtype=int) >= np.array([1, 1, 1], dtype=int)
9191
), "number of copies should be larger than or equal to 1"

data/raw/shuffle_raw.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _main():
3737
outpath = args.OUTPUT
3838

3939
if not os.path.isdir(inpath):
40-
print("# no input dir " + inpath + ", exit")
40+
print("# no input dir " + inpath + ", exit") # noqa: T201
4141
return
4242

4343
if not os.path.isdir(outpath):
@@ -47,16 +47,16 @@ def _main():
4747
raws = detect_raw(inpath)
4848

4949
if len(raws) == 0:
50-
print("# no file to shuffle, exit")
50+
print("# no file to shuffle, exit") # noqa: T201
5151
return
5252

5353
assert "box.raw" in raws
5454
tmp = np.loadtxt(os.path.join(inpath, "box.raw"))
5555
tmp = np.reshape(tmp, [-1, 9])
5656
nframe = tmp.shape[0]
57-
print(nframe)
57+
print(nframe) # noqa: T201
5858

59-
print(
59+
print( # noqa: T201
6060
"# will shuffle raw files "
6161
+ str(raws)
6262
+ " in dir "

deepmd/entrypoints/doc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ def doc_train_input(*, out_type: str = "rst", **kwargs):
1717
doc_str = gen_json()
1818
else:
1919
raise RuntimeError("Unsupported out type %s" % out_type)
20-
print(doc_str)
20+
print(doc_str) # noqa: T201

doc/sphinx_contrib_exhale_multiproject.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ def exhale_environment_ready(app):
103103
app.config.exhale_args["containmentFolder"] = os.path.realpath(
104104
app.config.exhale_args["containmentFolder"]
105105
)
106-
print("=" * 75)
107-
print(project)
108-
print("-" * 50)
109-
pprint(app.config.exhale_args)
110-
print("=" * 75)
106+
print("=" * 75) # noqa: T201
107+
print(project) # noqa: T201
108+
print("-" * 50) # noqa: T201
109+
pprint(app.config.exhale_args) # noqa: T203
110+
print("=" * 75) # noqa: T201
111111

112112
# First, setup the extension and verify all of the configurations.
113113
exhale.configs.apply_sphinx_configurations(app)

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ select = [
238238
"NPY", # numpy
239239
"TID251", # banned-api
240240
"TID253", # banned-module-level-imports
241+
"T20", # ban print
241242
]
242243

243244
ignore = [
@@ -283,6 +284,7 @@ banned-module-level-imports = [
283284
"source/tests/pt/**" = ["TID253"]
284285
"source/ipi/tests/**" = ["TID253"]
285286
"source/lmp/tests/**" = ["TID253"]
287+
"**/*.ipynb" = ["T20"] # printing in a nb file is expected
286288

287289
[tool.pytest.ini_options]
288290
markers = "run"

source/tests/pt/model/test_unused_params.py

-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ def get_contributing_params(y, top_level=True):
8787
contributing_parameters = set(get_contributing_params(ret0["energy"]))
8888
all_parameters = set(self.model.parameters())
8989
non_contributing = all_parameters - contributing_parameters
90-
for ii in non_contributing:
91-
print(ii.shape)
9290
self.assertEqual(len(non_contributing), 0)
9391

9492

source/tests/pt/test_dp_test.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ def test_dp_test(self):
4949
try:
5050
res = tester.run()
5151
except StopIteration:
52-
print("Unexpected stop iteration.(test step < total batch)")
53-
raise StopIteration
52+
raise StopIteration("Unexpected stop iteration.(test step < total batch)")
5453
for k, v in res.items():
5554
if k == "rmse" or "mae" in k or k not in more_loss:
5655
continue

source/tests/tf/common.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import pathlib
66
import shutil
7+
import warnings
78

89
import dpdata
910
import numpy as np
@@ -969,7 +970,7 @@ def __init__(self, systems, set_prefix, batch_size, test_size, rcut, run_opt=Non
969970
)
970971
chk_ret = self.data_systems[ii].check_test_size(test_size)
971972
if chk_ret is not None:
972-
print(
973+
warnings.warn(
973974
"WARNNING: system %s required test size %d is larger than the size %d of the dataset %s"
974975
% (self.system_dirs[ii], test_size, chk_ret[1], chk_ret[0])
975976
)

source/tests/tf/test_adjust_sel.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
import json
33
import os
4-
import subprocess as sp
54
import unittest
65

76
import numpy as np
@@ -33,17 +32,6 @@ def _file_delete(file):
3332
os.remove(file)
3433

3534

36-
def _subprocess_run(command):
37-
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
38-
for line in iter(popen.stdout.readline, b""):
39-
if hasattr(line, "decode"):
40-
line = line.decode("utf-8")
41-
line = line.rstrip()
42-
print(line)
43-
popen.wait()
44-
return popen.returncode
45-
46-
4735
def _init_models():
4836
# we use the setting for model compression
4937
data_file = str(tests_path / os.path.join("model_compression", "data"))

source/tests/tf/test_finetune_se_atten.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
import json
33
import os
4-
import subprocess as sp
54
import unittest
65

76
import numpy as np
@@ -46,17 +45,6 @@ def _file_delete(file):
4645
os.remove(file)
4746

4847

49-
def _subprocess_run(command):
50-
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
51-
for line in iter(popen.stdout.readline, b""):
52-
if hasattr(line, "decode"):
53-
line = line.decode("utf-8")
54-
line = line.rstrip()
55-
print(line)
56-
popen.wait()
57-
return popen.returncode
58-
59-
6048
def _init_models(setup_model, i):
6149
data_file = str(tests_path / os.path.join("finetune", "data"))
6250
data_file_mixed_type = str(tests_path / os.path.join("finetune", "data_mixed_type"))

source/tests/tf/test_mixed_prec_training.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
import json
33
import os
4-
import subprocess as sp
54
import unittest
65

76
import numpy as np
@@ -28,17 +27,6 @@ def _file_delete(file):
2827
os.remove(file)
2928

3029

31-
def _subprocess_run(command):
32-
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
33-
for line in iter(popen.stdout.readline, b""):
34-
if hasattr(line, "decode"):
35-
line = line.decode("utf-8")
36-
line = line.rstrip()
37-
print(line)
38-
popen.wait()
39-
return popen.returncode
40-
41-
4230
class TestMixedPrecTraining(unittest.TestCase):
4331
def setUp(self):
4432
data_file = str(tests_path / os.path.join("model_compression", "data"))

source/tests/tf/test_model_compression_se_a.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
import json
33
import os
4-
import subprocess as sp
54
import unittest
65

76
import numpy as np
@@ -33,17 +32,6 @@ def _file_delete(file):
3332
os.remove(file)
3433

3534

36-
def _subprocess_run(command):
37-
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
38-
for line in iter(popen.stdout.readline, b""):
39-
if hasattr(line, "decode"):
40-
line = line.decode("utf-8")
41-
line = line.rstrip()
42-
print(line)
43-
popen.wait()
44-
return popen.returncode
45-
46-
4735
def _init_models():
4836
data_file = str(tests_path / os.path.join("model_compression", "data"))
4937
frozen_model = str(tests_path / "dp-original.pb")

source/tests/tf/test_model_compression_se_a_ebd.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
import json
33
import os
4-
import subprocess as sp
54
import unittest
65

76
import numpy as np
@@ -33,17 +32,6 @@ def _file_delete(file):
3332
os.remove(file)
3433

3534

36-
def _subprocess_run(command):
37-
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
38-
for line in iter(popen.stdout.readline, b""):
39-
if hasattr(line, "decode"):
40-
line = line.decode("utf-8")
41-
line = line.rstrip()
42-
print(line)
43-
popen.wait()
44-
return popen.returncode
45-
46-
4735
def _init_models():
4836
data_file = str(tests_path / os.path.join("model_compression", "data"))
4937
frozen_model = str(tests_path / "dp-original-se-e2-a-v2.pb")

source/tests/tf/test_model_compression_se_a_ebd_type_one_side.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
import json
33
import os
4-
import subprocess as sp
54
import unittest
65

76
import numpy as np
@@ -33,17 +32,6 @@ def _file_delete(file):
3332
os.remove(file)
3433

3534

36-
def _subprocess_run(command):
37-
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
38-
for line in iter(popen.stdout.readline, b""):
39-
if hasattr(line, "decode"):
40-
line = line.decode("utf-8")
41-
line = line.rstrip()
42-
print(line)
43-
popen.wait()
44-
return popen.returncode
45-
46-
4735
def _init_models():
4836
data_file = str(tests_path / os.path.join("model_compression", "data"))
4937
frozen_model = str(tests_path / "dp-original-se-e2-a-v2-one-side.pb")

source/tests/tf/test_model_compression_se_a_type_one_side_exclude_types.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
import json
33
import os
4-
import subprocess as sp
54
import unittest
65

76
import numpy as np
@@ -33,17 +32,6 @@ def _file_delete(file):
3332
os.remove(file)
3433

3534

36-
def _subprocess_run(command):
37-
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
38-
for line in iter(popen.stdout.readline, b""):
39-
if hasattr(line, "decode"):
40-
line = line.decode("utf-8")
41-
line = line.rstrip()
42-
print(line)
43-
popen.wait()
44-
return popen.returncode
45-
46-
4735
def _init_models():
4836
data_file = str(tests_path / os.path.join("model_compression", "data"))
4937
frozen_model = str(tests_path / "dp-original-type-one-side-exclude-types.pb")

source/tests/tf/test_model_compression_se_atten.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
import json
33
import os
4-
import subprocess as sp
54
import unittest
65

76
import numpy as np
@@ -29,17 +28,6 @@ def _file_delete(file):
2928
os.remove(file)
3029

3130

32-
def _subprocess_run(command):
33-
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
34-
for line in iter(popen.stdout.readline, b""):
35-
if hasattr(line, "decode"):
36-
line = line.decode("utf-8")
37-
line = line.rstrip()
38-
print(line)
39-
popen.wait()
40-
return popen.returncode
41-
42-
4331
# 4 tests:
4432
# - type embedding FP64, se_atten FP64
4533
# - type embedding FP64, se_atten FP32

source/tests/tf/test_model_compression_se_r.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
import json
33
import os
4-
import subprocess as sp
54
import unittest
65

76
import numpy as np
@@ -33,17 +32,6 @@ def _file_delete(file):
3332
os.remove(file)
3433

3534

36-
def _subprocess_run(command):
37-
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
38-
for line in iter(popen.stdout.readline, b""):
39-
if hasattr(line, "decode"):
40-
line = line.decode("utf-8")
41-
line = line.rstrip()
42-
print(line)
43-
popen.wait()
44-
return popen.returncode
45-
46-
4735
def _init_models():
4836
data_file = str(tests_path / os.path.join("model_compression", "data"))
4937
frozen_model = str(tests_path / "dp-original-se-r.pb")

source/tests/tf/test_model_compression_se_t.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
import json
33
import os
4-
import subprocess as sp
54
import unittest
65

76
import numpy as np
@@ -33,17 +32,6 @@ def _file_delete(file):
3332
os.remove(file)
3433

3534

36-
def _subprocess_run(command):
37-
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
38-
for line in iter(popen.stdout.readline, b""):
39-
if hasattr(line, "decode"):
40-
line = line.decode("utf-8")
41-
line = line.rstrip()
42-
print(line)
43-
popen.wait()
44-
return popen.returncode
45-
46-
4735
def _init_models():
4836
data_file = str(tests_path / os.path.join("model_compression", "data"))
4937
frozen_model = str(tests_path / "dp-original-se-t.pb")

source/tests/tf/test_parallel_training.py

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def test_two_workers(self):
4444
if hasattr(line, "decode"):
4545
line = line.decode("utf-8")
4646
line = line.rstrip()
47-
print(line)
4847
popen.wait()
4948
self.assertEqual(0, popen.returncode, "Parallel training failed!")
5049

0 commit comments

Comments
 (0)