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.
I think you could squash the commits since they're related.
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
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/coinstatsindexBefore (test/lint/lint-circular-dependencies.sh):
A new circular dependency in the form of "index/blockfilterindex -> index/coinstatsindex -> index/blockfilterindex" appears to have been introduced.
A new circular dependency in the form of "index/blockfilterindex -> index/coinstatsindex -> validation -> index/blockfilterindex" appears to have been introduced.
Good job! The circular dependency "index/blockfilterindex -> node/blockstorage -> validation -> index/blockfilterindex" is no longer present.
Please remove it from EXPECTED_CIRCULAR_DEPENDENCIES in test/lint/lint-circular-dependencies.sh
to make sure this circular dependency is not accidentally reintroduced.
After (test/lint/lint-circular-dependencies.py):
A new circular dependency in the form of "index/blockfilterindex -> index/coinstatsindex -> index/blockfilterindex" appears to have been introduced.
A new circular dependency in the form of "index/blockfilterindex -> index/coinstatsindex -> validation -> index/blockfilterindex" appears to have been introduced.
Good job! The circular dependency "index/blockfilterindex -> node/blockstorage -> validation -> index/blockfilterindex" is no longer present.
Please remove it from EXPECTED_CIRCULAR_DEPENDENCIES in test/lint/lint-circular-dependencies.py
to 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
@KevinMusgrave Indeed, the newline after each message from the original script was missing. A new version has been pushed with this fix.
Tested ACK ca52afd92be695b05fb13fe4f96a25ff2b3c7f9c
Output:
A new circular dependency in the form of "index/blockfilterindex -> index/coinstatsindex -> index/blockfilterindex" appears to have been introduced.
A new circular dependency in the form of "index/blockfilterindex -> index/coinstatsindex -> validation -> index/blockfilterindex" appears to have been introduced.
Good job! The circular dependency "index/blockfilterindex -> node/blockstorage -> validation -> index/blockfilterindex" is no longer present.
Please remove it from EXPECTED_CIRCULAR_DEPENDENCIES in test/lint/lint-circular-dependencies.py
to 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?
dependencies_output = subprocess.check_output(
command,
Because ../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.
FIxed
Tested ACK 79635c79e0533aa7f2e2440515ad766f965343ba
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 ["*", "*/*", "*/*/*"]:
Wouldn't it be better to call 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]
Wouldn't it be better to use sys.executable instead of "python3"?