From de095fb24bfb8ccde737b4d79f8d3802d1e37f21 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 4 Apr 2024 11:11:29 +0200 Subject: [PATCH] gh-113317: Rename libclinic to argclinic * Rename Tools/clinic/libclinic/ to Tools/clinic/argclinic/ * Rename Tools/clinic/clinic.py to Tools/clinic/run_argclinic.py. * Add Tools/clinic/argclinic/__main__.py. * Convert absolute imports to imports related to the packages. For example, replace "from libclinic.cli import main" with "from .cli import main". * Remove "import clinic": import individual names. * "make clinic" now runs "python -m clinic". --- Lib/test/test_clinic.py | 62 +++--- Makefile.pre.in | 8 +- .../{libclinic => argclinic}/__init__.py | 0 Tools/clinic/argclinic/__main__.py | 2 + Tools/clinic/{libclinic => argclinic}/app.py | 25 ++- .../{libclinic => argclinic}/block_parser.py | 16 +- .../{libclinic => argclinic}/clanguage.py | 179 +++++++++--------- Tools/clinic/{libclinic => argclinic}/cli.py | 20 +- .../{libclinic => argclinic}/codegen.py | 15 +- .../{libclinic => argclinic}/converter.py | 18 +- .../{libclinic => argclinic}/converters.py | 8 +- Tools/clinic/{libclinic => argclinic}/cpp.py | 0 .../{libclinic => argclinic}/crenderdata.py | 0 .../{libclinic => argclinic}/dsl_parser.py | 37 ++-- .../clinic/{libclinic => argclinic}/errors.py | 0 .../{libclinic => argclinic}/formatting.py | 2 +- .../{libclinic => argclinic}/function.py | 12 +- .../{libclinic => argclinic}/identifiers.py | 0 .../{libclinic => argclinic}/language.py | 9 +- .../clinic/{libclinic => argclinic}/parser.py | 12 +- .../return_converters.py | 5 +- .../clinic/{libclinic => argclinic}/utils.py | 0 Tools/clinic/{clinic.py => run_argclinic.py} | 2 +- 23 files changed, 218 insertions(+), 214 deletions(-) rename Tools/clinic/{libclinic => argclinic}/__init__.py (100%) create mode 100644 Tools/clinic/argclinic/__main__.py rename Tools/clinic/{libclinic => argclinic}/app.py (94%) rename Tools/clinic/{libclinic => argclinic}/block_parser.py (94%) rename Tools/clinic/{libclinic => argclinic}/clanguage.py (89%) rename Tools/clinic/{libclinic => argclinic}/cli.py (94%) rename Tools/clinic/{libclinic => argclinic}/codegen.py (94%) rename Tools/clinic/{libclinic => argclinic}/converter.py (97%) rename Tools/clinic/{libclinic => argclinic}/converters.py (99%) rename Tools/clinic/{libclinic => argclinic}/cpp.py (100%) rename Tools/clinic/{libclinic => argclinic}/crenderdata.py (100%) rename Tools/clinic/{libclinic => argclinic}/dsl_parser.py (98%) rename Tools/clinic/{libclinic => argclinic}/errors.py (100%) rename Tools/clinic/{libclinic => argclinic}/formatting.py (99%) rename Tools/clinic/{libclinic => argclinic}/function.py (97%) rename Tools/clinic/{libclinic => argclinic}/identifiers.py (100%) rename Tools/clinic/{libclinic => argclinic}/language.py (94%) rename Tools/clinic/{libclinic => argclinic}/parser.py (80%) rename Tools/clinic/{libclinic => argclinic}/return_converters.py (98%) rename Tools/clinic/{libclinic => argclinic}/utils.py (100%) rename Tools/clinic/{clinic.py => run_argclinic.py} (85%) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 9788ac0261fa49..1a6ed1dfa1f54c 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -16,21 +16,25 @@ test_tools.skip_if_missing('clinic') with test_tools.imports_under_tool('clinic'): - import libclinic - from libclinic import ClinicError, unspecified, NULL, fail - from libclinic.converters import int_converter, str_converter, self_converter - from libclinic.function import ( + from argclinic import ClinicError, unspecified, NULL, fail + from argclinic.cpp import Monitor + from argclinic.formatting import ( + linear_format, normalize_snippet, docstring_for_c_string, + format_escape, indent_all_lines, suffix_all_lines, + ) + from argclinic.converters import int_converter, str_converter, self_converter + from argclinic.function import ( Module, Class, Function, FunctionKind, Parameter, permute_optional_groups, permute_right_option_groups, permute_left_option_groups) - import clinic - from libclinic.clanguage import CLanguage - from libclinic.converter import converters, legacy_converters - from libclinic.return_converters import return_converters, int_return_converter - from libclinic.block_parser import Block, BlockParser - from libclinic.codegen import BlockPrinter, Destination - from libclinic.dsl_parser import DSLParser - from libclinic.cli import parse_file, Clinic + import argclinic + from argclinic.clanguage import CLanguage + from argclinic.converter import converters, legacy_converters + from argclinic.return_converters import return_converters, int_return_converter + from argclinic.block_parser import Block, BlockParser + from argclinic.codegen import BlockPrinter, Destination + from argclinic.dsl_parser import DSLParser + from argclinic.cli import parse_file, Clinic, main def _make_clinic(*, filename='clinic_tests', limited_capi=False): @@ -738,7 +742,7 @@ def fn(): class ClinicLinearFormatTest(TestCase): def _test(self, input, output, **kwargs): - computed = libclinic.linear_format(input, **kwargs) + computed = linear_format(input, **kwargs) self.assertEqual(output, computed) def test_empty_strings(self): @@ -791,14 +795,14 @@ def test_multiline_substitution(self): def test_text_before_block_marker(self): regex = re.escape("found before '{marker}'") with self.assertRaisesRegex(ClinicError, regex): - libclinic.linear_format("no text before marker for you! {marker}", - marker="not allowed!") + linear_format("no text before marker for you! {marker}", + marker="not allowed!") def test_text_after_block_marker(self): regex = re.escape("found after '{marker}'") with self.assertRaisesRegex(ClinicError, regex): - libclinic.linear_format("{marker} no text after marker for you!", - marker="not allowed!") + linear_format("{marker} no text after marker for you!", + marker="not allowed!") class InertParser: @@ -2467,7 +2471,7 @@ def run_clinic(self, *args): support.captured_stderr() as err, self.assertRaises(SystemExit) as cm ): - clinic.main(args) + main(args) return out.getvalue(), err.getvalue(), cm.exception.code def expect_success(self, *args): @@ -3888,7 +3892,7 @@ def test_strip_leading_and_trailing_blank_lines(self): ) for lines, expected in dataset: with self.subTest(lines=lines, expected=expected): - out = libclinic.normalize_snippet(lines) + out = normalize_snippet(lines) self.assertEqual(out, expected) def test_normalize_snippet(self): @@ -3917,7 +3921,7 @@ def test_normalize_snippet(self): expected_outputs = {0: zero_indent, 4: four_indent, 8: eight_indent} for indent, expected in expected_outputs.items(): with self.subTest(indent=indent): - actual = libclinic.normalize_snippet(snippet, indent=indent) + actual = normalize_snippet(snippet, indent=indent) self.assertEqual(actual, expected) def test_escaped_docstring(self): @@ -3932,18 +3936,18 @@ def test_escaped_docstring(self): ) for line, expected in dataset: with self.subTest(line=line, expected=expected): - out = libclinic.docstring_for_c_string(line) + out = docstring_for_c_string(line) self.assertEqual(out, expected) def test_format_escape(self): line = "{}, {a}" expected = "{{}}, {{a}}" - out = libclinic.format_escape(line) + out = format_escape(line) self.assertEqual(out, expected) def test_indent_all_lines(self): # Blank lines are expected to be unchanged. - self.assertEqual(libclinic.indent_all_lines("", prefix="bar"), "") + self.assertEqual(indent_all_lines("", prefix="bar"), "") lines = ( "one\n" @@ -3953,7 +3957,7 @@ def test_indent_all_lines(self): "barone\n" "bartwo" ) - out = libclinic.indent_all_lines(lines, prefix="bar") + out = indent_all_lines(lines, prefix="bar") self.assertEqual(out, expected) # If last line is empty, expect it to be unchanged. @@ -3969,12 +3973,12 @@ def test_indent_all_lines(self): "bartwo\n" "" ) - out = libclinic.indent_all_lines(lines, prefix="bar") + out = indent_all_lines(lines, prefix="bar") self.assertEqual(out, expected) def test_suffix_all_lines(self): # Blank lines are expected to be unchanged. - self.assertEqual(libclinic.suffix_all_lines("", suffix="foo"), "") + self.assertEqual(suffix_all_lines("", suffix="foo"), "") lines = ( "one\n" @@ -3984,7 +3988,7 @@ def test_suffix_all_lines(self): "onefoo\n" "twofoo" ) - out = libclinic.suffix_all_lines(lines, suffix="foo") + out = suffix_all_lines(lines, suffix="foo") self.assertEqual(out, expected) # If last line is empty, expect it to be unchanged. @@ -4000,7 +4004,7 @@ def test_suffix_all_lines(self): "twofoo\n" "" ) - out = libclinic.suffix_all_lines(lines, suffix="foo") + out = suffix_all_lines(lines, suffix="foo") self.assertEqual(out, expected) @@ -4078,7 +4082,7 @@ def test_Function_and_Parameter_reprs(self): self.assertEqual(repr(parameter), "") def test_Monitor_repr(self): - monitor = libclinic.cpp.Monitor("test.c") + monitor = Monitor("test.c") self.assertRegex(repr(monitor), r"") monitor.line_number = 42 diff --git a/Makefile.pre.in b/Makefile.pre.in index 2a22a1e95a39a2..f6103501ac4338 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -846,14 +846,16 @@ coverage-report: regen-token regen-frozen @ # build lcov report $(MAKE) coverage-lcov +ARGCLINIC=PYTHONPATH="$(srcdir)/Tools/clinic" $(PYTHON_FOR_REGEN) -m argclinic + # Run "Argument Clinic" over all source files .PHONY: clinic clinic: check-clean-src $(srcdir)/Modules/_blake2/blake2s_impl.c - $(PYTHON_FOR_REGEN) $(srcdir)/Tools/clinic/clinic.py --make --exclude Lib/test/clinic.test.c --srcdir $(srcdir) + $(ARGCLINIC) --make --exclude Lib/test/clinic.test.c --srcdir $(srcdir) .PHONY: clinic-tests clinic-tests: check-clean-src $(srcdir)/Lib/test/clinic.test.c - $(PYTHON_FOR_REGEN) $(srcdir)/Tools/clinic/clinic.py -f $(srcdir)/Lib/test/clinic.test.c + $(ARGCLINIC) -f $(srcdir)/Lib/test/clinic.test.c # Build the interpreter $(BUILDPYTHON): Programs/python.o $(LINK_PYTHON_DEPS) @@ -881,7 +883,7 @@ pybuilddir.txt: $(PYTHON_FOR_BUILD_DEPS) # blake2s is auto-generated from blake2b $(srcdir)/Modules/_blake2/blake2s_impl.c: $(srcdir)/Modules/_blake2/blake2b_impl.c $(srcdir)/Modules/_blake2/blake2b2s.py $(PYTHON_FOR_REGEN) $(srcdir)/Modules/_blake2/blake2b2s.py - $(PYTHON_FOR_REGEN) $(srcdir)/Tools/clinic/clinic.py -f $@ + $(ARGCLINIC) -f $@ # Build static library $(LIBRARY): $(LIBRARY_OBJS) diff --git a/Tools/clinic/libclinic/__init__.py b/Tools/clinic/argclinic/__init__.py similarity index 100% rename from Tools/clinic/libclinic/__init__.py rename to Tools/clinic/argclinic/__init__.py diff --git a/Tools/clinic/argclinic/__main__.py b/Tools/clinic/argclinic/__main__.py new file mode 100644 index 00000000000000..130bc6375628df --- /dev/null +++ b/Tools/clinic/argclinic/__main__.py @@ -0,0 +1,2 @@ +from .cli import main +main() diff --git a/Tools/clinic/libclinic/app.py b/Tools/clinic/argclinic/app.py similarity index 94% rename from Tools/clinic/libclinic/app.py rename to Tools/clinic/argclinic/app.py index 47a897712d053e..080fec7bb39c10 100644 --- a/Tools/clinic/libclinic/app.py +++ b/Tools/clinic/argclinic/app.py @@ -5,19 +5,18 @@ from typing import Any, TYPE_CHECKING -import libclinic -from libclinic import fail, warn -from libclinic.function import Class -from libclinic.block_parser import Block, BlockParser -from libclinic.crenderdata import Include -from libclinic.codegen import BlockPrinter, Destination -from libclinic.parser import Parser, PythonParser -from libclinic.dsl_parser import DSLParser +from . import fail, warn, write_file +from .function import Class +from .block_parser import Block, BlockParser +from .crenderdata import Include +from .codegen import BlockPrinter, Destination +from .parser import Parser, PythonParser +from .dsl_parser import DSLParser if TYPE_CHECKING: - from libclinic.clanguage import CLanguage - from libclinic.function import ( + from .clanguage import CLanguage + from .function import ( Module, Function, ClassDict, ModuleDict) - from libclinic.codegen import DestinationDict + from .codegen import DestinationDict # maps strings to callables. @@ -260,8 +259,8 @@ def parse(self, input: str) -> str: core_includes=True, limited_capi=self.limited_capi, header_includes=self.includes) - libclinic.write_file(destination.filename, - printer_2.f.getvalue()) + write_file(destination.filename, + printer_2.f.getvalue()) continue return printer.f.getvalue() diff --git a/Tools/clinic/libclinic/block_parser.py b/Tools/clinic/argclinic/block_parser.py similarity index 94% rename from Tools/clinic/libclinic/block_parser.py rename to Tools/clinic/argclinic/block_parser.py index 4c0198b53592a9..c00fc57f9a9ce7 100644 --- a/Tools/clinic/libclinic/block_parser.py +++ b/Tools/clinic/argclinic/block_parser.py @@ -5,10 +5,9 @@ import shlex from typing import Any -import libclinic -from libclinic import fail, ClinicError -from libclinic.language import Language -from libclinic.function import ( +from . import fail, ClinicError, create_regex, compute_checksum +from .language import Language +from .function import ( Module, Class, Function) @@ -110,9 +109,8 @@ def __init__( self.language = language before, _, after = language.start_line.partition('{dsl_name}') assert _ == '{dsl_name}' - self.find_start_re = libclinic.create_regex(before, after, - whole_line=False) - self.start_re = libclinic.create_regex(before, after) + self.find_start_re = create_regex(before, after, whole_line=False) + self.start_re = create_regex(before, after) self.verify = verify self.last_checksum_re: re.Pattern[str] | None = None self.last_dsl_name: str | None = None @@ -206,7 +204,7 @@ def is_stop_line(line: str) -> bool: else: before, _, after = self.language.checksum_line.format(dsl_name=dsl_name, arguments='{arguments}').partition('{arguments}') assert _ == '{arguments}' - checksum_re = libclinic.create_regex(before, after, word=False) + checksum_re = create_regex(before, after, word=False) self.last_dsl_name = dsl_name self.last_checksum_re = checksum_re assert checksum_re is not None @@ -240,7 +238,7 @@ def is_stop_line(line: str) -> bool: else: checksum = d['checksum'] - computed = libclinic.compute_checksum(output, len(checksum)) + computed = compute_checksum(output, len(checksum)) if checksum != computed: fail("Checksum mismatch! " f"Expected {checksum!r}, computed {computed!r}. " diff --git a/Tools/clinic/libclinic/clanguage.py b/Tools/clinic/argclinic/clanguage.py similarity index 89% rename from Tools/clinic/libclinic/clanguage.py rename to Tools/clinic/argclinic/clanguage.py index ed08d12d8bfb29..a03cb0b74dcd85 100644 --- a/Tools/clinic/libclinic/clanguage.py +++ b/Tools/clinic/argclinic/clanguage.py @@ -6,20 +6,23 @@ from operator import attrgetter from collections.abc import Iterable -import libclinic -from libclinic import ( - unspecified, fail, warn, Sentinels, VersionTuple) -from libclinic.function import ( - GETTER, SETTER, METHOD_INIT, METHOD_NEW) -from libclinic.crenderdata import CRenderData, TemplateDict -from libclinic.language import Language -from libclinic.function import ( +from . import ( + unspecified, fail, warn, Sentinels, VersionTuple, c_repr) +from .cpp import Monitor +from .formatting import ( + normalize_snippet, linear_format, docstring_for_c_string, + format_escape, wrap_declarations, pprint_words, wrapped_c_string_literal, + indent_all_lines, suffix_all_lines) +from .function import GETTER, SETTER, METHOD_INIT, METHOD_NEW +from .crenderdata import CRenderData, TemplateDict +from .language import Language +from .function import ( Module, Class, Function, Parameter, permute_optional_groups) -from libclinic.converters import ( +from .converters import ( defining_class_converter, object_converter, self_converter) if TYPE_CHECKING: - from libclinic.app import Clinic + from .app import Clinic def declare_parser( @@ -92,7 +95,7 @@ def declare_parser( }}; #undef KWTUPLE """ % (format_ or fname) - return libclinic.normalize_snippet(declarations) + return normalize_snippet(declarations) class CLanguage(Language): @@ -106,67 +109,67 @@ class CLanguage(Language): NO_VARARG: Final[str] = "PY_SSIZE_T_MAX" - PARSER_PROTOTYPE_KEYWORD: Final[str] = libclinic.normalize_snippet(""" + PARSER_PROTOTYPE_KEYWORD: Final[str] = normalize_snippet(""" static PyObject * {c_basename}({self_type}{self_name}, PyObject *args, PyObject *kwargs) """) - PARSER_PROTOTYPE_KEYWORD___INIT__: Final[str] = libclinic.normalize_snippet(""" + PARSER_PROTOTYPE_KEYWORD___INIT__: Final[str] = normalize_snippet(""" static int {c_basename}({self_type}{self_name}, PyObject *args, PyObject *kwargs) """) - PARSER_PROTOTYPE_VARARGS: Final[str] = libclinic.normalize_snippet(""" + PARSER_PROTOTYPE_VARARGS: Final[str] = normalize_snippet(""" static PyObject * {c_basename}({self_type}{self_name}, PyObject *args) """) - PARSER_PROTOTYPE_FASTCALL: Final[str] = libclinic.normalize_snippet(""" + PARSER_PROTOTYPE_FASTCALL: Final[str] = normalize_snippet(""" static PyObject * {c_basename}({self_type}{self_name}, PyObject *const *args, Py_ssize_t nargs) """) - PARSER_PROTOTYPE_FASTCALL_KEYWORDS: Final[str] = libclinic.normalize_snippet(""" + PARSER_PROTOTYPE_FASTCALL_KEYWORDS: Final[str] = normalize_snippet(""" static PyObject * {c_basename}({self_type}{self_name}, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) """) - PARSER_PROTOTYPE_DEF_CLASS: Final[str] = libclinic.normalize_snippet(""" + PARSER_PROTOTYPE_DEF_CLASS: Final[str] = normalize_snippet(""" static PyObject * {c_basename}({self_type}{self_name}, PyTypeObject *{defining_class_name}, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) """) - PARSER_PROTOTYPE_NOARGS: Final[str] = libclinic.normalize_snippet(""" + PARSER_PROTOTYPE_NOARGS: Final[str] = normalize_snippet(""" static PyObject * {c_basename}({self_type}{self_name}, PyObject *Py_UNUSED(ignored)) """) - PARSER_PROTOTYPE_GETTER: Final[str] = libclinic.normalize_snippet(""" + PARSER_PROTOTYPE_GETTER: Final[str] = normalize_snippet(""" static PyObject * {c_basename}({self_type}{self_name}, void *Py_UNUSED(context)) """) - PARSER_PROTOTYPE_SETTER: Final[str] = libclinic.normalize_snippet(""" + PARSER_PROTOTYPE_SETTER: Final[str] = normalize_snippet(""" static int {c_basename}({self_type}{self_name}, PyObject *value, void *Py_UNUSED(context)) """) - METH_O_PROTOTYPE: Final[str] = libclinic.normalize_snippet(""" + METH_O_PROTOTYPE: Final[str] = normalize_snippet(""" static PyObject * {c_basename}({impl_parameters}) """) - DOCSTRING_PROTOTYPE_VAR: Final[str] = libclinic.normalize_snippet(""" + DOCSTRING_PROTOTYPE_VAR: Final[str] = normalize_snippet(""" PyDoc_VAR({c_basename}__doc__); """) - DOCSTRING_PROTOTYPE_STRVAR: Final[str] = libclinic.normalize_snippet(""" + DOCSTRING_PROTOTYPE_STRVAR: Final[str] = normalize_snippet(""" PyDoc_STRVAR({c_basename}__doc__, {docstring}); """) - GETSET_DOCSTRING_PROTOTYPE_STRVAR: Final[str] = libclinic.normalize_snippet(""" + GETSET_DOCSTRING_PROTOTYPE_STRVAR: Final[str] = normalize_snippet(""" PyDoc_STRVAR({getset_basename}__doc__, {docstring}); #define {getset_basename}_HAS_DOCSTR """) - IMPL_DEFINITION_PROTOTYPE: Final[str] = libclinic.normalize_snippet(""" + IMPL_DEFINITION_PROTOTYPE: Final[str] = normalize_snippet(""" static {impl_return_type} {c_basename}_impl({impl_parameters}) """) - METHODDEF_PROTOTYPE_DEFINE: Final[str] = libclinic.normalize_snippet(r""" + METHODDEF_PROTOTYPE_DEFINE: Final[str] = normalize_snippet(r""" #define {methoddef_name} \ {{"{name}", {methoddef_cast}{c_basename}{methoddef_cast_end}, {methoddef_flags}, {c_basename}__doc__}}, """) - GETTERDEF_PROTOTYPE_DEFINE: Final[str] = libclinic.normalize_snippet(r""" + GETTERDEF_PROTOTYPE_DEFINE: Final[str] = normalize_snippet(r""" #if defined({getset_basename}_HAS_DOCSTR) # define {getset_basename}_DOCSTR {getset_basename}__doc__ #else @@ -179,7 +182,7 @@ class CLanguage(Language): # define {getset_name}_GETSETDEF {{"{name}", (getter){getset_basename}_get, NULL, {getset_basename}_DOCSTR}}, #endif """) - SETTERDEF_PROTOTYPE_DEFINE: Final[str] = libclinic.normalize_snippet(r""" + SETTERDEF_PROTOTYPE_DEFINE: Final[str] = normalize_snippet(r""" #if defined({getset_name}_HAS_DOCSTR) # define {getset_basename}_DOCSTR {getset_basename}__doc__ #else @@ -192,7 +195,7 @@ class CLanguage(Language): # define {getset_name}_GETSETDEF {{"{name}", NULL, (setter){getset_basename}_set, NULL}}, #endif """) - METHODDEF_PROTOTYPE_IFNDEF: Final[str] = libclinic.normalize_snippet(""" + METHODDEF_PROTOTYPE_IFNDEF: Final[str] = normalize_snippet(""" #ifndef {methoddef_name} #define {methoddef_name} #endif /* !defined({methoddef_name}) */ @@ -221,7 +224,7 @@ class CLanguage(Language): def __init__(self, filename: str) -> None: super().__init__(filename) - self.cpp = libclinic.cpp.Monitor(filename) + self.cpp = Monitor(filename) def parse_line(self, line: str) -> None: self.cpp.writeline(line) @@ -258,9 +261,9 @@ def compiler_deprecated_warning( code = self.COMPILER_DEPRECATION_WARNING_PROTOTYPE.format( major=minversion[0], minor=minversion[1], - message=libclinic.c_repr(message), + message=c_repr(message), ) - return libclinic.normalize_snippet(code) + return normalize_snippet(code) def deprecate_positional_use( self, @@ -289,7 +292,7 @@ def deprecate_positional_use( params.values(), key=attrgetter("deprecated_positional") ): names = [repr(p.name) for p in group] - pstr = libclinic.pprint_words(names) + pstr = pprint_words(names) if len(names) == 1: message += ( f" Parameter {pstr} will become a keyword-only parameter " @@ -308,10 +311,10 @@ def deprecate_positional_use( code = self.DEPRECATION_WARNING_PROTOTYPE.format( condition=condition, errcheck="", - message=libclinic.wrapped_c_string_literal(message, width=64, - subsequent_indent=20), + message=wrapped_c_string_literal(message, width=64, + subsequent_indent=20), ) - return libclinic.normalize_snippet(code, indent=4) + return normalize_snippet(code, indent=4) def deprecate_keyword_use( self, @@ -358,7 +361,7 @@ def deprecate_keyword_use( else: condition = f"kwargs && PyDict_GET_SIZE(kwargs) && {condition}" names = [repr(p.name) for p in params.values()] - pstr = libclinic.pprint_words(names) + pstr = pprint_words(names) pl = 's' if len(params) != 1 else '' message = ( f"Passing keyword argument{pl} {pstr} to " @@ -369,7 +372,7 @@ def deprecate_keyword_use( params.values(), key=attrgetter("deprecated_keyword") ): names = [repr(p.name) for p in group] - pstr = libclinic.pprint_words(names) + pstr = pprint_words(names) pl = 's' if len(names) != 1 else '' message += ( f" Parameter{pl} {pstr} will become positional-only " @@ -391,10 +394,10 @@ def deprecate_keyword_use( code = self.DEPRECATION_WARNING_PROTOTYPE.format( condition=condition, errcheck=errcheck, - message=libclinic.wrapped_c_string_literal(message, width=64, - subsequent_indent=20), + message=wrapped_c_string_literal(message, width=64, + subsequent_indent=20), ) - return libclinic.normalize_snippet(code, indent=4) + return normalize_snippet(code, indent=4) def output_templates( self, @@ -491,14 +494,14 @@ def parser_body( lines.append(prototype) parser_body_fields = fields - preamble = libclinic.normalize_snippet(""" + preamble = normalize_snippet(""" {{ {return_value_declaration} {parser_declarations} {declarations} {initializers} """) + "\n" - finale = libclinic.normalize_snippet(""" + finale = normalize_snippet(""" {modifications} {lock} {return_value} = {c_basename}_impl({impl_arguments}); @@ -513,8 +516,8 @@ def parser_body( """) for field in preamble, *fields, finale: lines.append(field) - return libclinic.linear_format("\n".join(lines), - parser_declarations=declarations) + return linear_format("\n".join(lines), + parser_declarations=declarations) fastcall = not new_or_init limited_capi = clinic.limited_capi @@ -548,7 +551,7 @@ def parser_body( parser_prototype = self.PARSER_PROTOTYPE_DEF_CLASS return_error = ('return NULL;' if simple_return else 'goto exit;') - parser_code = [libclinic.normalize_snippet(""" + parser_code = [normalize_snippet(""" if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {{ PyErr_SetString(PyExc_TypeError, "{name}() takes no arguments"); %s @@ -588,7 +591,7 @@ def parser_body( argname = 'arg' if parameters[0].name == argname: argname += '_' - parser_prototype = libclinic.normalize_snippet(""" + parser_prototype = normalize_snippet(""" static PyObject * {c_basename}({self_type}{self_name}, PyObject *%s) """ % argname) @@ -603,7 +606,7 @@ def parser_body( }} """ % argname parser_definition = parser_body(parser_prototype, - libclinic.normalize_snippet(parsearg, indent=4)) + normalize_snippet(parsearg, indent=4)) elif has_option_groups: # positional parameters with option groups @@ -642,11 +645,11 @@ def parser_body( parser_code = [] if nargs != 'nargs': nargs_def = f'Py_ssize_t nargs = {nargs};' - parser_code.append(libclinic.normalize_snippet(nargs_def, indent=4)) + parser_code.append(normalize_snippet(nargs_def, indent=4)) nargs = 'nargs' if min_pos == max_args: pl = '' if min_pos == 1 else 's' - parser_code.append(libclinic.normalize_snippet(f""" + parser_code.append(normalize_snippet(f""" if ({nargs} != {min_pos}) {{{{ PyErr_Format(PyExc_TypeError, "{{name}} expected {min_pos} argument{pl}, got %zd", {nargs}); goto exit; @@ -656,7 +659,7 @@ def parser_body( else: if min_pos: pl = '' if min_pos == 1 else 's' - parser_code.append(libclinic.normalize_snippet(f""" + parser_code.append(normalize_snippet(f""" if ({nargs} < {min_pos}) {{{{ PyErr_Format(PyExc_TypeError, "{{name}} expected at least {min_pos} argument{pl}, got %zd", {nargs}); goto exit; @@ -665,7 +668,7 @@ def parser_body( indent=4)) if max_args != self.NO_VARARG: pl = '' if max_args == 1 else 's' - parser_code.append(libclinic.normalize_snippet(f""" + parser_code.append(normalize_snippet(f""" if ({nargs} > {max_args}) {{{{ PyErr_Format(PyExc_TypeError, "{{name}} expected at most {max_args} argument{pl}, got %zd", {nargs}); goto exit; @@ -675,7 +678,7 @@ def parser_body( else: clinic.add_include('pycore_modsupport.h', '_PyArg_CheckPositional()') - parser_code = [libclinic.normalize_snippet(f""" + parser_code = [normalize_snippet(f""" if (!_PyArg_CheckPositional("{{name}}", {nargs}, {min_pos}, {max_args})) {{{{ goto exit; }}}} @@ -685,7 +688,7 @@ def parser_body( for i, p in enumerate(parameters): if p.is_vararg(): if fastcall: - parser_code.append(libclinic.normalize_snippet(""" + parser_code.append(normalize_snippet(""" %s = PyTuple_New(%s); if (!%s) {{ goto exit; @@ -702,7 +705,7 @@ def parser_body( max_pos ), indent=4)) else: - parser_code.append(libclinic.normalize_snippet(""" + parser_code.append(normalize_snippet(""" %s = PyTuple_GetSlice(%d, -1); """ % ( p.converter.parser_name, @@ -718,12 +721,12 @@ def parser_body( break if has_optional or p.is_optional(): has_optional = True - parser_code.append(libclinic.normalize_snippet(""" + parser_code.append(normalize_snippet(""" if (%s < %d) {{ goto skip_optional; }} """, indent=4) % (nargs, i + 1)) - parser_code.append(libclinic.normalize_snippet(parsearg, indent=4)) + parser_code.append(normalize_snippet(parsearg, indent=4)) if parser_code is not None: if has_optional: @@ -737,7 +740,7 @@ def parser_body( if fastcall: clinic.add_include('pycore_modsupport.h', '_PyArg_ParseStack()') - parser_code = [libclinic.normalize_snippet(""" + parser_code = [normalize_snippet(""" if (!_PyArg_ParseStack(args, nargs, "{format_units}:{name}", {parse_arguments})) {{ goto exit; @@ -746,7 +749,7 @@ def parser_body( else: flags = "METH_VARARGS" parser_prototype = self.PARSER_PROTOTYPE_VARARGS - parser_code = [libclinic.normalize_snippet(""" + parser_code = [normalize_snippet(""" if (!PyArg_ParseTuple(args, "{format_units}:{name}", {parse_arguments})) {{ goto exit; @@ -801,7 +804,7 @@ def parser_body( declarations += "\nPyObject *argsbuf[%s];" % len(converters) if has_optional_kw: declarations += "\nPy_ssize_t noptargs = %s + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - %d;" % (nargs, min_pos + min_kw_only) - parser_code = [libclinic.normalize_snippet(""" + parser_code = [normalize_snippet(""" args = %s(args, nargs, NULL, kwnames, &_parser, %s, argsbuf); if (!args) {{ goto exit; @@ -819,7 +822,7 @@ def parser_body( declarations += "\nPy_ssize_t nargs = PyTuple_GET_SIZE(args);" if has_optional_kw: declarations += "\nPy_ssize_t noptargs = %s + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - %d;" % (nargs, min_pos + min_kw_only) - parser_code = [libclinic.normalize_snippet(""" + parser_code = [normalize_snippet(""" fastargs = %s(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, %s, argsbuf); if (!fastargs) {{ goto exit; @@ -852,19 +855,19 @@ def parser_body( parser_code.append("%s:" % add_label) add_label = None if not p.is_optional(): - parser_code.append(libclinic.normalize_snippet(parsearg, indent=4)) + parser_code.append(normalize_snippet(parsearg, indent=4)) elif i < pos_only: add_label = 'skip_optional_posonly' - parser_code.append(libclinic.normalize_snippet(""" + parser_code.append(normalize_snippet(""" if (nargs < %d) {{ goto %s; }} """ % (i + 1, add_label), indent=4)) if has_optional_kw: - parser_code.append(libclinic.normalize_snippet(""" + parser_code.append(normalize_snippet(""" noptargs--; """, indent=4)) - parser_code.append(libclinic.normalize_snippet(parsearg, indent=4)) + parser_code.append(normalize_snippet(parsearg, indent=4)) else: if i < max_pos: label = 'skip_optional_pos' @@ -876,20 +879,20 @@ def parser_body( first_opt += 1 if i == first_opt: add_label = label - parser_code.append(libclinic.normalize_snippet(""" + parser_code.append(normalize_snippet(""" if (!noptargs) {{ goto %s; }} """ % add_label, indent=4)) if i + 1 == len(parameters): - parser_code.append(libclinic.normalize_snippet(parsearg, indent=4)) + parser_code.append(normalize_snippet(parsearg, indent=4)) else: add_label = label - parser_code.append(libclinic.normalize_snippet(""" + parser_code.append(normalize_snippet(""" if (%s) {{ """ % (argname_fmt % i), indent=4)) - parser_code.append(libclinic.normalize_snippet(parsearg, indent=8)) - parser_code.append(libclinic.normalize_snippet(""" + parser_code.append(normalize_snippet(parsearg, indent=8)) + parser_code.append(normalize_snippet(""" if (!--noptargs) {{ goto %s; }} @@ -911,7 +914,7 @@ def parser_body( assert not fastcall flags = "METH_VARARGS|METH_KEYWORDS" parser_prototype = self.PARSER_PROTOTYPE_KEYWORD - parser_code = [libclinic.normalize_snippet(""" + parser_code = [normalize_snippet(""" if (!PyArg_ParseTupleAndKeywords(args, kwargs, "{format_units}:{name}", _keywords, {parse_arguments})) goto exit; @@ -923,7 +926,7 @@ def parser_body( elif fastcall: clinic.add_include('pycore_modsupport.h', '_PyArg_ParseStackAndKeywords()') - parser_code = [libclinic.normalize_snippet(""" + parser_code = [normalize_snippet(""" if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser{parse_arguments_comma} {parse_arguments})) {{ goto exit; @@ -932,7 +935,7 @@ def parser_body( else: clinic.add_include('pycore_modsupport.h', '_PyArg_ParseTupleAndKeywordsFast()') - parser_code = [libclinic.normalize_snippet(""" + parser_code = [normalize_snippet(""" if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, {parse_arguments})) {{ goto exit; @@ -986,7 +989,7 @@ def parser_body( declarations = '{base_type_ptr}' clinic.add_include('pycore_modsupport.h', '_PyArg_NoKeywords()') - fields.insert(0, libclinic.normalize_snippet(""" + fields.insert(0, normalize_snippet(""" if ({self_type_check}!_PyArg_NoKeywords("{name}", kwargs)) {{ goto exit; }} @@ -994,7 +997,7 @@ def parser_body( if not parses_positional: clinic.add_include('pycore_modsupport.h', '_PyArg_NoPositional()') - fields.insert(0, libclinic.normalize_snippet(""" + fields.insert(0, normalize_snippet(""" if ({self_type_check}!_PyArg_NoPositional("{name}", args)) {{ goto exit; }} @@ -1173,7 +1176,7 @@ def render_option_group_parsing( {group_booleans} break; """ - s = libclinic.linear_format(s, group_booleans=lines) + s = linear_format(s, group_booleans=lines) s = s.format_map(d) out.append(s) @@ -1183,7 +1186,7 @@ def render_option_group_parsing( out.append(' goto exit;\n') out.append("}") - template_dict['option_group_parsing'] = libclinic.format_escape("".join(out)) + template_dict['option_group_parsing'] = format_escape("".join(out)) def render_function( self, @@ -1280,7 +1283,7 @@ def render_function( template_dict['methoddef_name'] = f.c_basename.upper() + "_METHODDEF" template_dict['c_basename'] = f.c_basename - template_dict['docstring'] = libclinic.docstring_for_c_string(f.docstring) + template_dict['docstring'] = docstring_for_c_string(f.docstring) template_dict['self_name'] = template_dict['self_type'] = template_dict['self_type_check'] = '' template_dict['target_critical_section'] = ', '.join(f.target_critical_section) for converter in converters: @@ -1290,7 +1293,7 @@ def render_function( f.return_converter.render(f, data) template_dict['impl_return_type'] = f.return_converter.type - template_dict['declarations'] = libclinic.format_escape("\n".join(data.declarations)) + template_dict['declarations'] = format_escape("\n".join(data.declarations)) template_dict['initializers'] = "\n\n".join(data.initializers) template_dict['modifications'] = '\n\n'.join(data.modifications) template_dict['keywords_c'] = ' '.join('"' + k + '",' @@ -1307,9 +1310,9 @@ def render_function( template_dict['impl_parameters'] = ", ".join(data.impl_parameters) template_dict['impl_arguments'] = ", ".join(data.impl_arguments) - template_dict['return_conversion'] = libclinic.format_escape("".join(data.return_conversion).rstrip()) - template_dict['post_parsing'] = libclinic.format_escape("".join(data.post_parsing).rstrip()) - template_dict['cleanup'] = libclinic.format_escape("".join(data.cleanup)) + template_dict['return_conversion'] = format_escape("".join(data.return_conversion).rstrip()) + template_dict['post_parsing'] = format_escape("".join(data.post_parsing).rstrip()) + template_dict['cleanup'] = format_escape("".join(data.cleanup)) template_dict['return_value'] = data.return_value template_dict['lock'] = "\n".join(data.lock) @@ -1329,9 +1332,9 @@ def render_function( for name, destination in clinic.destination_buffers.items(): template = templates[name] if has_option_groups: - template = libclinic.linear_format(template, + template = linear_format(template, option_group_parsing=template_dict['option_group_parsing']) - template = libclinic.linear_format(template, + template = linear_format(template, declarations=template_dict['declarations'], return_conversion=template_dict['return_conversion'], initializers=template_dict['initializers'], @@ -1345,19 +1348,19 @@ def render_function( # Only generate the "exit:" label # if we have any gotos label = "exit:" if "goto exit;" in template else "" - template = libclinic.linear_format(template, exit_label=label) + template = linear_format(template, exit_label=label) s = template.format_map(template_dict) # mild hack: # reflow long impl declarations if name in {"impl_prototype", "impl_definition"}: - s = libclinic.wrap_declarations(s) + s = wrap_declarations(s) if clinic.line_prefix: - s = libclinic.indent_all_lines(s, clinic.line_prefix) + s = indent_all_lines(s, clinic.line_prefix) if clinic.line_suffix: - s = libclinic.suffix_all_lines(s, clinic.line_suffix) + s = suffix_all_lines(s, clinic.line_suffix) destination.append(s) diff --git a/Tools/clinic/libclinic/cli.py b/Tools/clinic/argclinic/cli.py similarity index 94% rename from Tools/clinic/libclinic/cli.py rename to Tools/clinic/argclinic/cli.py index f36c6d04efd383..e963c24f24dbee 100644 --- a/Tools/clinic/libclinic/cli.py +++ b/Tools/clinic/argclinic/cli.py @@ -10,17 +10,13 @@ # Local imports. -import libclinic -import libclinic.cpp -from libclinic import ClinicError -from libclinic.language import Language, PythonLanguage -from libclinic.block_parser import BlockParser -from libclinic.converter import ( - ConverterType, converters, legacy_converters) -from libclinic.return_converters import ( - return_converters, ReturnConverterType) -from libclinic.clanguage import CLanguage -from libclinic.app import Clinic +from . import ClinicError, write_file +from .language import Language, PythonLanguage +from .block_parser import BlockParser +from .converter import ConverterType, converters, legacy_converters +from .return_converters import return_converters, ReturnConverterType +from .clanguage import CLanguage +from .app import Clinic # TODO: @@ -83,7 +79,7 @@ def parse_file( limited_capi=limited_capi) cooked = clinic.parse(raw) - libclinic.write_file(output, cooked) + write_file(output, cooked) def create_cli() -> argparse.ArgumentParser: diff --git a/Tools/clinic/libclinic/codegen.py b/Tools/clinic/argclinic/codegen.py similarity index 94% rename from Tools/clinic/libclinic/codegen.py rename to Tools/clinic/argclinic/codegen.py index ad08e22e2e1c2c..04694234bd141a 100644 --- a/Tools/clinic/libclinic/codegen.py +++ b/Tools/clinic/argclinic/codegen.py @@ -4,13 +4,12 @@ import os from typing import Final, TYPE_CHECKING -import libclinic -from libclinic import fail -from libclinic.crenderdata import Include -from libclinic.language import Language -from libclinic.block_parser import Block +from . import fail, compute_checksum +from .crenderdata import Include +from .language import Language +from .block_parser import Block if TYPE_CHECKING: - from libclinic.app import Clinic + from .app import Clinic @dc.dataclass(slots=True) @@ -90,8 +89,8 @@ def print_block( write(output) arguments = "output={output} input={input}".format( - output=libclinic.compute_checksum(output, 16), - input=libclinic.compute_checksum(input, 16) + output=compute_checksum(output, 16), + input=compute_checksum(input, 16) ) write(self.language.checksum_line.format(dsl_name=dsl_name, arguments=arguments)) write("\n") diff --git a/Tools/clinic/libclinic/converter.py b/Tools/clinic/argclinic/converter.py similarity index 97% rename from Tools/clinic/libclinic/converter.py rename to Tools/clinic/argclinic/converter.py index ac78be3f7958da..d1e8874bfae0db 100644 --- a/Tools/clinic/libclinic/converter.py +++ b/Tools/clinic/argclinic/converter.py @@ -4,11 +4,11 @@ from typing import Any, TypeVar, Literal, TYPE_CHECKING, cast from collections.abc import Callable -import libclinic -from libclinic import fail -from libclinic import Sentinels, unspecified, unknown -from libclinic.crenderdata import CRenderData, Include, TemplateDict -from libclinic.function import Function, Parameter +from . import ( + fail, Sentinels, unspecified, unknown, + c_repr, ensure_legal_c_identifier, CLINIC_PREFIXED_ARGS, CLINIC_PREFIX) +from .crenderdata import CRenderData, Include, TemplateDict +from .function import Function, Parameter CConverterClassT = TypeVar("CConverterClassT", bound=type["CConverter"]) @@ -177,7 +177,7 @@ def __init__(self, unused: bool = False, **kwargs: Any ) -> None: - self.name = libclinic.ensure_legal_c_identifier(name) + self.name = ensure_legal_c_identifier(name) self.py_name = py_name self.unused = unused self.includes: list[Include] = [] @@ -324,7 +324,7 @@ def parse_argument(self, args: list[str]) -> None: args.append(self.converter) if self.encoding: - args.append(libclinic.c_repr(self.encoding)) + args.append(c_repr(self.encoding)) elif self.subclass_of: args.append(self.subclass_of) @@ -505,8 +505,8 @@ def set_template_dict(self, template_dict: TemplateDict) -> None: @property def parser_name(self) -> str: - if self.name in libclinic.CLINIC_PREFIXED_ARGS: # bpo-39741 - return libclinic.CLINIC_PREFIX + self.name + if self.name in CLINIC_PREFIXED_ARGS: # bpo-39741 + return CLINIC_PREFIX + self.name else: return self.name diff --git a/Tools/clinic/libclinic/converters.py b/Tools/clinic/argclinic/converters.py similarity index 99% rename from Tools/clinic/libclinic/converters.py rename to Tools/clinic/argclinic/converters.py index 7fc16f17450aaa..fb2f1d24c1cb79 100644 --- a/Tools/clinic/libclinic/converters.py +++ b/Tools/clinic/argclinic/converters.py @@ -4,13 +4,13 @@ from types import NoneType from typing import Any -from libclinic import fail, Null, unspecified, unknown -from libclinic.function import ( +from . import fail, Null, unspecified, unknown +from .function import ( Function, Parameter, CALLABLE, STATIC_METHOD, CLASS_METHOD, METHOD_INIT, METHOD_NEW, GETTER, SETTER) -from libclinic.crenderdata import CRenderData, TemplateDict -from libclinic.converter import ( +from .crenderdata import CRenderData, TemplateDict +from .converter import ( CConverter, legacy_converters, add_legacy_c_converter) diff --git a/Tools/clinic/libclinic/cpp.py b/Tools/clinic/argclinic/cpp.py similarity index 100% rename from Tools/clinic/libclinic/cpp.py rename to Tools/clinic/argclinic/cpp.py diff --git a/Tools/clinic/libclinic/crenderdata.py b/Tools/clinic/argclinic/crenderdata.py similarity index 100% rename from Tools/clinic/libclinic/crenderdata.py rename to Tools/clinic/argclinic/crenderdata.py diff --git a/Tools/clinic/libclinic/dsl_parser.py b/Tools/clinic/argclinic/dsl_parser.py similarity index 98% rename from Tools/clinic/libclinic/dsl_parser.py rename to Tools/clinic/argclinic/dsl_parser.py index 4c739efe1066e4..c1658d7e594009 100644 --- a/Tools/clinic/libclinic/dsl_parser.py +++ b/Tools/clinic/argclinic/dsl_parser.py @@ -10,27 +10,28 @@ from types import FunctionType, NoneType from typing import TYPE_CHECKING, Any, NamedTuple -import libclinic -from libclinic import ( +from . import ( ClinicError, VersionTuple, - fail, warn, unspecified, unknown, NULL) -from libclinic.function import ( + fail, warn, unspecified, unknown, NULL, + is_legal_py_identifier, is_legal_c_identifier, c_repr, SIG_END_MARKER) +from .formatting import linear_format +from .function import ( Module, Class, Function, Parameter, FunctionKind, CALLABLE, STATIC_METHOD, CLASS_METHOD, METHOD_INIT, METHOD_NEW, GETTER, SETTER) -from libclinic.converter import ( +from .converter import ( converters, legacy_converters) -from libclinic.converters import ( +from .converters import ( self_converter, defining_class_converter, correct_name_for_self) -from libclinic.return_converters import ( +from .return_converters import ( CReturnConverter, return_converters, int_return_converter) -from libclinic.parser import create_parser_namespace +from .parser import create_parser_namespace if TYPE_CHECKING: - from libclinic.block_parser import Block - from libclinic.app import Clinic + from .block_parser import Block + from .app import Clinic unsupported_special_methods: set[str] = set(""" @@ -539,9 +540,9 @@ def parse_function_names(self, line: str) -> FunctionNames: if fields[-1] == '__new__': fields.pop() c_basename = "_".join(fields) - if not libclinic.is_legal_py_identifier(full_name): + if not is_legal_py_identifier(full_name): fail(f"Illegal function name: {full_name!r}") - if not libclinic.is_legal_c_identifier(c_basename): + if not is_legal_c_identifier(c_basename): fail(f"Illegal C basename: {c_basename!r}") names = FunctionNames(full_name=full_name, c_basename=c_basename) self.normalize_function_kind(names.full_name) @@ -665,7 +666,7 @@ def state_modulename_name(self, line: str) -> None: before, equals, existing = line.rpartition('=') if equals: existing = existing.strip() - if libclinic.is_legal_py_identifier(existing): + if is_legal_py_identifier(existing): # we're cloning! names = self.parse_function_names(before) return self.parse_cloned_function(names, existing) @@ -1041,7 +1042,7 @@ def bad_node(self, node: ast.AST) -> None: if isinstance(value, (bool, NoneType)): c_default = "Py_" + py_default elif isinstance(value, str): - c_default = libclinic.c_repr(value) + c_default = c_repr(value) else: c_default = py_default @@ -1485,7 +1486,7 @@ def add_parameter(text: str) -> None: # lines.append(f.return_converter.py_default) if not f.docstring_only: - lines.append("\n" + libclinic.SIG_END_MARKER + "\n") + lines.append("\n" + SIG_END_MARKER + "\n") signature_line = "".join(lines) @@ -1542,9 +1543,9 @@ def format_docstring(self) -> str: parameters = self.format_docstring_parameters(params) signature = self.format_docstring_signature(f, params) docstring = "\n".join(lines) - return libclinic.linear_format(docstring, - signature=signature, - parameters=parameters).rstrip() + return linear_format(docstring, + signature=signature, + parameters=parameters).rstrip() def check_remaining_star(self, lineno: int | None = None) -> None: assert isinstance(self.function, Function) diff --git a/Tools/clinic/libclinic/errors.py b/Tools/clinic/argclinic/errors.py similarity index 100% rename from Tools/clinic/libclinic/errors.py rename to Tools/clinic/argclinic/errors.py diff --git a/Tools/clinic/libclinic/formatting.py b/Tools/clinic/argclinic/formatting.py similarity index 99% rename from Tools/clinic/libclinic/formatting.py rename to Tools/clinic/argclinic/formatting.py index 873ece6210017a..a929be251d03e6 100644 --- a/Tools/clinic/libclinic/formatting.py +++ b/Tools/clinic/argclinic/formatting.py @@ -4,7 +4,7 @@ import textwrap from typing import Final -from libclinic import ClinicError +from . import ClinicError SIG_END_MARKER: Final = "--" diff --git a/Tools/clinic/libclinic/function.py b/Tools/clinic/argclinic/function.py similarity index 97% rename from Tools/clinic/libclinic/function.py rename to Tools/clinic/argclinic/function.py index 1563fdf9065b7e..62f5748b130db5 100644 --- a/Tools/clinic/libclinic/function.py +++ b/Tools/clinic/argclinic/function.py @@ -6,13 +6,13 @@ import inspect from collections.abc import Iterable, Iterator, Sequence from typing import Final, Any, TYPE_CHECKING -if TYPE_CHECKING: - from libclinic.converter import CConverter - from libclinic.converters import self_converter - from libclinic.return_converters import CReturnConverter - from libclinic.app import Clinic -from libclinic import VersionTuple, unspecified +from . import VersionTuple, unspecified +if TYPE_CHECKING: + from .converter import CConverter + from .converters import self_converter + from .return_converters import CReturnConverter + from .app import Clinic ClassDict = dict[str, "Class"] diff --git a/Tools/clinic/libclinic/identifiers.py b/Tools/clinic/argclinic/identifiers.py similarity index 100% rename from Tools/clinic/libclinic/identifiers.py rename to Tools/clinic/argclinic/identifiers.py diff --git a/Tools/clinic/libclinic/language.py b/Tools/clinic/argclinic/language.py similarity index 94% rename from Tools/clinic/libclinic/language.py rename to Tools/clinic/argclinic/language.py index 15975430c16022..61ef20a6aa0f49 100644 --- a/Tools/clinic/libclinic/language.py +++ b/Tools/clinic/argclinic/language.py @@ -5,13 +5,12 @@ Iterable, ) -import libclinic -from libclinic import fail -from libclinic.function import ( +from . import fail, FormatCounterFormatter +from .function import ( Module, Class, Function) if typing.TYPE_CHECKING: - from libclinic.app import Clinic + from .app import Clinic class Language(metaclass=abc.ABCMeta): @@ -67,7 +66,7 @@ def assert_only_one( fields = ['dsl_name'] fields.extend(additional_fields) line: str = getattr(self, attr) - fcf = libclinic.FormatCounterFormatter() + fcf = FormatCounterFormatter() fcf.format(line) def local_fail(should_be_there_but_isnt: bool) -> None: if should_be_there_but_isnt: diff --git a/Tools/clinic/libclinic/parser.py b/Tools/clinic/argclinic/parser.py similarity index 80% rename from Tools/clinic/libclinic/parser.py rename to Tools/clinic/argclinic/parser.py index 8135dd9ceb3937..e2f8af9138329f 100644 --- a/Tools/clinic/libclinic/parser.py +++ b/Tools/clinic/argclinic/parser.py @@ -5,13 +5,13 @@ from types import NoneType from typing import Any, Protocol, TYPE_CHECKING -from libclinic import unspecified -from libclinic.block_parser import Block -from libclinic.converter import CConverter, converters -from libclinic.converters import buffer, robuffer, rwbuffer -from libclinic.return_converters import CReturnConverter, return_converters +from . import unspecified +from .block_parser import Block +from .converter import CConverter, converters +from .converters import buffer, robuffer, rwbuffer +from .return_converters import CReturnConverter, return_converters if TYPE_CHECKING: - from libclinic.app import Clinic + from .app import Clinic class Parser(Protocol): diff --git a/Tools/clinic/libclinic/return_converters.py b/Tools/clinic/argclinic/return_converters.py similarity index 98% rename from Tools/clinic/libclinic/return_converters.py rename to Tools/clinic/argclinic/return_converters.py index 7bdd257cfa3443..8b1e2587657426 100644 --- a/Tools/clinic/libclinic/return_converters.py +++ b/Tools/clinic/argclinic/return_converters.py @@ -1,9 +1,10 @@ import sys from collections.abc import Callable -from libclinic.crenderdata import CRenderData -from libclinic.function import Function from typing import Any +from .crenderdata import CRenderData +from .function import Function + ReturnConverterType = Callable[..., "CReturnConverter"] diff --git a/Tools/clinic/libclinic/utils.py b/Tools/clinic/argclinic/utils.py similarity index 100% rename from Tools/clinic/libclinic/utils.py rename to Tools/clinic/argclinic/utils.py diff --git a/Tools/clinic/clinic.py b/Tools/clinic/run_argclinic.py similarity index 85% rename from Tools/clinic/clinic.py rename to Tools/clinic/run_argclinic.py index 362715d264620e..550582cd5301ab 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/run_argclinic.py @@ -4,7 +4,7 @@ # Copyright 2012-2013 by Larry Hastings. # Licensed to the PSF under a contributor agreement. # -from libclinic.cli import main +from argclinic.cli import main if __name__ == "__main__": pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy