Read about our upcoming Code of Conduct on this issue

Commit 66a22c92 authored by durin42's avatar durin42
Browse files

formating: upgrade to black 20.8b1

This required a couple of small tweaks to un-confuse black, but now it
works. Big formatting changes come from:

 * Dramatically improved collection-splitting logic upstream
 * Black having a strong (correct IMO) opinion that """ is better than '''

Differential Revision: https://phab.mercurial-scm.org/D9430
parent 346af7687c6f
Pipeline #13497 failed with stage
in 1 minute and 56 seconds
......@@ -152,7 +152,11 @@ ASSUME_ROLE_POLICY_DOCUMENT = '''
IAM_INSTANCE_PROFILES = {
'ephemeral-ec2-1': {'roles': ['ephemeral-ec2-role-1',],}
'ephemeral-ec2-1': {
'roles': [
'ephemeral-ec2-role-1',
],
}
}
......@@ -469,10 +473,22 @@ def find_image(ec2resource, owner_id, name, reverse_sort_field=None):
images = ec2resource.images.filter(
Filters=[
{'Name': 'owner-id', 'Values': [owner_id],},
{'Name': 'state', 'Values': ['available'],},
{'Name': 'image-type', 'Values': ['machine'],},
{'Name': 'name', 'Values': [name],},
{
'Name': 'owner-id',
'Values': [owner_id],
},
{
'Name': 'state',
'Values': ['available'],
},
{
'Name': 'image-type',
'Values': ['machine'],
},
{
'Name': 'name',
'Values': [name],
},
]
)
......@@ -519,10 +535,13 @@ def ensure_security_groups(ec2resource, prefix='hg-'):
print('adding security group %s' % actual)
group_res = ec2resource.create_security_group(
Description=group['description'], GroupName=actual,
Description=group['description'],
GroupName=actual,
)
group_res.authorize_ingress(IpPermissions=group['ingress'],)
group_res.authorize_ingress(
IpPermissions=group['ingress'],
)
security_groups[name] = group_res
......@@ -614,7 +633,10 @@ def wait_for_ssm(ssmclient, instances):
while True:
res = ssmclient.describe_instance_information(
Filters=[
{'Key': 'InstanceIds', 'Values': [i.id for i in instances],},
{
'Key': 'InstanceIds',
'Values': [i.id for i in instances],
},
],
)
......@@ -636,7 +658,9 @@ def run_ssm_command(ssmclient, instances, document_name, parameters):
InstanceIds=[i.id for i in instances],
DocumentName=document_name,
Parameters=parameters,
CloudWatchOutputConfig={'CloudWatchOutputEnabled': True,},
CloudWatchOutputConfig={
'CloudWatchOutputEnabled': True,
},
)
command_id = res['Command']['CommandId']
......@@ -645,7 +669,8 @@ def run_ssm_command(ssmclient, instances, document_name, parameters):
while True:
try:
res = ssmclient.get_command_invocation(
CommandId=command_id, InstanceId=instance.id,
CommandId=command_id,
InstanceId=instance.id,
)
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == 'InvocationDoesNotExist':
......@@ -799,19 +824,32 @@ def create_ami_from_instance(
instance.stop()
ec2client.get_waiter('instance_stopped').wait(
InstanceIds=[instance.id], WaiterConfig={'Delay': 5,}
InstanceIds=[instance.id],
WaiterConfig={
'Delay': 5,
},
)
print('%s is stopped' % instance.id)
image = instance.create_image(Name=name, Description=description,)
image = instance.create_image(
Name=name,
Description=description,
)
image.create_tags(
Tags=[{'Key': 'HGIMAGEFINGERPRINT', 'Value': fingerprint,},]
Tags=[
{
'Key': 'HGIMAGEFINGERPRINT',
'Value': fingerprint,
},
]
)
print('waiting for image %s' % image.id)
ec2client.get_waiter('image_available').wait(ImageIds=[image.id],)
ec2client.get_waiter('image_available').wait(
ImageIds=[image.id],
)
print('image %s available as %s' % (image.id, image.name))
......@@ -837,7 +875,9 @@ def ensure_linux_dev_ami(c: AWSConnection, distro='debian10', prefix='hg-'):
ssh_username = 'admin'
elif distro == 'debian10':
image = find_image(
ec2resource, DEBIAN_ACCOUNT_ID_2, 'debian-10-amd64-20190909-10',
ec2resource,
DEBIAN_ACCOUNT_ID_2,
'debian-10-amd64-20190909-10',
)
ssh_username = 'admin'
elif distro == 'ubuntu18.04':
......@@ -1066,7 +1106,9 @@ def temporary_linux_dev_instances(
def ensure_windows_dev_ami(
c: AWSConnection, prefix='hg-', base_image_name=WINDOWS_BASE_IMAGE_NAME,
c: AWSConnection,
prefix='hg-',
base_image_name=WINDOWS_BASE_IMAGE_NAME,
):
"""Ensure Windows Development AMI is available and up-to-date.
......@@ -1190,7 +1232,9 @@ def ensure_windows_dev_ami(
ssmclient,
[instance],
'AWS-RunPowerShellScript',
{'commands': WINDOWS_BOOTSTRAP_POWERSHELL.split('\n'),},
{
'commands': WINDOWS_BOOTSTRAP_POWERSHELL.split('\n'),
},
)
# Reboot so all updates are fully applied.
......@@ -1202,7 +1246,10 @@ def ensure_windows_dev_ami(
print('rebooting instance %s' % instance.id)
instance.stop()
ec2client.get_waiter('instance_stopped').wait(
InstanceIds=[instance.id], WaiterConfig={'Delay': 5,}
InstanceIds=[instance.id],
WaiterConfig={
'Delay': 5,
},
)
instance.start()
......
......@@ -282,16 +282,20 @@ def get_parser():
help='Path for local state files',
)
parser.add_argument(
'--aws-region', help='AWS region to use', default='us-west-2',
'--aws-region',
help='AWS region to use',
default='us-west-2',
)
subparsers = parser.add_subparsers()
sp = subparsers.add_parser(
'bootstrap-linux-dev', help='Bootstrap Linux development environments',
'bootstrap-linux-dev',
help='Bootstrap Linux development environments',
)
sp.add_argument(
'--distros', help='Comma delimited list of distros to bootstrap',
'--distros',
help='Comma delimited list of distros to bootstrap',
)
sp.add_argument(
'--parallel',
......@@ -312,13 +316,17 @@ def get_parser():
sp.set_defaults(func=bootstrap_windows_dev)
sp = subparsers.add_parser(
'build-all-windows-packages', help='Build all Windows packages',
'build-all-windows-packages',
help='Build all Windows packages',
)
sp.add_argument(
'--revision', help='Mercurial revision to build', default='.',
'--revision',
help='Mercurial revision to build',
default='.',
)
sp.add_argument(
'--version', help='Mercurial version string to use',
'--version',
help='Mercurial version string to use',
)
sp.add_argument(
'--base-image-name',
......@@ -328,7 +336,8 @@ def get_parser():
sp.set_defaults(func=build_all_windows_packages)
sp = subparsers.add_parser(
'build-inno', help='Build Inno Setup installer(s)',
'build-inno',
help='Build Inno Setup installer(s)',
)
sp.add_argument(
'--python-version',
......@@ -346,10 +355,13 @@ def get_parser():
default=['x64'],
)
sp.add_argument(
'--revision', help='Mercurial revision to build', default='.',
'--revision',
help='Mercurial revision to build',
default='.',
)
sp.add_argument(
'--version', help='Mercurial version string to use in installer',
'--version',
help='Mercurial version string to use in installer',
)
sp.add_argument(
'--base-image-name',
......@@ -359,7 +371,8 @@ def get_parser():
sp.set_defaults(func=build_inno)
sp = subparsers.add_parser(
'build-windows-wheel', help='Build Windows wheel(s)',
'build-windows-wheel',
help='Build Windows wheel(s)',
)
sp.add_argument(
'--python-version',
......@@ -376,7 +389,9 @@ def get_parser():
default=['x64'],
)
sp.add_argument(
'--revision', help='Mercurial revision to build', default='.',
'--revision',
help='Mercurial revision to build',
default='.',
)
sp.add_argument(
'--base-image-name',
......@@ -402,10 +417,13 @@ def get_parser():
default=['x64'],
)
sp.add_argument(
'--revision', help='Mercurial revision to build', default='.',
'--revision',
help='Mercurial revision to build',
default='.',
)
sp.add_argument(
'--version', help='Mercurial version string to use in installer',
'--version',
help='Mercurial version string to use in installer',
)
sp.add_argument(
'--base-image-name',
......@@ -421,11 +439,15 @@ def get_parser():
sp.set_defaults(func=terminate_ec2_instances)
sp = subparsers.add_parser(
'purge-ec2-resources', help='Purge all EC2 resources managed by us',
'purge-ec2-resources',
help='Purge all EC2 resources managed by us',
)
sp.set_defaults(func=purge_ec2_resources)
sp = subparsers.add_parser('run-tests-linux', help='Run tests on Linux',)
sp = subparsers.add_parser(
'run-tests-linux',
help='Run tests on Linux',
)
sp.add_argument(
'--distro',
help='Linux distribution to run tests on',
......@@ -468,10 +490,13 @@ def get_parser():
sp.set_defaults(func=run_tests_linux)
sp = subparsers.add_parser(
'run-tests-windows', help='Run tests on Windows',
'run-tests-windows',
help='Run tests on Windows',
)
sp.add_argument(
'--instance-type', help='EC2 instance type to use', default='t3.medium',
'--instance-type',
help='EC2 instance type to use',
default='t3.medium',
)
sp.add_argument(
'--python-version',
......@@ -486,7 +511,8 @@ def get_parser():
default='x64',
)
sp.add_argument(
'--test-flags', help='Extra command line flags to pass to run-tests.py',
'--test-flags',
help='Extra command line flags to pass to run-tests.py',
)
sp.add_argument(
'--base-image-name',
......@@ -514,10 +540,12 @@ def get_parser():
help='Skip uploading to www.mercurial-scm.org',
)
sp.add_argument(
'--ssh-username', help='SSH username for mercurial-scm.org',
'--ssh-username',
help='SSH username for mercurial-scm.org',
)
sp.add_argument(
'version', help='Mercurial version string to locate local packages',
'version',
help='Mercurial version string to locate local packages',
)
sp.set_defaults(func=publish_windows_artifacts)
......
......@@ -362,7 +362,8 @@ def build_inno_installer(
raise Exception("unhandled arch: %s" % arch)
ps = BUILD_INNO_PYTHON3.format(
pyoxidizer_target=target_triple, version=version,
pyoxidizer_target=target_triple,
version=version,
)
else:
extra_args = []
......@@ -427,7 +428,8 @@ def build_wix_installer(
raise Exception("unhandled arch: %s" % arch)
ps = BUILD_WIX_PYTHON3.format(
pyoxidizer_target=target_triple, version=version,
pyoxidizer_target=target_triple,
version=version,
)
else:
extra_args = []
......@@ -460,7 +462,10 @@ def run_tests(winrm_client, python_version, arch, test_flags=''):
python_path = 'python%s-%s' % (python_version.replace('.', ''), arch)
ps = RUN_TESTS.format(python_path=python_path, test_flags=test_flags or '',)
ps = RUN_TESTS.format(
python_path=python_path,
test_flags=test_flags or '',
)
run_powershell(winrm_client, ps)
......
......@@ -213,15 +213,19 @@ def replacetokens(tokens, opts):
fn = t.string
# *attr() builtins don't accept byte strings to 2nd argument.
if fn in (
'getattr',
'setattr',
'hasattr',
'safehasattr',
'wrapfunction',
'wrapclass',
'addattr',
) and (opts['allow-attr-methods'] or not _isop(i - 1, '.')):
if (
fn
in (
'getattr',
'setattr',
'hasattr',
'safehasattr',
'wrapfunction',
'wrapclass',
'addattr',
)
and (opts['allow-attr-methods'] or not _isop(i - 1, '.'))
):
arg1idx = _findargnofcall(1)
if arg1idx is not None:
_ensuresysstr(arg1idx)
......
......@@ -620,13 +620,17 @@ cfilters = [
]
inutilpats = [
[(r'\bui\.', "don't use ui in util"),],
[
(r'\bui\.', "don't use ui in util"),
],
# warnings
[],
]
inrevlogpats = [
[(r'\brepo\.', "don't use repo in revlog"),],
[
(r'\brepo\.', "don't use repo in revlog"),
],
# warnings
[],
]
......
......@@ -44,7 +44,11 @@ def build_inno(pyoxidizer_target=None, python=None, iscc=None, version=None):
)
else:
inno.build_with_py2exe(
SOURCE_DIR, build_dir, pathlib.Path(python), iscc, version=version,
SOURCE_DIR,
build_dir,
pathlib.Path(python),
iscc,
version=version,
)
......
......@@ -198,7 +198,11 @@ def build_installer(
except jinja2.TemplateSyntaxError as e:
raise Exception(
'template syntax error at %s:%d: %s'
% (e.name, e.lineno, e.message,)
% (
e.name,
e.lineno,
e.message,
)
)
content = template.render(package_files=package_files)
......
......@@ -517,7 +517,10 @@ def run_wix_packaging(
args.append(str(build_dir / ('%s.wixobj' % source[:-4])))
args.extend(
[str(build_dir / 'stage.wixobj'), str(build_dir / 'mercurial.wixobj'),]
[
str(build_dir / 'stage.wixobj'),
str(build_dir / 'mercurial.wixobj'),
]
)
subprocess.run(args, cwd=str(source_dir), check=True)
......
......@@ -291,7 +291,9 @@ try:
experimental=True,
)
configitem(
b'perf', b'pre-run', default=mercurial.configitems.dynamicdefault,
b'perf',
b'pre-run',
default=mercurial.configitems.dynamicdefault,
)
configitem(
b'perf',
......@@ -310,19 +312,29 @@ except TypeError:
# compatibility fix for a11fd395e83f
# hg version: 5.2
configitem(
b'perf', b'presleep', default=mercurial.configitems.dynamicdefault,
b'perf',
b'presleep',
default=mercurial.configitems.dynamicdefault,
)
configitem(
b'perf', b'stub', default=mercurial.configitems.dynamicdefault,
b'perf',
b'stub',
default=mercurial.configitems.dynamicdefault,
)
configitem(
b'perf', b'parentscount', default=mercurial.configitems.dynamicdefault,
b'perf',
b'parentscount',
default=mercurial.configitems.dynamicdefault,
)
configitem(
b'perf', b'all-timing', default=mercurial.configitems.dynamicdefault,
b'perf',
b'all-timing',
default=mercurial.configitems.dynamicdefault,
)
configitem(
b'perf', b'pre-run', default=mercurial.configitems.dynamicdefault,
b'perf',
b'pre-run',
default=mercurial.configitems.dynamicdefault,
)
configitem(
b'perf',
......@@ -330,7 +342,9 @@ except TypeError:
default=mercurial.configitems.dynamicdefault,
)
configitem(
b'perf', b'run-limits', default=mercurial.configitems.dynamicdefault,
b'perf',
b'run-limits',
default=mercurial.configitems.dynamicdefault,
)
......@@ -385,8 +399,7 @@ def gettimer(ui, opts=None):
from mercurial import node
class defaultformatter(object):
"""Minimized composition of baseformatter and plainformatter
"""
"""Minimized composition of baseformatter and plainformatter"""
def __init__(self, ui, topic, opts):
self._ui = ui
......@@ -658,8 +671,7 @@ def getbranchmapsubsettable():
def getsvfs(repo):
"""Return appropriate object to access files under .hg/store
"""
"""Return appropriate object to access files under .hg/store"""
# for "historical portability":
# repo.svfs has been available since 2.3 (or 7034365089bf)
svfs = getattr(repo, 'svfs', None)
......@@ -670,8 +682,7 @@ def getsvfs(repo):
def getvfs(repo):
"""Return appropriate object to access files under .hg
"""
"""Return appropriate object to access files under .hg"""
# for "historical portability":
# repo.vfs has been available since 2.3 (or 7034365089bf)
vfs = getattr(repo, 'vfs', None)
......@@ -682,8 +693,7 @@ def getvfs(repo):
def repocleartagscachefunc(repo):
"""Return the function to clear tags cache according to repo internal API
"""
"""Return the function to clear tags cache according to repo internal API"""
if util.safehasattr(repo, b'_tagscache'): # since 2.0 (or 9dca7653b525)
# in this case, setattr(repo, '_tagscache', None) or so isn't
# correct way to clear tags cache, because existing code paths
......@@ -847,7 +857,9 @@ def perfheads(ui, repo, **opts):
@command(
b'perftags',
formatteropts
+ [(b'', b'clear-revlogs', False, b'refresh changelog and manifest'),],
+ [
(b'', b'clear-revlogs', False, b'refresh changelog and manifest'),
],
)
def perftags(ui, repo, **opts):
opts = _byteskwargs(opts)
......@@ -900,8 +912,7 @@ def perfancestorset(ui, repo, revset, **opts):
@command(b'perfdiscovery', formatteropts, b'PATH')
def perfdiscovery(ui, repo, path, **opts):
"""benchmark discovery between local repo and the peer at given path
"""
"""benchmark discovery between local repo and the peer at given path"""
repos = [repo, None]
timer, fm = gettimer(ui, opts)
path = ui.expandpath(path)
......@@ -919,7 +930,9 @@ def perfdiscovery(ui, repo, path, **opts):
@command(
b'perfbookmarks',
formatteropts
+ [(b'', b'clear-revlogs', False, b'refresh changelog and manifest'),],
+ [
(b'', b'clear-revlogs', False, b'refresh changelog and manifest'),
],
)
def perfbookmarks(ui, repo, **opts):
"""benchmark parsing bookmarks from disk to memory"""
......@@ -1184,8 +1197,7 @@ def perfdirstate(ui, repo, **opts):
@command(b'perfdirstatedirs', formatteropts)
def perfdirstatedirs(ui, repo, **opts):
"""benchmap a 'dirstate.hasdir' call from an empty `dirs` cache
"""
"""benchmap a 'dirstate.hasdir' call from an empty `dirs` cache"""
opts = _byteskwargs(opts)
timer, fm = gettimer(ui, opts)
repo.dirstate.hasdir(b"a")
......@@ -1245,8 +1257,7 @@ def perfdirfoldmap(ui, repo, **opts):
@command(b'perfdirstatewrite', formatteropts)
def perfdirstatewrite(ui, repo, **opts):
"""benchmap the time it take to write a dirstate on disk
"""
"""benchmap the time it take to write a dirstate on disk"""
opts = _byteskwargs(opts)
timer, fm = gettimer(ui, opts)
ds = repo.dirstate
......@@ -1359,7 +1370,9 @@ def perfpathcopies(ui, repo, rev1, rev2, **opts):
@command(
b'perfphases',
[(b'', b'full', False, b'include file reading time too'),],
[
(b'', b'full', False, b'include file reading time too'),
],
b"",
)
def perfphases(ui, repo, **opts):
......@@ -1839,7 +1852,10 @@ def perfmoonwalk(ui, repo, **opts):
@command(
b'perftemplating',
[(b'r', b'rev', [], b'revisions to run the template on'),] + formatteropts,
[
(b'r', b'rev', [], b'revisions to run the template on'),
]
+ formatteropts,
)
def perftemplating(ui, repo, testedtemplate=None, **opts):
"""test the rendering time of a given template"""
......@@ -2193,10 +2209,18 @@ def perfhelperpathcopies(ui, repo, revs=[], **opts):
}
if dostats:
alldata['nbrevs'].append(