HomePhabricator

[lint] remove executable flag and shebang on non-script python files

Description

[lint] remove executable flag and shebang on non-script python files

Summary:
Python files that are imported as modules or always executed using the interpreter explicitely (python test.py) should not have a shebang and should not be executable.
Fix the current inconsistencies.

This is mostly a scripted diff, except for the PythonShebangLinter.php changes:

find test/functional/ -name '*py' -not -name 'test_runner.py' | xargs  sed -i '1{/^#!/d;}'
find test/functional/ -name '*py' -not -name 'test_runner.py' | xargs chmod 644

find electrum -name '*py' -not -path 'electrum/scripts/*' -not -path 'electrum/contrib/*' -not -name 'test_runner.py' | xargs  sed -i '1{/^#!/d;}'
find electrum -name '*py' -not -path 'electrum/scripts/*' -not -path 'electrum/contrib/*' -not -name 'test_runner.py' | xargs chmod 644

find chronik/chronik-plugin-impl -name '*py'  | xargs  sed -i '1{/^#!/d;}'

chmod 755 contrib/testgen/base58.py
sed -i '1{/^#!/d;}' contrib/buildbot/shieldio.py
sed -i '1{/^#!/d;}' contrib/buildbot/test/abcbot_fixture.py
sed -i '1{/^#!/d;}' electrum/scripts/util.py

And arc lint to remove a few blank lines at the beginning of files.

Note that the sed command removes the first line of a file if it starts with #! (shebang lines).

Depends on D15449

Test Plan:
ninja check-functional-extend check-electrum

arc lint --everything

Add a few shebangs to non executable python files and check that it raises an error.

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D15448

Details

Provenance
PiRKAuthored on Feb 14 2024, 11:28
PiRKPushed on Feb 15 2024, 16:50
Reviewer
Restricted Project
Differential Revision
D15448: [lint] remove executable flag and shebang on non-script python files
Parents
rABC7e27ef7e48a8: [Automated] Update timing.json
Branches
Unknown
Tags
Unknown