mirror of
https://github.com/python/cpython
synced 2024-11-05 18:12:54 +00:00
fa3a38d81f
This is the converse of GH-15353 -- in addition to plenty of scripts in the tree that are marked with the executable bit (and so can be directly executed), there are a few that have a leading `#!` which could let them be executed, but it doesn't do anything because they don't have the executable bit set. Here's a command which finds such files and marks them. The first line finds files in the tree with a `#!` line *anywhere*; the next-to-last step checks that the *first* line is actually of that form. In between we filter out files that already have the bit set, and some files that are meant as fragments to be consumed by one or another kind of preprocessor. $ git grep -l '^#!' \ | grep -vxFf <( \ git ls-files --stage \ | perl -lane 'print $F[3] if (!/^100644/)' \ ) \ | grep -ve '\.in$' -e '^Doc/includes/' \ | while read f; do head -c2 "$f" | grep -qxF '#!' \ && chmod a+x "$f"; \ done
60 lines
1.8 KiB
Python
Executable file
60 lines
1.8 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
import os
|
|
import pathlib
|
|
import zipfile
|
|
from urllib.request import urlretrieve
|
|
|
|
|
|
def fetch_zip(commit_hash, zip_dir, *, org='python', binary=False, verbose):
|
|
repo = f'cpython-{"bin" if binary else "source"}-deps'
|
|
url = f'https://github.com/{org}/{repo}/archive/{commit_hash}.zip'
|
|
reporthook = None
|
|
if verbose:
|
|
reporthook = print
|
|
zip_dir.mkdir(parents=True, exist_ok=True)
|
|
filename, headers = urlretrieve(
|
|
url,
|
|
zip_dir / f'{commit_hash}.zip',
|
|
reporthook=reporthook,
|
|
)
|
|
return filename
|
|
|
|
|
|
def extract_zip(externals_dir, zip_path):
|
|
with zipfile.ZipFile(os.fspath(zip_path)) as zf:
|
|
zf.extractall(os.fspath(externals_dir))
|
|
return externals_dir / zf.namelist()[0].split('/')[0]
|
|
|
|
|
|
def parse_args():
|
|
p = argparse.ArgumentParser()
|
|
p.add_argument('-v', '--verbose', action='store_true')
|
|
p.add_argument('-b', '--binary', action='store_true',
|
|
help='Is the dependency in the binary repo?')
|
|
p.add_argument('-O', '--organization',
|
|
help='Organization owning the deps repos', default='python')
|
|
p.add_argument('-e', '--externals-dir', type=pathlib.Path,
|
|
help='Directory in which to store dependencies',
|
|
default=pathlib.Path(__file__).parent.parent / 'externals')
|
|
p.add_argument('tag',
|
|
help='tag of the dependency')
|
|
return p.parse_args()
|
|
|
|
|
|
def main():
|
|
args = parse_args()
|
|
zip_path = fetch_zip(
|
|
args.tag,
|
|
args.externals_dir / 'zips',
|
|
org=args.organization,
|
|
binary=args.binary,
|
|
verbose=args.verbose,
|
|
)
|
|
final_name = args.externals_dir / args.tag
|
|
extract_zip(args.externals_dir, zip_path).replace(final_name)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|