py3: fix test-help.t

Reviewed By: xavierd

Differential Revision: D20953745

fbshipit-source-id: 7d6dd303e5789ae8c0a6a32ed40d884aa1f24803
This commit is contained in:
Jun Wu 2020-04-09 18:20:36 -07:00 committed by Facebook GitHub Bot
parent 3e38bb9b6a
commit 73f93a438b
6 changed files with 22 additions and 25 deletions

15
eden/scm/doc/check-seclevel.py Executable file → Normal file
View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# Portions Copyright (c) Facebook, Inc. and its affiliates. # Portions Copyright (c) Facebook, Inc. and its affiliates.
# #
# This software may be used and distributed according to the terms of the # This software may be used and distributed according to the terms of the
@ -36,8 +35,8 @@ demandimport.enable()
table = commands.table table = commands.table
helptable = help.helptable helptable = help.helptable
level2mark = [b'"', b"=", b"-", b".", b"#"] level2mark = ['"', "=", "-", ".", "#"]
reservedmarks = [b'"'] reservedmarks = ['"']
mark2level = {} mark2level = {}
for m, l in zip(level2mark, range(len(level2mark))): for m, l in zip(level2mark, range(len(level2mark))):
@ -59,16 +58,14 @@ def showavailables(ui, initlevel):
def checkseclevel(ui, doc, name, initlevel): def checkseclevel(ui, doc, name, initlevel):
ui.note(('checking "%s"\n') % name) ui.note(('checking "%s"\n') % name)
if not isinstance(doc, bytes):
doc = doc.encode("utf-8")
blocks, pruned = minirst.parse(doc, 0, ["verbose"]) blocks, pruned = minirst.parse(doc, 0, ["verbose"])
errorcnt = 0 errorcnt = 0
curlevel = initlevel curlevel = initlevel
for block in blocks: for block in blocks:
if block[b"type"] != b"section": if block["type"] != "section":
continue continue
mark = block[b"underline"] mark = block["underline"]
title = block[b"lines"][0] title = block["lines"][0]
if (mark not in mark2level) or (mark2level[mark] <= initlevel): if (mark not in mark2level) or (mark2level[mark] <= initlevel):
ui.warn( ui.warn(
( (
@ -97,7 +94,7 @@ def checkseclevel(ui, doc, name, initlevel):
def checkcmdtable(ui, cmdtable, namefmt, initlevel): def checkcmdtable(ui, cmdtable, namefmt, initlevel):
errorcnt = 0 errorcnt = 0
for k, entry in cmdtable.items(): for k, entry in cmdtable.items():
name = k.split(b"|")[0].lstrip(b"^") name = k.split("|")[0].lstrip("^")
if not entry[0].__doc__: if not entry[0].__doc__:
ui.note(("skip checking %s: no help document\n") % (namefmt % name)) ui.note(("skip checking %s: no help document\n") % (namefmt % name))
continue continue

View File

@ -98,7 +98,11 @@ class LazyFinder(object):
def find_spec(self, *args, **kwargs): def find_spec(self, *args, **kwargs):
finder = object.__getattribute__(self, "_finder") finder = object.__getattribute__(self, "_finder")
spec = finder.find_spec(*args, **kwargs) find_spec = getattr(finder, "find_spec", None)
if find_spec:
spec = find_spec(*args, **kwargs)
else:
spec = None
# Lazy loader requires exec_module(). # Lazy loader requires exec_module().
if ( if (

View File

@ -821,8 +821,6 @@ def _parse(ui, args):
# combine global options into local # combine global options into local
c += commands.globalopts c += commands.globalopts
# for o in commands.globalopts:
# c.append((o[0], o[1], options[o[1]], o[3]))
try: try:
flagdefs = [(flagdef[0], flagdef[1], flagdef[2]) for flagdef in c] flagdefs = [(flagdef[0], flagdef[1], flagdef[2]) for flagdef in c]

View File

@ -280,8 +280,7 @@ def makeitemsdoc(ui, topic, doc, marker, items, dedent=False):
continue continue
text = gettext(text) text = gettext(text)
if dedent: if dedent:
# Abuse latin1 to use textwrap.dedent() on bytes. text = textwrap.dedent(text)
text = textwrap.dedent(text.decode("latin1")).encode("latin1")
lines = text.splitlines() lines = text.splitlines()
doclines = [(lines[0])] doclines = [(lines[0])]
for l in lines[1:]: for l in lines[1:]:

View File

@ -281,10 +281,10 @@ impl ToPyObject for Flag {
fn to_py_object(&self, py: Python) -> Self::ObjectType { fn to_py_object(&self, py: Python) -> Self::ObjectType {
( (
Bytes::from(self.short_name.map(|s| s.to_string()).unwrap_or_default()), Str::from(self.short_name.map(|s| s.to_string()).unwrap_or_default()),
Bytes::from(self.long_name.to_string()), Str::from(self.long_name.to_string()),
&self.default_value, &self.default_value,
Bytes::from(self.description.to_string()), Str::from(self.description.to_string()),
) )
.to_py_object(py) .to_py_object(py)
.into_object() .into_object()

View File

@ -1,4 +1,3 @@
#require py2
#chg-compatible #chg-compatible
#require no-fsmonitor #require no-fsmonitor
@ -781,14 +780,14 @@ this is a section and erroring out weirdly.
> command = registrar.command(cmdtable) > command = registrar.command(cmdtable)
> >
> @command('nohelp', > @command('nohelp',
> [(b'', b'longdesc', 3, b'x'*90), > [('', 'longdesc', 3, 'x'*90),
> (b'n', b'', None, b'normal desc'), > ('n', '', None, 'normal desc'),
> (b'', b'newline', b'', b'line1\nline2')], > ('', 'newline', '', 'line1\nline2')],
> b'hg nohelp', > 'hg nohelp',
> norepo=True) > norepo=True)
> @command('debugoptADV', [(b'', b'aopt', None, b'option is (ADVANCED)')]) > @command('debugoptADV', [('', 'aopt', None, 'option is (ADVANCED)')])
> @command('debugoptDEP', [(b'', b'dopt', None, b'option is (DEPRECATED)')]) > @command('debugoptDEP', [('', 'dopt', None, 'option is (DEPRECATED)')])
> @command('debugoptEXP', [(b'', b'eopt', None, b'option is (EXPERIMENTAL)')]) > @command('debugoptEXP', [('', 'eopt', None, 'option is (EXPERIMENTAL)')])
> def nohelp(ui, *args, **kwargs): > def nohelp(ui, *args, **kwargs):
> pass > pass
> >