Skip to content

Commit

Permalink
Generate module version file at build
Browse files Browse the repository at this point in the history
Gunicore rely on `eventlet.__version__` [1], however
this data have been removed during our modernization
of the continuous deployment mechanisms [2].

People reported problem with gunicore after 0.34.1 [3][4],
so, it could be worth to reintroduce similar version info,
to avoid side effects.

This patch propose to use a `hatch-vcs` hook [5] to generate
dynamically, at build, the missing data. Other solutions exists
but each of them have their own problems [6].

Indeed, considering "footgun" described in [6] I choose the
hatch-vcs approach, because, retrieving a wrong version number
during development when the lib is installed in editable mode,
is not, I think, something horrible. I prefer this side effect
rather than relying on another additional underlying library
just to print a version number when eventlet is installed in
editable mode. A new additional requirement which would be
installed anytime at runtime and production.

Moreover, sometimes you want to import a package from a
development repository tarball you just downloaded (where
there's no metadata or Git tags present). So, Using
`setuptools_scm` or `importlib.metadata.version` won't
works in that context.

Fix benoitc/gunicorn#3120

Also, update the supported python to 3.7 in a remaining
condition. Python 3.5 is not supported anymore.

[1] benoitc/gunicorn#3120
[2] #845
[3] #845 (comment)
[4] #842 (comment)
[5] https://github.com/ofek/hatch-vcs#build-hook
[6] https://github.com/maresb/hatch-vcs-footgun-example
  • Loading branch information
4383 committed Dec 22, 2023
1 parent b738b0a commit 1b4bf7f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
18 changes: 15 additions & 3 deletions eventlet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import sys
import warnings

if sys.version_info < (3, 5):
if sys.version_info < (3, 7):
warnings.warn(
"Support for your Python version is deprecated and will be removed in the future",
"""Your Python version is no longer supported by eventlet
Please consider upgrading to minimal supported Python version""",
DeprecationWarning,
)

from eventlet import convenience
from eventlet import event
from eventlet import greenpool
Expand All @@ -17,7 +17,19 @@
from eventlet import semaphore
from eventlet import support
from eventlet import timeout
# NOTE(hberaud): Versions are now managed by hatch and control version.
# hatch has a build hook which generates the version file, however,
# if the project is installed in editable mode then the _version.py file
# will not be updated unless the package is reinstalled (or locally rebuilt).
# For further details, please read:
# https://github.com/ofek/hatch-vcs#build-hook
# https://github.com/maresb/hatch-vcs-footgun-example
try:
from eventlet._version import __version__
except ImportError:
__version__ = "0.0.0"

Check warning on line 30 in eventlet/__init__.py

View check run for this annotation

Codecov / codecov/patch

eventlet/__init__.py#L29-L30

Added lines #L29 - L30 were not covered by tests
import greenlet

# Force monotonic library search as early as possible.
# Helpful when CPython < 3.5 on Linux blocked in `os.waitpid(-1)` before first use of hub.
# Example: gunicorn
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ exclude = ["tests*", "benchmarks", "examples"]

[tool.hatch]
version.source = "vcs"

[tool.hatch.build.hooks.vcs]
version-file = "eventlet/_version.py"

0 comments on commit 1b4bf7f

Please sign in to comment.