yore ¤
yore package.
Manage legacy code with comments.
Classes:
-
CommandCheck
–Command to check Yore comments.
-
CommandDiff
–Command to diff Yore comments.
-
CommandFix
–Command to fix Yore comments.
-
CommandMain
–Command to manage legacy code in your code base with YORE comments.
-
Config
–Configuration for the insiders project.
-
Unset
–A sentinel value for unset configuration options.
-
YoreComment
–A Yore comment.
Functions:
-
config_field
–Create a dataclass field with a TOML key.
-
get_pattern
–Get the Yore comment pattern with a specific prefix.
-
main
–Run the main program.
-
yield_buffer_comments
–Yield all Yore comments in a buffer.
-
yield_directory_comments
–Yield all Yore comments in a directory.
-
yield_file_comments
–Yield all Yore comments in a file.
-
yield_files
–Yield all files in a directory.
-
yield_path_comments
–Yield all Yore comments in a file or directory.
Attributes:
-
COMMENT_PATTERN
(str
) –The Yore comment pattern, as a regular expression.
-
COMMENT_PREFIXES
(set[str]
) –The supported comment prefixes.
-
DEFAULT_EXCLUDE
–The default patterns to exclude when scanning directories.
-
DEFAULT_PREFIX
–The default prefix for Yore comments.
-
Scope
–The scope of a comment.
-
YoreKind
–The supported kinds of Yore comments.
-
python_dates
–A dictionary of Python versions and their Beginning/End of Life dates.
COMMENT_PATTERN module-attribute
¤
COMMENT_PATTERN: str = "\n (?P<kind>bol|bump|eol)\\ (?P<version>[^:]+):\\ (?:\n remove\\ (?P<remove>block|file|line)\n |\n replace\\ (?P<replace>block|file|line)\\ with\\ (?:\n line\\ (?P<line>\\d+)\n |\n lines\\ (?P<lines>[\\d, -]+)\n |\n `(?P<string>.+)`\n )\n |\n (?P<regex>regex-)?replace\\ `(?P<pattern1>.+)`\\ with\\ `(?P<pattern2>.*)`\\ within\\ (?P<within>block|file|line)\n )\n"
The Yore comment pattern, as a regular expression.
COMMENT_PREFIXES module-attribute
¤
COMMENT_PREFIXES: set[str] = {
"\\#\\ ",
"//\\ ",
"--\\ ",
";",
"%\\ ",
"'\\ ?",
"/\\*\\ ",
"<!--\\ ",
"\\{\\#-?\\ ",
"\\(\\*\\ ",
}
The supported comment prefixes.
DEFAULT_EXCLUDE module-attribute
¤
DEFAULT_EXCLUDE = ['.*', '__py*', 'build', 'dist']
The default patterns to exclude when scanning directories.
YoreKind module-attribute
¤
YoreKind = Literal['bump', 'eol', 'bol']
The supported kinds of Yore comments.
python_dates module-attribute
¤
python_dates = _LazyPythonDates()
A dictionary of Python versions and their Beginning/End of Life dates.
CommandCheck dataclass
¤
CommandCheck(
paths: list[Path] = list(),
bump: str | None = None,
eol_within: timedelta | None = None,
bol_within: timedelta | None = None,
prefix: str = DEFAULT_PREFIX,
)
Command to check Yore comments.
Methods:
-
__call__
–Check Yore comments.
Attributes:
-
bol_within
(timedelta | None
) –The time delta to start checking before the Beginning of Life of a Python version.
-
bump
(str | None
) –The next version of your project.
-
eol_within
(timedelta | None
) –The time delta to start checking before the End of Life of a Python version.
-
paths
(list[Path]
) –Path to files or directories to check.
-
prefix
(str
) –The prefix for Yore comments.
bol_within class-attribute
instance-attribute
¤
bol_within: timedelta | None = None
The time delta to start checking before the Beginning of Life of a Python version. It is provided in a human-readable format, like 2 weeks
or 1 month
. Spaces are optional, and the unit can be shortened to a single letter: d
for days, w
for weeks, m
for months, and y
for years.
eol_within class-attribute
instance-attribute
¤
eol_within: timedelta | None = None
The time delta to start checking before the End of Life of a Python version. It is provided in a human-readable format, like 2 weeks
or 1 month
. Spaces are optional, and the unit can be shortened to a single letter: d
for days, w
for weeks, m
for months, and y
for years.
paths class-attribute
instance-attribute
¤
Path to files or directories to check.
prefix class-attribute
instance-attribute
¤
prefix: str = DEFAULT_PREFIX
The prefix for Yore comments.
__call__ ¤
__call__() -> int
Check Yore comments.
Source code in src/yore/_internal/cli.py
135 136 137 138 139 140 141 142 |
|
CommandDiff dataclass
¤
CommandDiff(
paths: list[Path] = list(),
bump: str | None = None,
eol_within: timedelta | None = None,
bol_within: timedelta | None = None,
highlight: str | None = None,
prefix: str = DEFAULT_PREFIX,
)
Command to diff Yore comments.
Methods:
-
__call__
–Diff Yore comments.
Attributes:
-
bol_within
(timedelta | None
) –The time delta to start diffing before the Beginning of Life of a Python version.
-
bump
(str | None
) –The next version of your project.
-
eol_within
(timedelta | None
) –The time delta to start diffing before the End of Life of a Python version.
-
highlight
(str | None
) –The command to highlight diffs.
-
paths
(list[Path]
) –Path to files or directories to diff.
-
prefix
(str
) –The prefix for Yore comments.
bol_within class-attribute
instance-attribute
¤
bol_within: timedelta | None = None
The time delta to start diffing before the Beginning of Life of a Python version. It is provided in a human-readable format, like 2 weeks
or 1 month
. Spaces are optional, and the unit can be shortened to a single letter: d
for days, w
for weeks, m
for months, and y
for years.
eol_within class-attribute
instance-attribute
¤
eol_within: timedelta | None = None
The time delta to start diffing before the End of Life of a Python version. It is provided in a human-readable format, like 2 weeks
or 1 month
. Spaces are optional, and the unit can be shortened to a single letter: d
for days, w
for weeks, m
for months, and y
for years.
highlight class-attribute
instance-attribute
¤
highlight: str | None = None
The command to highlight diffs.
paths class-attribute
instance-attribute
¤
Path to files or directories to diff.
prefix class-attribute
instance-attribute
¤
prefix: str = DEFAULT_PREFIX
The prefix for Yore comments.
__call__ ¤
__call__() -> int
Diff Yore comments.
Source code in src/yore/_internal/cli.py
254 255 256 257 258 259 260 261 262 263 264 265 266 |
|
CommandFix dataclass
¤
CommandFix(
paths: list[Path] = list(),
bump: str | None = None,
eol_within: timedelta | None = None,
bol_within: timedelta | None = None,
prefix: str = DEFAULT_PREFIX,
)
Command to fix Yore comments.
Methods:
-
__call__
–Fix Yore comments.
Attributes:
-
bol_within
(timedelta | None
) –The time delta to start fixing before the Beginning of Life of a Python version.
-
bump
(str | None
) –The next version of your project.
-
eol_within
(timedelta | None
) –The time delta to start fixing before the End of Life of a Python version.
-
paths
(list[Path]
) –Path to files or directories to fix.
-
prefix
(str
) –The prefix for Yore comments.
bol_within class-attribute
instance-attribute
¤
bol_within: timedelta | None = None
The time delta to start fixing before the Beginning of Life of a Python version. It is provided in a human-readable format, like 2 weeks
or 1 month
. Spaces are optional, and the unit can be shortened to a single letter: d
for days, w
for weeks, m
for months, and y
for years.
eol_within class-attribute
instance-attribute
¤
eol_within: timedelta | None = None
The time delta to start fixing before the End of Life of a Python version. It is provided in a human-readable format, like 2 weeks
or 1 month
. Spaces are optional, and the unit can be shortened to a single letter: d
for days, w
for weeks, m
for months, and y
for years.
paths class-attribute
instance-attribute
¤
Path to files or directories to fix.
prefix class-attribute
instance-attribute
¤
prefix: str = DEFAULT_PREFIX
The prefix for Yore comments.
__call__ ¤
__call__() -> int
Fix Yore comments.
Source code in src/yore/_internal/cli.py
357 358 359 360 361 362 363 364 365 366 |
|
CommandMain dataclass
¤
CommandMain(
subcommand: Subcommands[
CommandCheck | CommandDiff | CommandFix
],
config: Config = _load_config(),
version: bool = False,
debug_info: bool = False,
)
Command to manage legacy code in your code base with YORE comments.
Attributes:
-
config
(Config
) –Path to the configuration file.
-
debug_info
(bool
) –Print debug information.
-
subcommand
(Subcommands[CommandCheck | CommandDiff | CommandFix]
) –The selected subcommand.
-
version
(bool
) –Version CLI option.
config class-attribute
instance-attribute
¤
Path to the configuration file.
subcommand instance-attribute
¤
subcommand: Subcommands[
CommandCheck | CommandDiff | CommandFix
]
The selected subcommand.
Config dataclass
¤
Config(
prefix: list[str] | Unset = config_field("prefix"),
diff_highlight: str | Unset = config_field(
"diff.highlight"
),
)
Configuration for the insiders project.
Methods:
-
from_data
–Load configuration from data.
-
from_default_locations
–Load configuration from the default locations.
-
from_file
–Load configuration from a file.
-
from_pyproject
–Load configuration from pyproject.toml.
Attributes:
-
diff_highlight
(str | Unset
) –The command to highlight diffs.
-
prefix
(list[str] | Unset
) –The prefix for Yore comments.
diff_highlight class-attribute
instance-attribute
¤
diff_highlight: str | Unset = config_field("diff.highlight")
The command to highlight diffs.
prefix class-attribute
instance-attribute
¤
prefix: list[str] | Unset = config_field('prefix')
The prefix for Yore comments.
from_data classmethod
¤
Load configuration from data.
Parameters:
Returns:
-
Config
–Loaded configuration.
Source code in src/yore/_internal/config.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
from_default_locations classmethod
¤
from_default_locations() -> Config
Load configuration from the default locations.
Returns:
-
Config
–Loaded configuration.
Source code in src/yore/_internal/config.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
from_file classmethod
¤
Load configuration from a file.
Parameters:
Returns:
-
Config
–Loaded configuration.
Source code in src/yore/_internal/config.py
122 123 124 125 126 127 128 129 |
|
from_pyproject classmethod
¤
Load configuration from pyproject.toml.
Parameters:
Returns:
-
Config
–Loaded configuration.
Source code in src/yore/_internal/config.py
131 132 133 134 135 136 137 138 |
|
Unset ¤
A sentinel value for unset configuration options.
Parameters:
-
key
¤str
) –TOML key.
-
transform
¤str | None
, default:None
) –Name of the method to call to transform the config value.
Methods:
-
__bool__
–An unset value always evaluates to False.
Attributes:
-
key
(str
) –TOML key.
-
name
(str
) –Transformed key name.
-
transform
(str | None
) –Name of the method to call to transform the config value.
Source code in src/yore/_internal/config.py
29 30 31 32 33 34 35 36 |
|
transform instance-attribute
¤
Name of the method to call to transform the config value.
YoreComment dataclass
¤
YoreComment(
file: Path,
lineno: int,
raw: str,
prefix: str,
suffix: str,
kind: YoreKind,
version: str,
remove: Scope | None = None,
replace: Scope | None = None,
line: int | None = None,
lines: list[int] | None = None,
string: str | None = None,
regex: bool = False,
pattern1: str | None = None,
pattern2: str | None = None,
within: Scope | None = None,
)
A Yore comment.
Methods:
Attributes:
-
bol
(date
) –The Beginning of Life date for the Python version.
-
comment
(str
) –The comment without the prefix.
-
eol
(date
) –The End of Life date for the Python version.
-
file
(Path
) –The file containing comment.
-
is_bol
(bool
) –Whether the comment is an End of Life comment.
-
is_bump
(bool
) –Whether the comment is a bump comment.
-
is_eol
(bool
) –Whether the comment is an End of Life comment.
-
kind
(YoreKind
) –The kind of comment.
-
line
(int | None
) –The line to replace.
-
lineno
(int
) –The line number of the comment.
-
lines
(list[int] | None
) –The lines to replace.
-
pattern1
(str | None
) –The pattern to replace.
-
pattern2
(str | None
) –The replacement pattern.
-
prefix
(str
) –The prefix of the comment.
-
raw
(str
) –The raw comment.
-
regex
(bool
) –Whether to use regex for replacement.
-
remove
(Scope | None
) –The removal scope.
-
replace
(Scope | None
) –The replacement scope.
-
string
(str | None
) –The string to replace.
-
suffix
(str
) –The suffix of the comment.
-
version
(str
) –The EOL/bump version.
-
within
(Scope | None
) –The scope to replace within.
regex class-attribute
instance-attribute
¤
regex: bool = False
Whether to use regex for replacement.
within class-attribute
instance-attribute
¤
within: Scope | None = None
The scope to replace within.
check ¤
check(
*,
bump: str | None = None,
eol_within: timedelta | None = None,
bol_within: timedelta | None = None,
) -> bool
Check the comment.
Parameters:
-
bump
¤str | None
, default:None
) –The next version of the project.
-
eol_within
¤timedelta | None
, default:None
) –The time delta to start warning before the End of Life of a Python version.
-
bol_within
¤timedelta | None
, default:None
) –The time delta to start warning before the Beginning of Life of a Python version.
Returns:
-
bool
–True when there is nothing to do, False otherwise.
Source code in src/yore/_internal/lib.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
fix ¤
fix(
buffer: list[str] | None = None,
*,
bump: str | None = None,
eol_within: timedelta | None = None,
bol_within: timedelta | None = None,
) -> bool
Fix the comment and code below it.
Parameters:
-
buffer
¤list[str] | None
, default:None
) –The buffer to fix. If not provided, read from and write to the file.
-
bump
¤str | None
, default:None
) –The next version of the project.
-
eol_within
¤timedelta | None
, default:None
) –The time delta to start fixing before the End of Life of a Python version.
-
bol_within
¤timedelta | None
, default:None
) –The time delta to start fixing before the Beginning of Life of a Python version.
Returns:
-
bool
–Whether the comment was fixed.
Source code in src/yore/_internal/lib.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
config_field ¤
Create a dataclass field with a TOML key.
Parameters:
-
key
¤str
) –Key within the config file.
-
transform
¤str | None
, default:None
) –Name of transformation method to apply.
Returns:
-
Unset
–Configuration field.
Source code in src/yore/_internal/config.py
50 51 52 53 54 55 |
|
get_pattern cached
¤
get_pattern(prefix: str = DEFAULT_PREFIX) -> Pattern
Get the Yore comment pattern with a specific prefix.
Parameters:
-
prefix
¤str
, default:DEFAULT_PREFIX
) –The prefix to use in the pattern.
Returns:
-
Pattern
–The Yore comment pattern.
Source code in src/yore/_internal/lib.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
|
main ¤
Run the main program.
This function is executed when you type yore
or python -m yore
.
Parameters:
Returns:
-
int
–An exit code.
Source code in src/yore/_internal/cli.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
|
yield_buffer_comments ¤
yield_buffer_comments(
file: Path,
lines: list[str],
*,
prefix: str = DEFAULT_PREFIX,
) -> Iterator[YoreComment]
Yield all Yore comments in a buffer.
Parameters:
-
file
¤Path
) –The file to check.
-
lines
¤list[str]
) –The buffer to check (pre-read lines).
-
prefix
¤str
, default:DEFAULT_PREFIX
) –The prefix to look for in the comments.
Yields:
-
YoreComment
–Yore comments.
Source code in src/yore/_internal/lib.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
|
yield_directory_comments ¤
yield_directory_comments(
directory: Path, *, prefix: str = DEFAULT_PREFIX
) -> Iterator[YoreComment]
Yield all Yore comments in a directory.
Parameters:
-
directory
¤Path
) –The directory to check.
-
prefix
¤str
, default:DEFAULT_PREFIX
) –The prefix to look for in the comments.
Yields:
-
YoreComment
–Yore comments.
Source code in src/yore/_internal/lib.py
436 437 438 439 440 441 442 443 444 445 446 447 |
|
yield_file_comments ¤
yield_file_comments(
file: Path, *, prefix: str = DEFAULT_PREFIX
) -> Iterator[YoreComment]
Yield all Yore comments in a file.
Parameters:
-
file
¤Path
) –The file to check.
-
prefix
¤str
, default:DEFAULT_PREFIX
) –The prefix to look for in the comments.
Yields:
-
YoreComment
–Yore comments.
Source code in src/yore/_internal/lib.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
|
yield_files ¤
Yield all files in a directory.
Source code in src/yore/_internal/lib.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
|
yield_path_comments ¤
yield_path_comments(
path: Path, *, prefix: str = DEFAULT_PREFIX
) -> Iterator[YoreComment]
Yield all Yore comments in a file or directory.
Parameters:
-
path
¤Path
) –The file or directory to check.
-
prefix
¤str
, default:DEFAULT_PREFIX
) –The prefix to look for in the comments.
Yields:
-
YoreComment
–Yore comments.
Source code in src/yore/_internal/lib.py
450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
|