mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 15:03:39 +02:00
py: Various flake8 cleanups
None of these are particularly significant, but they do get the CI output clean. Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
@@ -21,8 +21,6 @@
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
import sys
|
||||
|
||||
from . import config
|
||||
from . import utils
|
||||
from . import dbustypes
|
||||
@@ -37,6 +35,10 @@ LICENSE_STR = """/*
|
||||
*/\n"""
|
||||
|
||||
|
||||
# Disable line length warnings as wrapping the C code templates would be hard
|
||||
# flake8: noqa: E501
|
||||
|
||||
|
||||
def generate_namespace(namespace):
|
||||
ns = namespace
|
||||
if len(namespace) > 0:
|
||||
@@ -163,7 +165,7 @@ class HeaderCodeGenerator:
|
||||
key = (m.since, "_method_%s" % m.name_lower)
|
||||
value = " gboolean (*handle_%s) (\n" % (m.name_lower)
|
||||
value += " %s *object,\n" % (i.camel_name)
|
||||
value += " GDBusMethodInvocation *invocation" % ()
|
||||
value += " GDBusMethodInvocation *invocation"
|
||||
if m.unix_fd:
|
||||
value += ",\n GUnixFDList *fd_list"
|
||||
for a in m.in_args:
|
||||
@@ -369,7 +371,7 @@ class HeaderCodeGenerator:
|
||||
"%s%s_get_%s (%s *object);\n"
|
||||
% (p.arg.ctype_in, i.name_lower, p.name_lower, i.camel_name)
|
||||
)
|
||||
if p.arg.free_func != None:
|
||||
if p.arg.free_func is not None:
|
||||
if self.symbol_decorator is not None:
|
||||
self.outfile.write("%s\n" % self.symbol_decorator)
|
||||
if p.deprecated:
|
||||
@@ -2342,7 +2344,7 @@ class CodeGenerator:
|
||||
False,
|
||||
)
|
||||
)
|
||||
if p.arg.free_func != None:
|
||||
if p.arg.free_func is not None:
|
||||
self.outfile.write(
|
||||
" * The returned value is only valid until the property changes so on the client-side it is only safe to use this function on the thread where @object was constructed. Use %s_dup_%s() if on another thread.\n"
|
||||
" *\n"
|
||||
@@ -2363,7 +2365,7 @@ class CodeGenerator:
|
||||
)
|
||||
self.outfile.write("}\n")
|
||||
self.outfile.write("\n")
|
||||
if p.arg.free_func != None:
|
||||
if p.arg.free_func is not None:
|
||||
|
||||
self.outfile.write(
|
||||
self.docbook_gen.expand(
|
||||
@@ -3082,7 +3084,7 @@ class CodeGenerator:
|
||||
# property vfuncs
|
||||
for p in i.properties:
|
||||
nul_value = "0"
|
||||
if p.arg.free_func != None:
|
||||
if p.arg.free_func is not None:
|
||||
nul_value = "NULL"
|
||||
self.outfile.write(
|
||||
"static %s\n"
|
||||
@@ -3544,7 +3546,7 @@ class CodeGenerator:
|
||||
)
|
||||
self.outfile.write(
|
||||
" info = (_ExtendedGDBusMethodInfo *) g_dbus_method_invocation_get_method_info (invocation);\n"
|
||||
" g_assert (info != NULL);\n" % ()
|
||||
" g_assert (info != NULL);\n"
|
||||
)
|
||||
self.outfile.write(
|
||||
" num_params = g_variant_n_children (parameters);\n"
|
||||
@@ -4006,7 +4008,7 @@ class CodeGenerator:
|
||||
" g_value_copy (orig_value, &cp->orig_value);\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n" % ()
|
||||
"\n"
|
||||
)
|
||||
|
||||
# Postpone setting up the refresh source until the ::notify signal is emitted as
|
||||
@@ -4506,7 +4508,7 @@ class CodeGenerator:
|
||||
" G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);\n"
|
||||
% (self.ns_lower)
|
||||
)
|
||||
self.outfile.write("}\n" "\n" % ())
|
||||
self.outfile.write("}\n" "\n")
|
||||
self.outfile.write(
|
||||
"static void\n"
|
||||
"%sobject_proxy_get_property (GObject *gobject,\n"
|
||||
@@ -4536,7 +4538,7 @@ class CodeGenerator:
|
||||
" break;\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n" % ()
|
||||
"\n"
|
||||
)
|
||||
self.outfile.write(
|
||||
"static void\n"
|
||||
@@ -4685,7 +4687,7 @@ class CodeGenerator:
|
||||
" break;\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n" % ()
|
||||
"\n"
|
||||
)
|
||||
self.outfile.write(
|
||||
"static void\n"
|
||||
@@ -4716,7 +4718,7 @@ class CodeGenerator:
|
||||
" break;\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n" % ()
|
||||
"\n"
|
||||
)
|
||||
self.outfile.write(
|
||||
"static void\n"
|
||||
|
@@ -19,14 +19,15 @@
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
import sys
|
||||
import re
|
||||
from os import path
|
||||
|
||||
from . import config
|
||||
from . import utils
|
||||
from . import dbustypes
|
||||
from . import parser
|
||||
|
||||
|
||||
# Disable line length warnings as wrapping the Docbook templates would be hard
|
||||
# flake8: noqa: E501
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -167,31 +168,31 @@ class DocbookCodeGenerator:
|
||||
self.out.write(" %s %s\n" % (access, p.signature))
|
||||
|
||||
def print_synopsis_methods(self, i):
|
||||
self.out.write(' <refsynopsisdiv role="synopsis">\n' % ())
|
||||
self.out.write(' <title role="synopsis.title">Methods</title>\n' % ())
|
||||
self.out.write(" <synopsis>\n" % ())
|
||||
self.out.write(' <refsynopsisdiv role="synopsis">\n')
|
||||
self.out.write(' <title role="synopsis.title">Methods</title>\n')
|
||||
self.out.write(" <synopsis>\n")
|
||||
for m in i.methods:
|
||||
self.print_method_prototype(i, m, in_synopsis=True)
|
||||
self.out.write("</synopsis>\n" % ())
|
||||
self.out.write(" </refsynopsisdiv>\n" % ())
|
||||
self.out.write("</synopsis>\n")
|
||||
self.out.write(" </refsynopsisdiv>\n")
|
||||
|
||||
def print_synopsis_signals(self, i):
|
||||
self.out.write(' <refsect1 role="signal_proto">\n' % ())
|
||||
self.out.write(' <title role="signal_proto.title">Signals</title>\n' % ())
|
||||
self.out.write(" <synopsis>\n" % ())
|
||||
self.out.write(' <refsect1 role="signal_proto">\n')
|
||||
self.out.write(' <title role="signal_proto.title">Signals</title>\n')
|
||||
self.out.write(" <synopsis>\n")
|
||||
for s in i.signals:
|
||||
self.print_signal_prototype(i, s, in_synopsis=True)
|
||||
self.out.write("</synopsis>\n" % ())
|
||||
self.out.write(" </refsect1>\n" % ())
|
||||
self.out.write("</synopsis>\n")
|
||||
self.out.write(" </refsect1>\n")
|
||||
|
||||
def print_synopsis_properties(self, i):
|
||||
self.out.write(' <refsect1 role="properties">\n' % ())
|
||||
self.out.write(' <title role="properties.title">Properties</title>\n' % ())
|
||||
self.out.write(" <synopsis>\n" % ())
|
||||
self.out.write(' <refsect1 role="properties">\n')
|
||||
self.out.write(' <title role="properties.title">Properties</title>\n')
|
||||
self.out.write(" <synopsis>\n")
|
||||
for p in i.properties:
|
||||
self.print_property_prototype(i, p, in_synopsis=True)
|
||||
self.out.write("</synopsis>\n" % ())
|
||||
self.out.write(" </refsect1>\n" % ())
|
||||
self.out.write("</synopsis>\n")
|
||||
self.out.write(" </refsect1>\n")
|
||||
|
||||
def print_method(self, i, m):
|
||||
self.out.write(
|
||||
@@ -217,7 +218,7 @@ class DocbookCodeGenerator:
|
||||
if m.in_args or m.out_args:
|
||||
self.out.write('<variablelist role="params">\n')
|
||||
for a in m.in_args:
|
||||
self.out.write("<varlistentry>\n" % ())
|
||||
self.out.write("<varlistentry>\n")
|
||||
self.out.write(
|
||||
" <term><literal>IN %s <parameter>%s</parameter></literal>:</term>\n"
|
||||
% (a.signature, a.name)
|
||||
@@ -226,9 +227,9 @@ class DocbookCodeGenerator:
|
||||
" <listitem>%s</listitem>\n"
|
||||
% (self.expand_paras(a.doc_string, True))
|
||||
)
|
||||
self.out.write("</varlistentry>\n" % ())
|
||||
self.out.write("</varlistentry>\n")
|
||||
for a in m.out_args:
|
||||
self.out.write("<varlistentry>\n" % ())
|
||||
self.out.write("<varlistentry>\n")
|
||||
self.out.write(
|
||||
" <term><literal>OUT %s <parameter>%s</parameter></literal>:</term>\n"
|
||||
% (a.signature, a.name)
|
||||
@@ -237,7 +238,7 @@ class DocbookCodeGenerator:
|
||||
" <listitem>%s</listitem>\n"
|
||||
% (self.expand_paras(a.doc_string, True))
|
||||
)
|
||||
self.out.write("</varlistentry>\n" % ())
|
||||
self.out.write("</varlistentry>\n")
|
||||
self.out.write("</variablelist>\n")
|
||||
if len(m.since) > 0:
|
||||
self.out.write('<para role="since">Since %s</para>\n' % (m.since))
|
||||
@@ -272,7 +273,7 @@ class DocbookCodeGenerator:
|
||||
if s.args:
|
||||
self.out.write('<variablelist role="params">\n')
|
||||
for a in s.args:
|
||||
self.out.write("<varlistentry>\n" % ())
|
||||
self.out.write("<varlistentry>\n")
|
||||
self.out.write(
|
||||
" <term><literal>%s <parameter>%s</parameter></literal>:</term>\n"
|
||||
% (a.signature, a.name)
|
||||
@@ -281,7 +282,7 @@ class DocbookCodeGenerator:
|
||||
" <listitem>%s</listitem>\n"
|
||||
% (self.expand_paras(a.doc_string, True))
|
||||
)
|
||||
self.out.write("</varlistentry>\n" % ())
|
||||
self.out.write("</varlistentry>\n")
|
||||
self.out.write("</variablelist>\n")
|
||||
if len(s.since) > 0:
|
||||
self.out.write('<para role="since">Since %s</para>\n' % (s.since))
|
||||
@@ -394,19 +395,17 @@ class DocbookCodeGenerator:
|
||||
def generate(self, docbook, outdir):
|
||||
for i in self.ifaces:
|
||||
self.out = open(path.join(outdir, "%s-%s.xml" % (docbook, i.name)), "w")
|
||||
self.out.write("" % ())
|
||||
self.out.write('<?xml version="1.0" encoding="utf-8"?>\n' % ())
|
||||
self.out.write("")
|
||||
self.out.write('<?xml version="1.0" encoding="utf-8"?>\n')
|
||||
self.out.write(
|
||||
'<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"\n'
|
||||
% ()
|
||||
)
|
||||
self.out.write(
|
||||
' "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [\n'
|
||||
% ()
|
||||
)
|
||||
self.out.write("]>\n" % ())
|
||||
self.out.write("]>\n")
|
||||
self.out.write('<refentry id="gdbus-%s">\n' % (i.name))
|
||||
self.out.write(" <refmeta>" % ())
|
||||
self.out.write(" <refmeta>")
|
||||
self.out.write(
|
||||
' <refentrytitle role="top_of_page" id="gdbus-interface-%s.top_of_page">%s</refentrytitle>\n'
|
||||
% (utils.dots_to_hyphens(i.name), i.name)
|
||||
@@ -415,12 +414,12 @@ class DocbookCodeGenerator:
|
||||
' <indexterm zone="gdbus-interface-%s.top_of_page"><primary sortas="%s">%s</primary></indexterm>\n'
|
||||
% (utils.dots_to_hyphens(i.name), i.name_without_prefix, i.name)
|
||||
)
|
||||
self.out.write(" </refmeta>" % ())
|
||||
self.out.write(" </refmeta>")
|
||||
|
||||
self.out.write(" <refnamediv>" % ())
|
||||
self.out.write(" <refnamediv>")
|
||||
self.out.write(" <refname>%s</refname>" % (i.name))
|
||||
self.out.write(" <refpurpose>%s</refpurpose>" % (i.doc_string_brief))
|
||||
self.out.write(" </refnamediv>" % ())
|
||||
self.out.write(" </refnamediv>")
|
||||
|
||||
if len(i.methods) > 0:
|
||||
self.print_synopsis_methods(i)
|
||||
@@ -433,7 +432,7 @@ class DocbookCodeGenerator:
|
||||
'<refsect1 role="desc" id="gdbus-interface-%s">\n'
|
||||
% (utils.dots_to_hyphens(i.name))
|
||||
)
|
||||
self.out.write(' <title role="desc.title">Description</title>\n' % ())
|
||||
self.out.write(' <title role="desc.title">Description</title>\n')
|
||||
self.out.write(" %s\n" % (self.expand_paras(i.doc_string, True)))
|
||||
if len(i.since) > 0:
|
||||
self.out.write(' <para role="since">Since %s</para>\n' % (i.since))
|
||||
@@ -442,40 +441,36 @@ class DocbookCodeGenerator:
|
||||
"<warning><para>The %s interface is deprecated.</para></warning>"
|
||||
% (i.name)
|
||||
)
|
||||
self.out.write("</refsect1>\n" % ())
|
||||
self.out.write("</refsect1>\n")
|
||||
|
||||
if len(i.methods) > 0:
|
||||
self.out.write(
|
||||
'<refsect1 role="details" id="gdbus-methods-%s">\n' % (i.name)
|
||||
)
|
||||
self.out.write(
|
||||
' <title role="details.title">Method Details</title>\n' % ()
|
||||
)
|
||||
self.out.write(' <title role="details.title">Method Details</title>\n')
|
||||
for m in i.methods:
|
||||
self.print_method(i, m)
|
||||
self.out.write("</refsect1>\n" % ())
|
||||
self.out.write("</refsect1>\n")
|
||||
|
||||
if len(i.signals) > 0:
|
||||
self.out.write(
|
||||
'<refsect1 role="details" id="gdbus-signals-%s">\n' % (i.name)
|
||||
)
|
||||
self.out.write(
|
||||
' <title role="details.title">Signal Details</title>\n' % ()
|
||||
)
|
||||
self.out.write(' <title role="details.title">Signal Details</title>\n')
|
||||
for s in i.signals:
|
||||
self.print_signal(i, s)
|
||||
self.out.write("</refsect1>\n" % ())
|
||||
self.out.write("</refsect1>\n")
|
||||
|
||||
if len(i.properties) > 0:
|
||||
self.out.write(
|
||||
'<refsect1 role="details" id="gdbus-properties-%s">\n' % (i.name)
|
||||
)
|
||||
self.out.write(
|
||||
' <title role="details.title">Property Details</title>\n' % ()
|
||||
' <title role="details.title">Property Details</title>\n'
|
||||
)
|
||||
for s in i.properties:
|
||||
self.print_property(i, s)
|
||||
self.out.write("</refsect1>\n" % ())
|
||||
self.out.write("</refsect1>\n")
|
||||
|
||||
self.out.write("</refentry>\n")
|
||||
self.out.write("\n")
|
||||
|
@@ -226,24 +226,29 @@ def codegen_main():
|
||||
arg_parser.add_argument(
|
||||
"--glib-min-required",
|
||||
metavar="VERSION",
|
||||
help="Minimum version of GLib to be supported by the outputted code (default: 2.30)",
|
||||
help="Minimum version of GLib to be supported by the outputted code "
|
||||
"(default: 2.30)",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--glib-max-allowed",
|
||||
metavar="VERSION",
|
||||
help="Maximum version of GLib to be used by the outputted code (default: current GLib version)",
|
||||
help="Maximum version of GLib to be used by the outputted code "
|
||||
"(default: current GLib version)",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--symbol-decorator",
|
||||
help="Macro used to decorate a symbol in the outputted header, possibly to export symbols",
|
||||
help="Macro used to decorate a symbol in the outputted header, "
|
||||
"possibly to export symbols",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--symbol-decorator-header",
|
||||
help="Additional header required for decorator specified by --symbol-decorator",
|
||||
help="Additional header required for decorator specified by "
|
||||
"--symbol-decorator",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--symbol-decorator-define",
|
||||
help="Additional define required for decorator specified by --symbol-decorator",
|
||||
help="Additional define required for decorator specified by "
|
||||
"--symbol-decorator",
|
||||
)
|
||||
|
||||
group = arg_parser.add_mutually_exclusive_group()
|
||||
@@ -370,11 +375,13 @@ def codegen_main():
|
||||
else:
|
||||
glib_max_allowed = (config.MAJOR_VERSION, config.MINOR_VERSION)
|
||||
|
||||
# Only allow --symbol-decorator-define and --symbol-decorator-header if --symbol-decorator is used
|
||||
# Only allow --symbol-decorator-define and --symbol-decorator-header if
|
||||
# --symbol-decorator is used
|
||||
if args.symbol_decorator is None:
|
||||
if args.symbol_decorator_header or args.symbol_decorator_define:
|
||||
print_error(
|
||||
"--symbol-decorator-define and --symbol-decorator-header must be used with --symbol-decorator"
|
||||
"--symbol-decorator-define and --symbol-decorator-header must "
|
||||
"be used with --symbol-decorator"
|
||||
)
|
||||
|
||||
# Round --glib-max-allowed up to the next stable release.
|
||||
@@ -411,7 +418,7 @@ def codegen_main():
|
||||
docbook = args.generate_docbook
|
||||
docbook_gen = codegen_docbook.DocbookCodeGenerator(all_ifaces)
|
||||
if docbook:
|
||||
ret = docbook_gen.generate(docbook, args.output_directory)
|
||||
docbook_gen.generate(docbook, args.output_directory)
|
||||
|
||||
if args.header:
|
||||
with open(h_file, "w") as outfile:
|
||||
|
@@ -414,7 +414,8 @@ class Property:
|
||||
name = overridden_name
|
||||
self.name_lower = utils.camel_case_to_uscore(name).lower().replace("-", "_")
|
||||
self.name_hyphen = self.name_lower.replace("_", "-")
|
||||
# don't clash with the GType getter, e.g.: GType foo_bar_get_type (void); G_GNUC_CONST
|
||||
# don't clash with the GType getter, e.g.:
|
||||
# GType foo_bar_get_type (void); G_GNUC_CONST
|
||||
if self.name_lower == "type":
|
||||
self.name_lower = "type_"
|
||||
|
||||
@@ -431,7 +432,8 @@ class Property:
|
||||
for a in self.annotations:
|
||||
a.post_process(interface_prefix, cns, cns_upper, cns_lower, self)
|
||||
|
||||
# FIXME: for now we only support 'false' and 'const' on the signal itself, see #674913 and
|
||||
# FIXME: for now we only support 'false' and 'const' on the signal itself,
|
||||
# see #674913 and
|
||||
# http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format
|
||||
# for details
|
||||
if utils.lookup_annotation(
|
||||
|
@@ -19,7 +19,6 @@
|
||||
#
|
||||
# Author: David Zeuthen <davidz@redhat.com>
|
||||
|
||||
import sys
|
||||
import xml.parsers.expat
|
||||
|
||||
from . import dbustypes
|
||||
@@ -222,7 +221,7 @@ class DBusXMLParser:
|
||||
if self.doc_comment_last_symbol == old_cur_object.name:
|
||||
if "name" in attrs and attrs["name"] in self.doc_comment_params:
|
||||
doc_string = self.doc_comment_params[attrs["name"]]
|
||||
if doc_string != None:
|
||||
if doc_string is not None:
|
||||
self._cur_object.doc_string = doc_string
|
||||
if "since" in self.doc_comment_params:
|
||||
self._cur_object.since = self.doc_comment_params[
|
||||
@@ -250,7 +249,7 @@ class DBusXMLParser:
|
||||
if self.doc_comment_last_symbol == old_cur_object.name:
|
||||
if "name" in attrs and attrs["name"] in self.doc_comment_params:
|
||||
doc_string = self.doc_comment_params[attrs["name"]]
|
||||
if doc_string != None:
|
||||
if doc_string is not None:
|
||||
self._cur_object.doc_string = doc_string
|
||||
if "since" in self.doc_comment_params:
|
||||
self._cur_object.since = self.doc_comment_params[
|
||||
|
@@ -23,6 +23,7 @@ import distutils.version
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class Color:
|
||||
"""ANSI Terminal colors"""
|
||||
|
Reference in New Issue
Block a user