Code formatting for test/sanity/code-smell/ (#85165)

pull/85169/head
Matt Clay 7 months ago committed by GitHub
parent fe2d9e316a
commit 460343510c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -83,9 +83,7 @@ def main():
data = {}
data['doc'], data['examples'], data['return'], data['metadata'] = get_docstring(plugin, fragment_loader)
for result in find_deprecations(data['doc']):
print(
'%s: %s is scheduled for removal in %s' % (plugin, '.'.join(str(i) for i in result[0][:-2]), result[1])
)
print('%s: %s is scheduled for removal in %s' % (plugin, '.'.join(str(i) for i in result[0][:-2]), result[1]))
base = os.path.join(os.path.dirname(ansible.config.__file__), 'base.yml')
root_path = os.path.dirname(os.path.dirname(os.path.dirname(ansible.__file__)))

@ -33,13 +33,10 @@ def main() -> None:
contexts = (
MyPyContext('ansible-test', ['test/lib/ansible_test/'], controller_python_versions),
MyPyContext('ansible-test', ['test/lib/ansible_test/_util/target/'], remote_only_python_versions),
MyPyContext('ansible-core', ['lib/ansible/'], controller_python_versions),
MyPyContext('ansible-core', ['lib/ansible/modules/', 'lib/ansible/module_utils/'], remote_only_python_versions),
MyPyContext('ansible-core', ['test/units/'], controller_python_versions),
MyPyContext('ansible-core', ['test/units/modules/', 'test/units/module_utils/'], remote_only_python_versions),
MyPyContext('packaging', ['packaging/'], controller_python_versions),
)
@ -61,14 +58,16 @@ def main() -> None:
match = re.search(r'^(?P<message>.*) {2}\[(?P<code>.*)]$', message.message)
messages.append(SanityMessage(
message=match.group('message'),
path=message.path,
line=message.line,
column=message.column,
level=message.level,
code=match.group('code'),
))
messages.append(
SanityMessage(
message=match.group('message'),
path=message.path,
line=message.line,
column=message.column,
level=message.level,
code=match.group('code'),
)
)
# FUTURE: provide a way for script based tests to report non-error messages (in this case, notices)
@ -172,14 +171,17 @@ def test_context(
parsed = parse_to_list_of_dict(pattern, stdout or '')
messages = [SanityMessage(
level=r['level'],
message=r['message'],
path=r['path'],
line=int(r['line']),
column=int(r.get('column') or '0'),
code='', # extracted from error level messages later
) for r in parsed]
messages = [
SanityMessage(
level=r['level'],
message=r['message'],
path=r['path'],
line=int(r['line']),
column=int(r.get('column') or '0'),
code='', # extracted from error level messages later
)
for r in parsed
]
return messages

@ -20,8 +20,7 @@ def main():
match = re.search('(\u00a0)', text)
if match:
print('%s:%d:%d: use an ASCII space instead of a Unicode no-break space' % (
path, line + 1, match.start(1) + 1))
print('%s:%d:%d: use an ASCII space instead of a Unicode no-break space' % (path, line + 1, match.start(1) + 1))
if __name__ == '__main__':

@ -43,7 +43,7 @@ def main():
continue
ext = os.path.splitext(path)[1]
if ext in ('.yml', ) and any(path.startswith(yaml_directory) for yaml_directory in allow_yaml):
if ext in ('.yml',) and any(path.startswith(yaml_directory) for yaml_directory in allow_yaml):
continue
if ext not in allowed_extensions:

@ -167,10 +167,7 @@ def check_files(source: str, expected: list[str], actual: list[str]) -> list[str
filter_fuzzy_matches(missing, extra)
errors = (
[f'{path}: missing from {source}' for path in sorted(missing)] +
[f'{path}: unexpected in {source}' for path in sorted(extra)]
)
errors = [f'{path}: missing from {source}' for path in sorted(missing)] + [f'{path}: unexpected in {source}' for path in sorted(extra)]
return errors

@ -15,8 +15,10 @@ def main() -> None:
cmd = [
sys.executable,
'-m', 'pymarkdown',
'--config', pathlib.Path(__file__).parent / 'pymarkdown.config.json',
'-m',
'pymarkdown',
'--config',
pathlib.Path(__file__).parent / 'pymarkdown.config.json',
'--strict-config',
'scan',
] + paths

@ -72,10 +72,10 @@ def check_ansible_test(path: str, requirements: list[tuple[int, str, re.Match]])
from ansible_test._internal.coverage_util import COVERAGE_VERSIONS
from ansible_test._internal.util import version_to_str
expected_lines = set((
expected_lines = {
f"coverage == {item.coverage_version} ; python_version >= '{version_to_str(item.min_python)}' and python_version <= '{version_to_str(item.max_python)}'"
for item in COVERAGE_VERSIONS
))
}
for idx, requirement in enumerate(requirements):
lineno, line, match = requirement
@ -92,8 +92,10 @@ def check_ansible_test(path: str, requirements: list[tuple[int, str, re.Match]])
def parse_requirements(lines):
# see https://www.python.org/dev/peps/pep-0508/#names
pattern = re.compile(r'^(?P<name>[A-Z0-9][A-Z0-9._-]*[A-Z0-9]|[A-Z0-9])(?P<extras> *\[[^]]*])?(?P<constraints>[^;#]*)(?P<markers>[^#]*)(?P<comment>.*)$',
re.IGNORECASE)
pattern = re.compile(
pattern=r'^(?P<name>[A-Z0-9][A-Z0-9._-]*[A-Z0-9]|[A-Z0-9])(?P<extras> *\[[^]]*])?(?P<constraints>[^;#]*)(?P<markers>[^#]*)(?P<comment>.*)$',
flags=re.IGNORECASE,
)
matches = [(lineno, line, pattern.search(line)) for lineno, line in enumerate(lines, start=1)]
requirements = []

@ -88,18 +88,17 @@ def get_bundled_metadata(filename):
return None
if line.strip().startswith('# CANT_UPDATE'):
print(
'{0} marked as CANT_UPDATE, so skipping. Manual '
'check for CVEs required.'.format(filename))
print(f'{filename} marked as CANT_UPDATE, so skipping. Manual check for CVEs required.')
return None
if line.strip().startswith('_BUNDLED_METADATA'):
data = line[line.index('{'):].strip()
data = line[line.index('{') :].strip()
break
else:
raise ValueError('Unable to check bundled library for update. Please add'
' _BUNDLED_METADATA dictionary to the library file with'
' information on pypi name and bundled version.')
raise ValueError(
'Unable to check bundled library for update. '
'Please add _BUNDLED_METADATA dictionary to the library file with information on pypi name and bundled version.'
)
metadata = json.loads(data)
return metadata
@ -138,20 +137,20 @@ def main():
if filename.startswith('test/support/'):
continue # bundled support code does not need to be updated or tracked
print('{0}: ERROR: File contains _BUNDLED_METADATA but needs to be added to'
' test/sanity/code-smell/update-bundled.py'.format(filename))
print(f'{filename}: ERROR: File contains _BUNDLED_METADATA but needs to be added to test/sanity/code-smell/update-bundled.py')
for filename in bundled_libs:
try:
metadata = get_bundled_metadata(filename)
except ValueError as e:
print('{0}: ERROR: {1}'.format(filename, e))
print(f'{filename}: ERROR: {e}')
continue
except (IOError, OSError) as e:
if e.errno == 2:
print('{0}: ERROR: {1}. Perhaps the bundled library has been removed'
' or moved and the bundled library test needs to be modified as'
' well?'.format(filename, e))
print(
f'{filename}: ERROR: {e}. '
'Perhaps the bundled library has been removed or moved and the bundled library test needs to be modified as well?'
)
if metadata is None:
continue
@ -163,12 +162,11 @@ def main():
latest_version = get_latest_applicable_version(pypi_data, constraints)
if LooseVersion(metadata['version']) < LooseVersion(latest_version):
print('{0}: UPDATE {1} from {2} to {3} {4}'.format(
filename,
metadata['pypi_name'],
metadata['version'],
latest_version,
'https://pypi.org/pypi/{0}/json'.format(metadata['pypi_name'])))
name = metadata['pypi_name']
version = metadata['version']
url = f"https://pypi.org/pypi/{name}/json"
print(f"{filename}: UPDATE {name} from {version} to {latest_version} {url}")
if __name__ == '__main__':

Loading…
Cancel
Save