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 | NoneThe time delta to start checking before the Beginning of Life of a Python version.
-
(bump ) –str | NoneThe next version of your project.
-
(eol_within ) –timedelta | NoneThe 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
¤
paths: list [Path ] = field (default_factory =list )
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
126 127 128 129 130 131 132 133 | |
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 | NoneThe time delta to start diffing before the Beginning of Life of a Python version.
-
(bump ) –str | NoneThe next version of your project.
-
(eol_within ) –timedelta | NoneThe time delta to start diffing before the End of Life of a Python version.
-
(highlight ) –str | NoneThe 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
¤
paths: list [Path ] = field (default_factory =list )
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
244 245 246 247 248 249 250 251 252 253 254 255 256 | |
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 | NoneThe time delta to start fixing before the Beginning of Life of a Python version.
-
(bump ) –str | NoneThe next version of your project.
-
(eol_within ) –timedelta | NoneThe 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
¤
paths: list [Path ] = field (default_factory =list )
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
346 347 348 349 350 351 352 353 354 355 | |
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
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
¤
from_data(data : Mapping [str , Any ]) -> Config
Load configuration from data.
Parameters:
-
(data¤) –Mapping [str ,Any ]Data to load configuration from.
Returns:
-
–Config Loaded configuration.
Source code in src/yore/_internal/config.py
82 83 84 85 86 87 88 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 | |
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
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
from_file
classmethod
¤
from_file(path : str | Path ) -> Config
Load configuration from a file.
Parameters:
-
(path¤) –str |Path Path to the configuration file.
Returns:
-
–Config Loaded configuration.
Source code in src/yore/_internal/config.py
115 116 117 118 119 120 121 122 | |
from_pyproject
classmethod
¤
from_pyproject(path : str | Path ) -> Config
Load configuration from pyproject.toml.
Parameters:
-
(path¤) –str |Path Path to the pyproject.toml file.
Returns:
-
–Config Loaded configuration.
Source code in src/yore/_internal/config.py
124 125 126 127 128 129 130 131 | |
Unset
¤
Unset(key : str , transform : str | None = None)
A sentinel value for unset configuration options.
Parameters:
-
(key¤) –str TOML key.
-
(transform¤, default:str | NoneNone) –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 | NoneName 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
¤
transform: str | None = transform
Name of the method to call to transform the config value.
__bool__
¤
__bool__() -> bool
An unset value always evaluates to False.
Source code in src/yore/_internal/config.py
38 39 40 | |
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:
-
–check Check the comment.
-
–fix Fix the comment and code below it.
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 | NoneThe line to replace.
-
(lineno ) –int The line number of the comment.
-
(lines ) –list [int ] | NoneThe lines to replace.
-
(pattern1 ) –str | NoneThe pattern to replace.
-
(pattern2 ) –str | NoneThe replacement pattern.
-
(prefix ) –str The prefix of the comment.
-
(raw ) –str The raw comment.
-
(regex ) –bool Whether to use regex for replacement.
-
(remove ) –Scope | NoneThe removal scope.
-
(replace ) –Scope | NoneThe replacement scope.
-
(string ) –str | NoneThe string to replace.
-
(suffix ) –str The suffix of the comment.
-
(version ) –str The EOL/bump version.
-
(within ) –Scope | NoneThe 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¤, default:str | NoneNone) –The next version of the project.
-
(eol_within¤, default:timedelta | NoneNone) –The time delta to start warning before the End of Life of a Python version.
-
(bol_within¤, default:timedelta | NoneNone) –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
198 199 200 201 202 203 204 205 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 245 246 | |
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¤, default:list [str ] | NoneNone) –The buffer to fix. If not provided, read from and write to the file.
-
(bump¤, default:str | NoneNone) –The next version of the project.
-
(eol_within¤, default:timedelta | NoneNone) –The time delta to start fixing before the End of Life of a Python version.
-
(bol_within¤, default:timedelta | NoneNone) –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
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 317 318 | |
config_field
¤
config_field(
key : str , transform : str | None = None
) -> Unset
Create a dataclass field with a TOML key.
Parameters:
-
(key¤) –str Key within the config file.
-
(transform¤, default:str | NoneNone) –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¤, default:str ) –DEFAULT_PREFIX The prefix to use in the pattern.
Returns:
-
–Pattern The Yore comment pattern.
Source code in src/yore/_internal/lib.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
main
¤
main(args : list [str ] | None = None) -> int
Run the main program.
This function is executed when you type yore or python -m yore.
Parameters:
-
(args¤, default:list [str ] | NoneNone) –Arguments passed from the command line.
Returns:
-
–int An exit code.
Source code in src/yore/_internal/cli.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
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¤, default:str ) –DEFAULT_PREFIX The prefix to look for in the comments.
Yields:
-
–YoreComment Yore comments.
Source code in src/yore/_internal/lib.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
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¤, default:str ) –DEFAULT_PREFIX The prefix to look for in the comments.
Yields:
-
–YoreComment Yore comments.
Source code in src/yore/_internal/lib.py
438 439 440 441 442 443 444 445 446 447 448 449 | |
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¤, default:str ) –DEFAULT_PREFIX The prefix to look for in the comments.
Yields:
-
–YoreComment Yore comments.
Source code in src/yore/_internal/lib.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | |
yield_files
¤
yield_files(
directory : Path , exclude : list [str ] | None = None
) -> Iterator [Path ]
Yield all files in a directory.
Source code in src/yore/_internal/lib.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
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¤, default:str ) –DEFAULT_PREFIX The prefix to look for in the comments.
Yields:
-
–YoreComment Yore comments.
Source code in src/yore/_internal/lib.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |