Here is a port of /test/lint/lint-circular-dependencies.sh
to a Python-script as part of the request of #24783.
It aims to provide the same output as the bash version.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Tested 23e047620f85636195c8d7b81891ec3a8693d671. The new version could maybe use a line break before the Good job
message.
As a test I added:
#include <index/coinstatsindex.h>
to index/blockfilterindex
#include <index/blockfilterindex.h>
to index/coinstatsindex
Before (test/lint/lint-circular-dependencies.sh
):
0A new circular dependency in the form of "index/blockfilterindex -> index/coinstatsindex -> index/blockfilterindex" appears to have been introduced.
1
2A new circular dependency in the form of "index/blockfilterindex -> index/coinstatsindex -> validation -> index/blockfilterindex" appears to have been introduced.
3
4Good job! The circular dependency "index/blockfilterindex -> node/blockstorage -> validation -> index/blockfilterindex" is no longer present.
5Please remove it from EXPECTED_CIRCULAR_DEPENDENCIES in test/lint/lint-circular-dependencies.sh
6to make sure this circular dependency is not accidentally reintroduced.
After (test/lint/lint-circular-dependencies.py
):
0A new circular dependency in the form of "index/blockfilterindex -> index/coinstatsindex -> index/blockfilterindex" appears to have been introduced.
1A new circular dependency in the form of "index/blockfilterindex -> index/coinstatsindex -> validation -> index/blockfilterindex" appears to have been introduced.
2Good job! The circular dependency "index/blockfilterindex -> node/blockstorage -> validation -> index/blockfilterindex" is no longer present.
3Please remove it from EXPECTED_CIRCULAR_DEPENDENCIES in test/lint/lint-circular-dependencies.py
4to make sure this circular dependency is not accidentally reintroduced.
Sidenote: I’m not sure why adding a circular dependency causes an existing circular dependency to disappear
Tested ACK ca52afd92be695b05fb13fe4f96a25ff2b3c7f9c
Output:
0A new circular dependency in the form of "index/blockfilterindex -> index/coinstatsindex -> index/blockfilterindex" appears to have been introduced.
1
2A new circular dependency in the form of "index/blockfilterindex -> index/coinstatsindex -> validation -> index/blockfilterindex" appears to have been introduced.
3
4Good job! The circular dependency "index/blockfilterindex -> node/blockstorage -> validation -> index/blockfilterindex" is no longer present.
5Please remove it from EXPECTED_CIRCULAR_DEPENDENCIES in test/lint/lint-circular-dependencies.py
6to make sure this circular dependency is not accidentally reintroduced.
45+ files.extend(glob.glob(f"{path}.{extension}"))
46+
47+ command = ["python3", "../contrib/devtools/circular-dependencies.py", *files]
48+ dependencies_output = subprocess.run(
49+ command,
50+ stdout=subprocess.PIPE,
any reason to ignore errors?
0 dependencies_output = subprocess.check_output(
1 command,
../contrib/devtools/circular-dependencies.py
does not exit with 0 if there is at least one circular dependency, resulting in subprocess.check
raising an error
76+ f"Please remove it from EXPECTED_CIRCULAR_DEPENDENCIES in {__file__}",
77+ file=sys.stderr,
78+ )
79+ print(
80+ "to make sure this circular dependency is not accidentally reintroduced.\n",
81+ file=sys.stderr,
why are you printing to stderr?
Also the exit code is wrong.
38+ CODE_DIR
39+ ) # We change dir before globbing since glob.glob's root_dir option is only available in Python 3.10
40+
41+ # Using glob.glob since subprocess.run's globbing won't work without shell=True
42+ files = []
43+ for path in ["*", "*/*", "*/*/*"]:
git ls-files -- '*.h' '*.cpp'
?
42+ files = []
43+ for path in ["*", "*/*", "*/*/*"]:
44+ for extension in ["h", "cpp"]:
45+ files.extend(glob.glob(f"{path}.{extension}"))
46+
47+ command = ["python3", "../contrib/devtools/circular-dependencies.py", *files]
sys.executable
instead of "python3"
?