Closed vstinner closed 6 months ago
@erlend-aasland: Here is a PR based on https://github.com/Argument-Clinic/cpython main branch which splits Argument Clinic into sub-files. I created it to discuss how we can reorganize the code.
I didn't try to group related code at all. I just splitted clinic.py into smaller pieces, that's all.
Main outside changes:
Tools/clinic/clinic/__main__.py
(not used by the Makefile)make clinic
).I'm not sure how to handle imports. For example, dslparser.py
starts with:
from __future__ import annotations
import ast
import enum
import inspect
import re
import shlex
import pprint
import sys
from typing import Any, NamedTuple
from collections.abc import Callable
from types import FunctionType, NoneType
from typing import TYPE_CHECKING
import clinic
from clinic import (
fail, warn, VersionTuple, ClinicError, unknown, unspecified, NULL)
from clinic.block_parser import Block
from clinic.function import (
Module, Class, Function, Parameter, FunctionKind,
METHOD_NEW, METHOD_INIT, GETTER, SETTER, CALLABLE,
CLASS_METHOD, STATIC_METHOD)
from clinic.converter import converters, legacy_converters
from clinic.converters import (
self_converter, correct_name_for_self, defining_class_converter)
from clinic.return_converters import (
CReturnConverter, return_converters, int_return_converter)
from clinic.parser import create_parser_namespace
if TYPE_CHECKING:
from clinic.clinic_class import Clinic
test_clinic.py imports directly classes and functions:
test_tools.skip_if_missing('clinic')
with test_tools.imports_under_tool('clinic'):
import clinic
from clinic import (
suffix_all_lines, normalize_snippet,
indent_all_lines, format_escape, docstring_for_c_string)
from clinic.cpp import Monitor
from clinic import ClinicError
from clinic.dslparser import DSLParser
from clinic.option_groups import (
permute_optional_groups, permute_left_option_groups,
permute_right_option_groups)
from clinic.cli import parse_file
from clinic.clinic_class import Clinic
from clinic.clanguage import CLanguage
from clinic.converters import self_converter, str_converter, int_converter
from clinic.return_converters import int_return_converter
from clinic.block_parser import Block, BlockParser
from clinic.block_printer import BlockPrinter, Destination
from clinic.function import (
Module, Class, Function, FunctionKind, Parameter)
I see clinic as an application, and so it might only expose main() and that's it. Similar API to pip. But I'm open to discussion.
cc @serhiy-storchaka
Only in terms of classes, my PR creates the following organization.
This PR was merged as smaller changes in the Python main branch.