Skip to content

Commit

Permalink
ban print (#3415)
Browse files Browse the repository at this point in the history
Signed-off-by: Jinzhe Zeng <[email protected]>
(cherry picked from commit 268a0fc)
Signed-off-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
njzjz committed Apr 6, 2024
1 parent 308d9f2 commit 99a2d44
Show file tree
Hide file tree
Showing 18 changed files with 17 additions and 145 deletions.
2 changes: 1 addition & 1 deletion data/raw/copy_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _main():
)
args = parser.parse_args()

print("# copy the system by %s copies" % args.ncopies)
print("# copy the system by %s copies" % args.ncopies) # noqa: T201
assert np.all(
np.array(args.ncopies, dtype=int) >= np.array([1, 1, 1], dtype=int)
), "number of copies should be larger than or equal to 1"
Expand Down
8 changes: 4 additions & 4 deletions data/raw/shuffle_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _main():
outpath = args.OUTPUT

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

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

if len(raws) == 0:
print("# no file to shuffle, exit")
print("# no file to shuffle, exit") # noqa: T201
return

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

print(
print( # noqa: T201
"# will shuffle raw files "
+ str(raws)
+ " in dir "
Expand Down
2 changes: 1 addition & 1 deletion deepmd_utils/entrypoints/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ def doc_train_input(*, out_type: str = "rst", **kwargs):
doc_str = gen_json()
else:
raise RuntimeError("Unsupported out type %s" % out_type)
print(doc_str)
print(doc_str) # noqa: T201
10 changes: 5 additions & 5 deletions doc/sphinx_contrib_exhale_multiproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ def exhale_environment_ready(app):
app.config.exhale_args["containmentFolder"] = os.path.realpath(
app.config.exhale_args["containmentFolder"]
)
print("=" * 75)
print(project)
print("-" * 50)
pprint(app.config.exhale_args)
print("=" * 75)
print("=" * 75) # noqa: T201
print(project) # noqa: T201
print("-" * 50) # noqa: T201
pprint(app.config.exhale_args) # noqa: T203
print("=" * 75) # noqa: T201

# First, setup the extension and verify all of the configurations.
exhale.configs.apply_sphinx_configurations(app)
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ select = [
"C4", # flake8-comprehensions
"RUF", # ruff
"NPY", # numpy
"T20", # ban print
]

ignore = [
Expand All @@ -252,5 +253,8 @@ ignore-init-module-imports = true
[tool.ruff.lint.pydocstyle]
convention = "numpy"

[tool.ruff.lint.extend-per-file-ignores]
"**/*.ipynb" = ["T20"] # printing in a nb file is expected

[tool.pytest.ini_options]
markers = "run"
3 changes: 2 additions & 1 deletion source/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import pathlib
import shutil
import warnings

import dpdata
import numpy as np
Expand Down Expand Up @@ -965,7 +966,7 @@ def __init__(self, systems, set_prefix, batch_size, test_size, rcut, run_opt=Non
)
chk_ret = self.data_systems[ii].check_test_size(test_size)
if chk_ret is not None:
print(
warnings.warn(
"WARNNING: system %s required test size %d is larger than the size %d of the dataset %s"
% (self.system_dirs[ii], test_size, chk_ret[1], chk_ret[0])
)
Expand Down
12 changes: 0 additions & 12 deletions source/tests/test_adjust_sel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import json
import os
import subprocess as sp
import unittest

import numpy as np
Expand Down Expand Up @@ -33,17 +32,6 @@ def _file_delete(file):
os.remove(file)


def _subprocess_run(command):
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
for line in iter(popen.stdout.readline, b""):
if hasattr(line, "decode"):
line = line.decode("utf-8")
line = line.rstrip()
print(line)
popen.wait()
return popen.returncode


def _init_models():
# we use the setting for model compression
data_file = str(tests_path / os.path.join("model_compression", "data"))
Expand Down
12 changes: 0 additions & 12 deletions source/tests/test_finetune_se_atten.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import json
import os
import subprocess as sp
import unittest

import numpy as np
Expand Down Expand Up @@ -45,17 +44,6 @@ def _file_delete(file):
os.remove(file)


def _subprocess_run(command):
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
for line in iter(popen.stdout.readline, b""):
if hasattr(line, "decode"):
line = line.decode("utf-8")
line = line.rstrip()
print(line)
popen.wait()
return popen.returncode


def _init_models(setup_model, i):
data_file = str(tests_path / os.path.join("finetune", "data"))
data_file_mixed_type = str(tests_path / os.path.join("finetune", "data_mixed_type"))
Expand Down
12 changes: 0 additions & 12 deletions source/tests/test_mixed_prec_training.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import json
import os
import subprocess as sp
import unittest

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


def _subprocess_run(command):
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
for line in iter(popen.stdout.readline, b""):
if hasattr(line, "decode"):
line = line.decode("utf-8")
line = line.rstrip()
print(line)
popen.wait()
return popen.returncode


class TestMixedPrecTraining(unittest.TestCase):
def setUp(self):
data_file = str(tests_path / os.path.join("model_compression", "data"))
Expand Down
12 changes: 0 additions & 12 deletions source/tests/test_model_compression_se_a.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import json
import os
import subprocess as sp
import unittest

import numpy as np
Expand Down Expand Up @@ -33,17 +32,6 @@ def _file_delete(file):
os.remove(file)


def _subprocess_run(command):
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
for line in iter(popen.stdout.readline, b""):
if hasattr(line, "decode"):
line = line.decode("utf-8")
line = line.rstrip()
print(line)
popen.wait()
return popen.returncode


def _init_models():
data_file = str(tests_path / os.path.join("model_compression", "data"))
frozen_model = str(tests_path / "dp-original.pb")
Expand Down
12 changes: 0 additions & 12 deletions source/tests/test_model_compression_se_a_ebd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import json
import os
import subprocess as sp
import unittest

import numpy as np
Expand Down Expand Up @@ -33,17 +32,6 @@ def _file_delete(file):
os.remove(file)


def _subprocess_run(command):
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
for line in iter(popen.stdout.readline, b""):
if hasattr(line, "decode"):
line = line.decode("utf-8")
line = line.rstrip()
print(line)
popen.wait()
return popen.returncode


def _init_models():
data_file = str(tests_path / os.path.join("model_compression", "data"))
frozen_model = str(tests_path / "dp-original-se-e2-a-v2.pb")
Expand Down
12 changes: 0 additions & 12 deletions source/tests/test_model_compression_se_a_ebd_type_one_side.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import json
import os
import subprocess as sp
import unittest

import numpy as np
Expand Down Expand Up @@ -33,17 +32,6 @@ def _file_delete(file):
os.remove(file)


def _subprocess_run(command):
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
for line in iter(popen.stdout.readline, b""):
if hasattr(line, "decode"):
line = line.decode("utf-8")
line = line.rstrip()
print(line)
popen.wait()
return popen.returncode


def _init_models():
data_file = str(tests_path / os.path.join("model_compression", "data"))
frozen_model = str(tests_path / "dp-original-se-e2-a-v2-one-side.pb")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import json
import os
import subprocess as sp
import unittest

import numpy as np
Expand Down Expand Up @@ -33,17 +32,6 @@ def _file_delete(file):
os.remove(file)


def _subprocess_run(command):
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
for line in iter(popen.stdout.readline, b""):
if hasattr(line, "decode"):
line = line.decode("utf-8")
line = line.rstrip()
print(line)
popen.wait()
return popen.returncode


def _init_models():
data_file = str(tests_path / os.path.join("model_compression", "data"))
frozen_model = str(tests_path / "dp-original-type-one-side-exclude-types.pb")
Expand Down
12 changes: 0 additions & 12 deletions source/tests/test_model_compression_se_atten.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import json
import os
import subprocess as sp
import unittest

import numpy as np
Expand Down Expand Up @@ -29,17 +28,6 @@ def _file_delete(file):
os.remove(file)


def _subprocess_run(command):
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
for line in iter(popen.stdout.readline, b""):
if hasattr(line, "decode"):
line = line.decode("utf-8")
line = line.rstrip()
print(line)
popen.wait()
return popen.returncode


# 4 tests:
# - type embedding FP64, se_atten FP64
# - type embedding FP64, se_atten FP32
Expand Down
12 changes: 0 additions & 12 deletions source/tests/test_model_compression_se_r.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import json
import os
import subprocess as sp
import unittest

import numpy as np
Expand Down Expand Up @@ -33,17 +32,6 @@ def _file_delete(file):
os.remove(file)


def _subprocess_run(command):
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
for line in iter(popen.stdout.readline, b""):
if hasattr(line, "decode"):
line = line.decode("utf-8")
line = line.rstrip()
print(line)
popen.wait()
return popen.returncode


def _init_models():
data_file = str(tests_path / os.path.join("model_compression", "data"))
frozen_model = str(tests_path / "dp-original-se-r.pb")
Expand Down
12 changes: 0 additions & 12 deletions source/tests/test_model_compression_se_t.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import json
import os
import subprocess as sp
import unittest

import numpy as np
Expand Down Expand Up @@ -33,17 +32,6 @@ def _file_delete(file):
os.remove(file)


def _subprocess_run(command):
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
for line in iter(popen.stdout.readline, b""):
if hasattr(line, "decode"):
line = line.decode("utf-8")
line = line.rstrip()
print(line)
popen.wait()
return popen.returncode


def _init_models():
data_file = str(tests_path / os.path.join("model_compression", "data"))
frozen_model = str(tests_path / "dp-original-se-t.pb")
Expand Down
1 change: 0 additions & 1 deletion source/tests/test_parallel_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def test_two_workers(self):
if hasattr(line, "decode"):
line = line.decode("utf-8")
line = line.rstrip()
print(line)
popen.wait()
self.assertEqual(0, popen.returncode, "Parallel training failed!")

Expand Down
12 changes: 0 additions & 12 deletions source/tests/test_transfer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import os
import subprocess as sp
import unittest

import numpy as np
Expand Down Expand Up @@ -30,17 +29,6 @@ def _file_delete(file):
os.remove(file)


def _subprocess_run(command):
popen = sp.Popen(command.split(), shell=False, stdout=sp.PIPE, stderr=sp.STDOUT)
for line in iter(popen.stdout.readline, b""):
if hasattr(line, "decode"):
line = line.decode("utf-8")
line = line.rstrip()
print(line)
popen.wait()
return popen.returncode


class TestTransform(unittest.TestCase):
@classmethod
def setUpClass(self):
Expand Down

0 comments on commit 99a2d44

Please sign in to comment.