From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Eduardo Habkost" <ehabkost@redhat.com>,
"Michael Roth" <michael.roth@amd.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Cleber Rosa" <crosa@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"John Snow" <jsnow@redhat.com>
Subject: [PATCH v2 05/12] qapi/gen: use './builtin' for the built-in module name
Date: Wed, 16 Dec 2020 20:59:20 -0500 [thread overview]
Message-ID: <20201217015927.197287-6-jsnow@redhat.com> (raw)
In-Reply-To: <20201217015927.197287-1-jsnow@redhat.com>
Use this in preference to 'None', which helps remove some edge cases in
the typing.
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qapi/gen.py | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index a6dc991b1d0..476d0adac4e 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -245,23 +245,23 @@ def __init__(self,
self._pydoc = pydoc
self._genc: Optional[QAPIGenC] = None
self._genh: Optional[QAPIGenH] = None
- self._module: Dict[Optional[str], Tuple[QAPIGenC, QAPIGenH]] = {}
+ self._module: Dict[str, Tuple[QAPIGenC, QAPIGenH]] = {}
self._main_module: Optional[str] = None
@staticmethod
- def _is_user_module(name: Optional[str]) -> bool:
- return bool(name and not name.startswith('./'))
+ def _is_user_module(name: str) -> bool:
+ return not name.startswith('./')
@staticmethod
- def _is_builtin_module(name: Optional[str]) -> bool:
- return not name
+ def _is_builtin_module(name: str) -> bool:
+ return name == './builtin'
- def _module_dirname(self, name: Optional[str]) -> str:
+ def _module_dirname(self, name: str) -> str:
if self._is_user_module(name):
return os.path.dirname(name)
return ''
- def _module_basename(self, what: str, name: Optional[str]) -> str:
+ def _module_basename(self, what: str, name: str) -> str:
ret = '' if self._is_builtin_module(name) else self._prefix
if self._is_user_module(name):
basename = os.path.basename(name)
@@ -269,15 +269,15 @@ def _module_basename(self, what: str, name: Optional[str]) -> str:
if name != self._main_module:
ret += '-' + os.path.splitext(basename)[0]
else:
- name = name[2:] if name else 'builtin'
- ret += re.sub(r'-', '-' + name + '-', what)
+ assert name.startswith('./')
+ ret += re.sub(r'-', '-' + name[2:] + '-', what)
return ret
- def _module_filename(self, what: str, name: Optional[str]) -> str:
+ def _module_filename(self, what: str, name: str) -> str:
return os.path.join(self._module_dirname(name),
self._module_basename(what, name))
- def _add_module(self, name: Optional[str], blurb: str) -> None:
+ def _add_module(self, name: str, blurb: str) -> None:
basename = self._module_filename(self._what, name)
genc = QAPIGenC(basename + '.c', blurb, self._pydoc)
genh = QAPIGenH(basename + '.h', blurb, self._pydoc)
@@ -290,8 +290,8 @@ def _add_user_module(self, name: str, blurb: str) -> None:
self._main_module = name
self._add_module(name, blurb)
- def _add_system_module(self, name: Optional[str], blurb: str) -> None:
- self._add_module(name and './' + name, blurb)
+ def _add_system_module(self, name: str, blurb: str) -> None:
+ self._add_module('./' + name, blurb)
def write(self, output_dir: str, opt_builtins: bool = False) -> None:
for name in self._module:
@@ -310,7 +310,7 @@ def _begin_user_module(self, name: str) -> None:
def visit_module(self, name: Optional[str]) -> None:
if name is None:
if self._builtin_blurb:
- self._add_system_module(None, self._builtin_blurb)
+ self._add_system_module('builtin', self._builtin_blurb)
self._begin_system_module(name)
else:
# The built-in module has not been created. No code may
--
2.26.2
next prev parent reply other threads:[~2020-12-17 2:13 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-17 1:59 [PATCH v2 00/12] qapi: static typing conversion, pt1.5 John Snow
2020-12-17 1:59 ` [PATCH v2 01/12] qapi/commands: assert arg_type is not None John Snow
2020-12-17 1:59 ` [PATCH v2 02/12] qapi/events: fix visit_event typing John Snow
2020-12-17 1:59 ` [PATCH v2 03/12] qapi/main: handle theoretical None-return from re.match() John Snow
2020-12-17 1:59 ` [PATCH v2 04/12] qapi/gen: assert that _start_if is not None in _wrap_ifcond John Snow
2021-01-13 15:14 ` Markus Armbruster
2021-01-13 21:34 ` John Snow
2020-12-17 1:59 ` John Snow [this message]
2020-12-17 1:59 ` [PATCH v2 06/12] qapi/source: Add builtin null-object sentinel John Snow
2021-01-13 15:39 ` Markus Armbruster
2021-01-13 22:30 ` John Snow
2021-01-14 13:39 ` Markus Armbruster
2021-01-18 18:36 ` Eduardo Habkost
2021-01-19 10:21 ` Markus Armbruster
2021-01-19 16:10 ` Eduardo Habkost
2020-12-17 1:59 ` [PATCH v2 07/12] qapi/schema: make QAPISourceInfo mandatory John Snow
2021-01-13 16:12 ` Markus Armbruster
2021-01-13 23:04 ` John Snow
2021-01-14 0:29 ` Eduardo Habkost
2021-01-14 0:47 ` John Snow
2020-12-17 1:59 ` [PATCH v2 08/12] qapi/gen: write _genc/_genh access shims John Snow
2020-12-17 1:59 ` [PATCH v2 09/12] qapi/gen: move write method to QAPIGenC, make fname a str John Snow
2020-12-17 1:59 ` [PATCH v2 10/12] tests/qapi-schema: Add quotes to module name in test output John Snow
2020-12-17 1:59 ` [PATCH v2 11/12] qapi/schema: Name the builtin module "" instead of None John Snow
2020-12-17 1:59 ` [PATCH v2 12/12] qapi: enable strict-optional checks John Snow
2021-01-13 16:23 ` [PATCH v2 00/12] qapi: static typing conversion, pt1.5 Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201217015927.197287-6-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=armbru@redhat.com \
--cc=crosa@redhat.com \
--cc=ehabkost@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=michael.roth@amd.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).