Skip to main content

yore

ci documentation pypi version gitter

Manage legacy code with comments.

In days of yore, ancients penned scripts of eld, their legacy code a relic of arcane lore. These venerable lines, cryptic and profound, whisper the wisdom of bygone masters, shaping our digital realm's very ground.

— ChatGPT the Sage

With time, the code base of your project evolves. You add features, you fix bugs, and you generally reorganize code. Some of these changes might make your project's public API incompatible with previous versions. In that case, you usually have to "deprecate" previous usage in favor of the new usage. That means you have to support both usages, and emit deprecation warnings when old usage is detected.

Sometimes, you don't change anything in an incompatible way, but you want to support multiple versions of Python which provide different, incompatible APIs, or for which libraries you depend on provide different, incompatible APIs. In that case, you have to write multiple code branches to support the different Python versions. The code branches for versions of Python older than the latest one are what we call legacy code. Ideally you'd want to only use the API and features of the latest Python version, but your users are sometimes stuck with older versions, and you want to follow the official Python release cycle, which promises support for a certain amount of time after initial release for each minor version (3.11, 3.12, etc.). At the time of writing (2024, see Python release cycle for up-to-date information), each minor version is supported for approximately 5 years. There's a new minor version each year, so if you follow the release cycle, you maintain support for a window of 5 minor Python versions at any time. Sometimes you will have to support much older versions...

For these use-cases, Yore comes to the rescue.

Yore was born from the will of automating comments I had added along the evolution of my projects. I was usually writing comments such as TODO: Remove once support for Python 3.8 is dropped, or TODO: Remove when we are ready for v1. One day I decided to make these comments more formal, so I designed a very simple syntax and wrote a tool that would parse them and act on them.

Yore can therefore find comments in your code base, to warn you about upcoming end-of-life dates of Python versions, or outdated code based on the project version. It can also apply transformations to your code, to remove legacy blocks or lines of code or update them.

Yore is language agnostic. It works with many of the most popular languages. For now it only supports beginning/end of life dates for Python, but in the future it will likely support more.

Quick usage

Write Yore comments:

# YORE: EOL 3.8: Replace block with line 4.
if sys.version_info < (3, 9):
    from astunparse import unparse
else:
    from ast import unparse

Check your code base:

$ yore check --eol-within '5 months'
./src/griffe/agents/nodes/_values.py:11: Python 3.8 will reach its End of Life within approx. 4 months

Fix your code base:

$ yore fix --eol-within '5 months'
fixed 1 comment in ./src/griffe/agents/nodes/_values.py
diff --git a/src/griffe/agents/nodes/_values.py b/src/griffe/agents/nodes/_values.py
index 59bfacac..2f6eaa88 100644
--- a/src/griffe/agents/nodes/_values.py
+++ b/src/griffe/agents/nodes/_values.py
@@ -8,11 +8,7 @@ from typing import TYPE_CHECKING

 from griffe.logger import get_logger

-# YORE: EOL 3.8: Replace block with line 4.
-if sys.version_info < (3, 9):
-    from astunparse import unparse
-else:
-    from ast import unparse
+from ast import unparse

 if TYPE_CHECKING:
     from pathlib import Path

See the usage documentation.

Installation

pip install yore

With uv:

uv tool install yore

Sponsors

Release files for yore 0.4.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yore 0.4.7
File Size Uploaded
yore-0.4.7.tar.gz 43.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yore 0.4.7
File Interpreter ABI Platform
yore-0.4.7-py3-none-any.whl Python 3 none any Details

Total release size: 60.6 kB

Release files / yore-0.4.7.tar.gz

Download URL yore-0.4.7.tar.gz
Size 43.2 kB
Tags Source
SHA-256 checksum
How to use checksums
45279f8aabbe9b261220c8b8848ea045a4fa7def1376cab16712415bae9c8491
BLAKE2b-256 checksum
How to use checksums
d681eff41e135c4dc57db6cb96badefa82b5ed6704982f8620b91c57e65666e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / yore-0.4.7-py3-none-any.whl

Download URL yore-0.4.7-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02f6f9ea7eb71754c7bc92216d4fa40574d81e725a174a3a1674a65286c68a1c
BLAKE2b-256 checksum
How to use checksums
c5ce867b1c034d48da93923a958f478e21feb5c6974a6275d04d9052f8a8bf84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.4.7 This release

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page