From 0eede701d74dea79c3857942ed0c02a0a25f983d Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sat, 6 Apr 2024 02:22:10 -0400 Subject: [PATCH] ban print (#3415) Signed-off-by: Jinzhe Zeng (cherry picked from commit 268a0fcd561906df6699b566c299ea67db392410) Signed-off-by: Jinzhe Zeng --- data/raw/copy_raw.py | 2 +- data/raw/shuffle_raw.py | 8 ++++---- deepmd_utils/entrypoints/doc.py | 2 +- doc/sphinx_contrib_exhale_multiproject.py | 10 +++++----- pyproject.toml | 4 ++++ source/tests/common.py | 3 ++- source/tests/test_adjust_sel.py | 12 ------------ source/tests/test_finetune_se_atten.py | 12 ------------ source/tests/test_mixed_prec_training.py | 12 ------------ source/tests/test_model_compression_se_a.py | 12 ------------ source/tests/test_model_compression_se_a_ebd.py | 12 ------------ .../test_model_compression_se_a_ebd_type_one_side.py | 12 ------------ ...l_compression_se_a_type_one_side_exclude_types.py | 12 ------------ source/tests/test_model_compression_se_atten.py | 12 ------------ source/tests/test_model_compression_se_r.py | 12 ------------ source/tests/test_model_compression_se_t.py | 12 ------------ source/tests/test_parallel_training.py | 1 - source/tests/test_transfer.py | 12 ------------ 18 files changed, 17 insertions(+), 145 deletions(-) diff --git a/data/raw/copy_raw.py b/data/raw/copy_raw.py index 642865db86..69ccdf5c63 100755 --- a/data/raw/copy_raw.py +++ b/data/raw/copy_raw.py @@ -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" diff --git a/data/raw/shuffle_raw.py b/data/raw/shuffle_raw.py index 51bb7466c9..b4fc1457e5 100755 --- a/data/raw/shuffle_raw.py +++ b/data/raw/shuffle_raw.py @@ -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): @@ -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 " diff --git a/deepmd_utils/entrypoints/doc.py b/deepmd_utils/entrypoints/doc.py index 9f1fd39095..2c2c5e8451 100644 --- a/deepmd_utils/entrypoints/doc.py +++ b/deepmd_utils/entrypoints/doc.py @@ -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 diff --git a/doc/sphinx_contrib_exhale_multiproject.py b/doc/sphinx_contrib_exhale_multiproject.py index e05cf88ba2..e26cc158a4 100644 --- a/doc/sphinx_contrib_exhale_multiproject.py +++ b/doc/sphinx_contrib_exhale_multiproject.py @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 3a186b3949..c19c909c29 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -230,6 +230,7 @@ select = [ "C4", # flake8-comprehensions "RUF", # ruff "NPY", # numpy + "T20", # ban print ] ignore = [ @@ -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" diff --git a/source/tests/common.py b/source/tests/common.py index 9af324896f..5a7477d7e7 100644 --- a/source/tests/common.py +++ b/source/tests/common.py @@ -4,6 +4,7 @@ import os import pathlib import shutil +import warnings import dpdata import numpy as np @@ -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]) ) diff --git a/source/tests/test_adjust_sel.py b/source/tests/test_adjust_sel.py index 0ff6eb0792..ed3f89f964 100644 --- a/source/tests/test_adjust_sel.py +++ b/source/tests/test_adjust_sel.py @@ -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 @@ -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")) diff --git a/source/tests/test_finetune_se_atten.py b/source/tests/test_finetune_se_atten.py index f4689aacb3..782181ba62 100644 --- a/source/tests/test_finetune_se_atten.py +++ b/source/tests/test_finetune_se_atten.py @@ -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 @@ -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")) diff --git a/source/tests/test_mixed_prec_training.py b/source/tests/test_mixed_prec_training.py index d4c859f958..581355b172 100644 --- a/source/tests/test_mixed_prec_training.py +++ b/source/tests/test_mixed_prec_training.py @@ -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 @@ -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")) diff --git a/source/tests/test_model_compression_se_a.py b/source/tests/test_model_compression_se_a.py index 0e6e1361ad..cb1356f579 100644 --- a/source/tests/test_model_compression_se_a.py +++ b/source/tests/test_model_compression_se_a.py @@ -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 @@ -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") diff --git a/source/tests/test_model_compression_se_a_ebd.py b/source/tests/test_model_compression_se_a_ebd.py index 2a3163b062..133bae922e 100644 --- a/source/tests/test_model_compression_se_a_ebd.py +++ b/source/tests/test_model_compression_se_a_ebd.py @@ -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 @@ -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") diff --git a/source/tests/test_model_compression_se_a_ebd_type_one_side.py b/source/tests/test_model_compression_se_a_ebd_type_one_side.py index 2f3d16b05f..1079c80326 100644 --- a/source/tests/test_model_compression_se_a_ebd_type_one_side.py +++ b/source/tests/test_model_compression_se_a_ebd_type_one_side.py @@ -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 @@ -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") diff --git a/source/tests/test_model_compression_se_a_type_one_side_exclude_types.py b/source/tests/test_model_compression_se_a_type_one_side_exclude_types.py index 10ce352b6c..afdccd5ec9 100644 --- a/source/tests/test_model_compression_se_a_type_one_side_exclude_types.py +++ b/source/tests/test_model_compression_se_a_type_one_side_exclude_types.py @@ -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 @@ -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") diff --git a/source/tests/test_model_compression_se_atten.py b/source/tests/test_model_compression_se_atten.py index 6bab1a3881..0752635a98 100644 --- a/source/tests/test_model_compression_se_atten.py +++ b/source/tests/test_model_compression_se_atten.py @@ -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 @@ -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 diff --git a/source/tests/test_model_compression_se_r.py b/source/tests/test_model_compression_se_r.py index f79cdbee6c..4a9ee1de7c 100644 --- a/source/tests/test_model_compression_se_r.py +++ b/source/tests/test_model_compression_se_r.py @@ -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 @@ -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") diff --git a/source/tests/test_model_compression_se_t.py b/source/tests/test_model_compression_se_t.py index 48fee4ea1d..68566202b9 100644 --- a/source/tests/test_model_compression_se_t.py +++ b/source/tests/test_model_compression_se_t.py @@ -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 @@ -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") diff --git a/source/tests/test_parallel_training.py b/source/tests/test_parallel_training.py index 0a1a63a29b..7870c69b91 100644 --- a/source/tests/test_parallel_training.py +++ b/source/tests/test_parallel_training.py @@ -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!") diff --git a/source/tests/test_transfer.py b/source/tests/test_transfer.py index 27b97571c9..708e4e1538 100644 --- a/source/tests/test_transfer.py +++ b/source/tests/test_transfer.py @@ -1,6 +1,5 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import os -import subprocess as sp import unittest import numpy as np @@ -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):