Argument-Clinic / cpython

The Python programming language
https://www.python.org/
Other
1 stars 0 forks source link

[WIP] Split clinic.py into smaller files #41

Closed vstinner closed 6 months ago

vstinner commented 7 months ago
vstinner commented 7 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:

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

vstinner commented 7 months ago

Only in terms of classes, my PR creates the following organization.

clinic.block_parser

clinic.block_printer

clinic.clanguage

clinic.clinic_class

clinic.converter

clinic.converters

clinic.cpp

clinic.crenderdata

clinic.dslparser

clinic.errors

clinic.function

clinic.language

clinic.parser

clinic.parsers

clinic.return_converters

clinic.utils

vstinner commented 6 months ago

This PR was merged as smaller changes in the Python main branch.