8000 gh-113317: Rename libclinic to argclinic by vstinner · Pull Request #117533 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-113317: Rename libclinic to argclinic #117533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 33 additions & 29 deletions Lib/test/test_clinic.py
< EDBE tr data-hunk="8963edd6d3edaec0c3ec7fe376109b2edf509c8a5e4c76605be6d4a4bd301842" class="show-top-border">
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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"
Expand All @@ -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.
Expand All @@ -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"
Expand All @@ -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.
Expand All @@ -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)


Expand Down Expand Up @@ -4078,7 +4082,7 @@ def test_Function_and_Parameter_reprs(self):
self.assertEqual(repr(parameter), "<clinic.Parameter 'bar'>")

def test_Monitor_repr(self):
monitor = libclinic.cpp.Monitor("test.c")
monitor = Monitor("test.c")
self.assertRegex(repr(monitor), r"<clinic.Monitor \d+ line=0 condition=''>")

monitor.line_number = 42
Expand Down
8 changes: 5 additions & 3 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Tools/clinic/argclinic/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .cli import main
main()
25 changes: 12 additions & 13 deletions Tools/clinic/libclinic/app.py → Tools/clinic/argclinic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}. "
Expand Down
Loading
0