Skip to main content

Manage legacy code with comments.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yore-0.4.6.tar.gz (43.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yore-0.4.6-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file yore-0.4.6.tar.gz.

File metadata

  • Download URL: yore-0.4.6.tar.gz
  • Upload date:
  • Size: 43.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for yore-0.4.6.tar.gz
Algorithm Hash digest
SHA256 5308782d10033f162bdad5a06a8b7bda6921196775a5f7dad5380c5a03b9d318
MD5 2ace76afbbd639950f22d06af2395553
BLAKE2b-256 efc1f665fa0fbaf69344143a1d5dc60576ccebb8f0d90247605b96137b3081af

See more details on using hashes here.

File details

Details for the file yore-0.4.6-py3-none-any.whl.

File metadata

  • Download URL: yore-0.4.6-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for yore-0.4.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d382a1ae588f4cc4469d7624d862626c8eef45ddb4d75e5e97452e1db33fd4ee
MD5 cedad6f8e4b02afe5c68c568d0456c78
BLAKE2b-256 3174fb2ed267aa6dddf120996fb84bcea14d3930206de5cafc586e2b17062517

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page