Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formatting all code with black and flake8 #82920

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
24 changes: 13 additions & 11 deletions .azure-pipelines/scripts/combine-coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def main():
"""Main program entry point."""
source_directory = sys.argv[1]

if '/ansible_collections/' in os.getcwd():
if "/ansible_collections/" in os.getcwd():
output_path = "tests/output"
else:
output_path = "test/results"

destination_directory = os.path.join(output_path, 'coverage')
destination_directory = os.path.join(output_path, "coverage")

if not os.path.exists(destination_directory):
os.makedirs(destination_directory)
Expand All @@ -33,27 +33,29 @@ def main():
count = 0

for name in os.listdir(source_directory):
match = re.search('^Coverage (?P<attempt>[0-9]+) (?P<label>.+)$', name)
label = match.group('label')
attempt = int(match.group('attempt'))
match = re.search("^Coverage (?P<attempt>[0-9]+) (?P<label>.+)$", name)
label = match.group("label")
attempt = int(match.group("attempt"))
jobs[label] = max(attempt, jobs.get(label, 0))

for label, attempt in jobs.items():
name = 'Coverage {attempt} {label}'.format(label=label, attempt=attempt)
name = "Coverage {attempt} {label}".format(label=label, attempt=attempt)
source = os.path.join(source_directory, name)
source_files = os.listdir(source)

for source_file in source_files:
source_path = os.path.join(source, source_file)
destination_path = os.path.join(destination_directory, source_file + '.' + label)
destination_path = os.path.join(
destination_directory, source_file + "." + label
)
print('"%s" -> "%s"' % (source_path, destination_path))
shutil.copyfile(source_path, destination_path)
count += 1

print('Coverage file count: %d' % count)
print('##vso[task.setVariable variable=coverageFileCount]%d' % count)
print('##vso[task.setVariable variable=outputPath]%s' % output_path)
print("Coverage file count: %d" % count)
print("##vso[task.setVariable variable=coverageFileCount]%d" % count)
print("##vso[task.setVariable variable=outputPath]%s" % output_path)


if __name__ == '__main__':
if __name__ == "__main__":
main()
45 changes: 27 additions & 18 deletions .azure-pipelines/scripts/publish-codecov.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class Args:

def parse_args() -> Args:
parser = argparse.ArgumentParser()
parser.add_argument('-n', '--dry-run', action='store_true')
parser.add_argument('path', type=pathlib.Path)
parser.add_argument("-n", "--dry-run", action="store_true")
parser.add_argument("path", type=pathlib.Path)

args = parser.parse_args()

Expand All @@ -45,42 +45,51 @@ def parse_args() -> Args:

def process_files(directory: pathlib.Path) -> t.Tuple[CoverageFile, ...]:
processed = []
for file in directory.joinpath('reports').glob('coverage*.xml'):
name = file.stem.replace('coverage=', '')
for file in directory.joinpath("reports").glob("coverage*.xml"):
name = file.stem.replace("coverage=", "")

# Get flags from name
flags = name.replace('-powershell', '').split('=') # Drop '-powershell' suffix
flags = [flag if not flag.startswith('stub') else flag.split('-')[0] for flag in flags] # Remove "-01" from stub files
flags = name.replace("-powershell", "").split("=") # Drop '-powershell' suffix
flags = [
flag if not flag.startswith("stub") else flag.split("-")[0]
for flag in flags
] # Remove "-01" from stub files

processed.append(CoverageFile(name, file, flags))

return tuple(processed)


def upload_files(codecov_bin: pathlib.Path, files: t.Tuple[CoverageFile, ...], dry_run: bool = False) -> None:
def upload_files(
codecov_bin: pathlib.Path, files: t.Tuple[CoverageFile, ...], dry_run: bool = False
) -> None:
for file in files:
cmd = [
str(codecov_bin),
'--name', file.name,
'--file', str(file.path),
"--name",
file.name,
"--file",
str(file.path),
]
for flag in file.flags:
cmd.extend(['--flags', flag])
cmd.extend(["--flags", flag])

if dry_run:
print(f'DRY-RUN: Would run command: {cmd}')
print(f"DRY-RUN: Would run command: {cmd}")
continue

subprocess.run(cmd, check=True)


def download_file(url: str, dest: pathlib.Path, flags: int, dry_run: bool = False) -> None:
def download_file(
url: str, dest: pathlib.Path, flags: int, dry_run: bool = False
) -> None:
if dry_run:
print(f'DRY-RUN: Would download {url} to {dest} and set mode to {flags:o}')
print(f"DRY-RUN: Would download {url} to {dest} and set mode to {flags:o}")
return

with urllib.request.urlopen(url) as resp:
with dest.open('w+b') as f:
with dest.open("w+b") as f:
# Read data in chunks rather than all at once
shutil.copyfileobj(resp, f, 64 * 1024)

Expand All @@ -89,14 +98,14 @@ def download_file(url: str, dest: pathlib.Path, flags: int, dry_run: bool = Fals

def main():
args = parse_args()
url = 'https://ci-files.testing.ansible.com/codecov/linux/codecov'
with tempfile.TemporaryDirectory(prefix='codecov-') as tmpdir:
codecov_bin = pathlib.Path(tmpdir) / 'codecov'
url = "https://ci-files.testing.ansible.com/codecov/linux/codecov"
with tempfile.TemporaryDirectory(prefix="codecov-") as tmpdir:
codecov_bin = pathlib.Path(tmpdir) / "codecov"
download_file(url, codecov_bin, 0o755, args.dry_run)

files = process_files(args.path)
upload_files(codecov_bin, files, args.dry_run)


if __name__ == '__main__':
if __name__ == "__main__":
main()
8 changes: 4 additions & 4 deletions .azure-pipelines/scripts/time-command.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def main():
"""Main program entry point."""
start = time.time()

sys.stdin.reconfigure(errors='surrogateescape')
sys.stdout.reconfigure(errors='surrogateescape')
sys.stdin.reconfigure(errors="surrogateescape")
sys.stdout.reconfigure(errors="surrogateescape")

for line in sys.stdin:
seconds = time.time() - start
sys.stdout.write('%02d:%02d %s' % (seconds // 60, seconds % 60, line))
sys.stdout.write("%02d:%02d %s" % (seconds // 60, seconds % 60, line))
sys.stdout.flush()


if __name__ == '__main__':
if __name__ == "__main__":
main()
10 changes: 5 additions & 5 deletions hacking/ansible-profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

target = sys.argv.pop(1)
myclass = "%sCLI" % target.capitalize()
module_name = f'ansible.cli.{target}'
module_name = f"ansible.cli.{target}"

try:
# define cli
Expand All @@ -21,10 +21,10 @@
raise

try:
args = [to_text(a, errors='surrogate_or_strict') for a in sys.argv]
args = [to_text(a, errors="surrogate_or_strict") for a in sys.argv]
except UnicodeError:
sys.stderr.write(u"The full traceback was:\n\n%s" % to_text(traceback.format_exc()))
sys.exit(u'Command line args are parsable to utf-8')
sys.stderr.write("The full traceback was:\n\n%s" % to_text(traceback.format_exc()))
sys.exit("Command line args are parsable to utf-8")

# init cli
cli = mycli(args)
Expand All @@ -35,4 +35,4 @@
cli.parse()

# run
cProfile.run('cli.run()')
cProfile.run("cli.run()")