Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/primer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ jobs:
pip install -e .
cd ..

python -m pydocstringformatter.testutils.primer.primer --prepare
python -m pydocstringformatter.testutils.primer.primer --step-one
python -m pydocstringformatter._testutils.primer.primer --prepare
python -m pydocstringformatter._testutils.primer.primer --step-one

cd program_to_test
git checkout $GITHUB_SHA
cd ..
python -m pydocstringformatter.testutils.primer.primer --step-two
python -m pydocstringformatter._testutils.primer.primer --step-two
- name: Upload primer diff
uses: actions/upload-artifact@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion pydocstringformatter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import sys

from pydocstringformatter.utils.exceptions import (
from pydocstringformatter._utils.exceptions import (
ParsingError,
PydocstringFormatterError,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import argparse

from pydocstringformatter.configuration import (
from pydocstringformatter._configuration import (
command_line_parsing,
formatter_options,
toml_parsing,
)
from pydocstringformatter.configuration.validators import VALIDATORS
from pydocstringformatter.formatting.base import Formatter
from pydocstringformatter._configuration.validators import VALIDATORS
from pydocstringformatter._formatting.base import Formatter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you don't want to make the Formatter public ? It's what make this extendable :)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to revisit #29 when I'm satisfied with the tool.

There are some last things I'd like to include before a 1.0 release but since those aren't a priority and quite difficult to get right I don't think I'll get to them soon.

After that I want to look at the public API. It's probably easier to do that from an "all private" situation than a "all public" situation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's definitely better than the current pylint deprecation "situation" 😄



class ArgumentsManager:
Expand All @@ -32,14 +32,14 @@ def __init__(self, version: str, formatters: list[Formatter]) -> None:
)

# Register all arguments
self._register_arguments(version)
formatter_options._register_arguments_formatters(
self.register_arguments(version)
formatter_options.register_arguments_formatters(
self.default_formatters_group,
self.optional_formatters_group,
self.formatters,
)

def _register_arguments(self, version: str) -> None:
def register_arguments(self, version: str) -> None:
"""Register all standard arguments on the parser."""
self.parser.add_argument(
"files", nargs="*", type=str, help="The directory or files to format."
Expand Down Expand Up @@ -128,9 +128,9 @@ def parse_options(
1. configuration files, 2. command line arguments.
"""
# pylint: disable=protected-access
toml_parsing._parse_toml_file(self.parser, self.namespace)
toml_parsing.parse_toml_file(self.parser, self.namespace)

command_line_parsing._parse_command_line_arguments(
command_line_parsing.parse_command_line_arguments(
self.parser, self.namespace, argv
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import argparse


def _parse_command_line_arguments(
def parse_command_line_arguments(
parser: argparse.ArgumentParser, namespace: argparse.Namespace, args: list[str]
) -> None:
"""Parse all arguments on the provided argument parser."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import argparse

from pydocstringformatter.configuration.boolean_option_action import (
from pydocstringformatter._configuration.boolean_option_action import (
BooleanOptionalAction,
)
from pydocstringformatter.formatting.base import Formatter
from pydocstringformatter._formatting.base import Formatter


def _register_arguments_formatters(
def register_arguments_formatters(
default_arg_group: argparse._ArgumentGroup,
optional_arg_group: argparse._ArgumentGroup,
formatters: list[Formatter],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

import tomli

from pydocstringformatter.utils.exceptions import TomlParsingError, UnrecognizedOption
from pydocstringformatter._utils.exceptions import TomlParsingError, UnrecognizedOption

OPTIONS_TYPES: Final = {"write": "store_true", "exclude": "store"}


def _get_toml_file() -> dict[str, Any] | None:
def get_toml_file() -> dict[str, Any] | None:
"""See if there is a pyproject.toml and extract the correct section if it exists."""
if os.path.isfile("pyproject.toml"):
with open("pyproject.toml", "rb") as file:
Expand All @@ -26,7 +26,7 @@ def _get_toml_file() -> dict[str, Any] | None:
return None


def _parse_toml_option(opt: str, value: Any) -> list[str]:
def parse_toml_option(opt: str, value: Any) -> list[str]:
"""Parse an options value in the correct argument type for argparse."""
try:
action = OPTIONS_TYPES[opt]
Expand All @@ -42,14 +42,14 @@ def _parse_toml_option(opt: str, value: Any) -> list[str]:
return [] # pragma: no cover


def _parse_toml_file(
def parse_toml_file(
parser: argparse.ArgumentParser, namespace: argparse.Namespace
) -> None:
"""Get and parse the relevant section form a pyproject.toml file."""
if toml_sect := _get_toml_file():
if toml_sect := get_toml_file():
arguments: list[str] = []

for key, value in toml_sect.items():
arguments += _parse_toml_option(key, value)
arguments += parse_toml_option(key, value)

parser.parse_args(arguments, namespace)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Final, List


def _comma_separated_list_validator(value: str | list[str]) -> list[str]:
def comma_separated_list_validator(value: str | list[str]) -> list[str]:
"""Validate a comma separated list."""
if isinstance(value, list):
return value
Expand All @@ -13,5 +13,5 @@ def _comma_separated_list_validator(value: str | list[str]) -> list[str]:

ValidatedTypes = List[str]
VALIDATORS: Final[dict[str, Callable[[str], ValidatedTypes]]] = {
"csv": _comma_separated_list_validator
"csv": comma_separated_list_validator
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
__all__ = ["FORMATTERS", "Formatter"]


from pydocstringformatter.formatting.base import Formatter
from pydocstringformatter.formatting.formatter import (
from pydocstringformatter._formatting.base import Formatter
from pydocstringformatter._formatting.formatter import (
BeginningQuotesFormatter,
CapitalizeFirstLetterFormatter,
ClosingQuotesFormatter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class StringFormatter(Formatter):
"""Base class for formatter that only modifies the string content."""

@abc.abstractmethod
def _treat_string(self, tokeninfo: tokenize.TokenInfo, indent_length: int) -> str:
def treat_string(self, tokeninfo: tokenize.TokenInfo, indent_length: int) -> str:
"""Return a modified string."""

def treat_token(self, tokeninfo: tokenize.TokenInfo) -> tokenize.TokenInfo:
return tokenize.TokenInfo(
tokeninfo.type,
self._treat_string(tokeninfo, tokeninfo.start[1]),
self.treat_string(tokeninfo, tokeninfo.start[1]),
tokeninfo.start,
tokeninfo.end,
tokeninfo.line,
Expand All @@ -68,7 +68,7 @@ class StringAndQuotesFormatter(Formatter):
"""Pattern to match against opening quotes."""

@abc.abstractmethod
def _treat_string(
def treat_string(
self,
tokeninfo: tokenize.TokenInfo,
indent_length: int,
Expand All @@ -88,7 +88,7 @@ def treat_token(self, tokeninfo: tokenize.TokenInfo) -> tokenize.TokenInfo:

return tokenize.TokenInfo(
tokeninfo.type,
self._treat_string(
self.treat_string(
tokeninfo,
tokeninfo.start[1],
quotes,
Expand All @@ -104,7 +104,7 @@ class SummaryAndDescriptionFormatter(StringAndQuotesFormatter):
"""Base class for formatter that modifies the summary and description."""

@abc.abstractmethod
def _treat_summary(
def treat_summary(
self,
summary: str,
indent_length: int,
Expand All @@ -114,12 +114,12 @@ def _treat_summary(
"""Return a modified summary."""

@abc.abstractmethod
def _treat_description(self, description: str, indent_length: int) -> str:
def treat_description(self, description: str, indent_length: int) -> str:
"""Return a modified description."""

@staticmethod
@functools.lru_cache(maxsize=None)
def _separate_summary_and_description(
def separate_summary_and_description(
docstring: str, indent_length: int, quotes_length: Literal[1, 3]
) -> tuple[str, str, str | None]:
"""Split the summary and description and handle quotes and indentation."""
Expand Down Expand Up @@ -153,26 +153,26 @@ def _separate_summary_and_description(
summary = summary[1 + indent_length :]
return prefix, summary, description

def _treat_string(
def treat_string(
self,
tokeninfo: tokenize.TokenInfo,
indent_length: int,
quotes: str,
quotes_length: Literal[1, 3],
) -> str:
prefix, summary, description = self._separate_summary_and_description(
prefix, summary, description = self.separate_summary_and_description(
tokeninfo.string,
indent_length,
quotes_length,
)

new_summary = self._treat_summary(
new_summary = self.treat_summary(
summary, indent_length, quotes_length, bool(description)
)
docstring = f"{quotes}{prefix}{new_summary}"

if description:
new_description = self._treat_description(description, indent_length)
new_description = self.treat_description(description, indent_length)
docstring += f"\n\n{new_description}"

# Determine whether ending quotes were initially on same or new line
Expand All @@ -185,7 +185,7 @@ class SummaryFormatter(SummaryAndDescriptionFormatter):
"""Base class for formatter that only modifies the summary of a docstring."""

@abc.abstractmethod
def _treat_summary(
def treat_summary(
self,
summary: str,
indent_length: int,
Expand All @@ -194,5 +194,5 @@ def _treat_summary(
) -> str:
"""Return a modified summary."""

def _treat_description(self, description: str, indent_length: int) -> str:
def treat_description(self, description: str, indent_length: int) -> str:
return description
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import tokenize
from typing import Literal

from pydocstringformatter.formatting import _utils
from pydocstringformatter.formatting.base import (
from pydocstringformatter._formatting import _utils
from pydocstringformatter._formatting.base import (
StringAndQuotesFormatter,
StringFormatter,
SummaryFormatter,
Expand All @@ -28,7 +28,7 @@ class BeginningQuotesFormatter(StringFormatter):
)
"""Regex pattern to match against a potential single line docstring."""

def _treat_string(self, tokeninfo: tokenize.TokenInfo, _: int) -> str:
def treat_string(self, tokeninfo: tokenize.TokenInfo, _: int) -> str:
new_string = tokeninfo.string
if new_string[3] == "\n":
if (
Expand All @@ -46,7 +46,7 @@ class CapitalizeFirstLetterFormatter(StringFormatter):
name = "capitalize-first-letter"
first_letter_re = re.compile(r"""['"]{1,3}\s*(\w)""", re.DOTALL)

def _treat_string(self, tokeninfo: tokenize.TokenInfo, _: int) -> str:
def treat_string(self, tokeninfo: tokenize.TokenInfo, _: int) -> str:
new_string = None
if match := self.first_letter_re.match(tokeninfo.string):
first_letter = match.end() - 1
Expand All @@ -64,7 +64,7 @@ class LineWrapperFormatter(SummaryFormatter):
name = "linewrap-full-docstring"
optional = True

def _treat_summary(
def treat_summary(
self,
summary: str,
indent_length: int,
Expand Down Expand Up @@ -120,7 +120,7 @@ class ClosingQuotesFormatter(StringFormatter):

name = "closing-quotes"

def _treat_string(self, tokeninfo: tokenize.TokenInfo, _: int) -> str:
def treat_string(self, tokeninfo: tokenize.TokenInfo, _: int) -> str:
"""Fix the position of end quotes for multi-line docstrings."""
new_string = tokeninfo.string
if "\n" not in new_string:
Expand All @@ -144,7 +144,7 @@ class FinalPeriodFormatter(SummaryFormatter):
name = "final-period"
END_OF_SENTENCE_PUNCTUATION = {".", "?", "!", "‽", ":", ";"}

def _treat_summary(
def treat_summary(
self,
summary: str,
indent_length: int,
Expand Down Expand Up @@ -180,7 +180,7 @@ class SplitSummaryAndDocstringFormatter(SummaryFormatter):
"""Pattern to match against an end of sentence period."""

# pylint: disable-next=too-many-branches
def _treat_summary(
def treat_summary(
self,
summary: str,
indent_length: int,
Expand Down Expand Up @@ -230,7 +230,7 @@ class StripWhitespacesFormatter(StringAndQuotesFormatter):

name = "strip-whitespaces"

def _treat_string(
def treat_string(
self,
tokeninfo: tokenize.TokenInfo,
indent_length: int,
Expand Down Expand Up @@ -275,7 +275,7 @@ class QuotesTypeFormatter(StringAndQuotesFormatter):

name = "quotes-type"

def _treat_string(
def treat_string(
self,
tokeninfo: tokenize.TokenInfo,
_: int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest

from pydocstringformatter import run_docstring_formatter
from pydocstringformatter.formatting import Formatter
from pydocstringformatter._formatting import Formatter

LOGGER = logging.getLogger(__name__)

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import git

from pydocstringformatter.testutils.primer.const import PRIMER_DIRECTORY_PATH
from pydocstringformatter._testutils.primer.const import PRIMER_DIRECTORY_PATH


@dataclass
class _PackageToPrime:
class PackageToPrime:
"""Represents data about a package to be tested during primer tests."""

url: str
Expand Down Expand Up @@ -58,13 +58,13 @@ def lazy_clone(self) -> None:


PACKAGES = {
"pylint": _PackageToPrime(
"pylint": PackageToPrime(
"https://github.com/PyCQA/pylint",
"main",
["pylint"],
["--max-summary-lines=2"],
),
"pydocstringformatter": _PackageToPrime(
"pydocstringformatter": PackageToPrime(
"https://github.com/DanielNoord/pydocstringformatter",
"main",
["pydocstringformatter"],
Expand Down
Loading