Skip to content

Commit da301ab

Browse files
Use importlib.metadata to obtain the version in __init__.py
1 parent 75786f6 commit da301ab

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

Diff for: setup.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
#!/usr/bin/env python
22
import os
3-
import re
43

54
from setuptools import find_packages, setup
65

76
with open(os.path.join(os.path.dirname(__file__), "README.rst")) as f:
87
long_description = f.read()
98

109

11-
def get_version(package):
12-
"""
13-
Return package version as listed in `__version__` in `__init__.py`.
14-
"""
15-
path = os.path.join(os.path.dirname(__file__), "src", package, "__init__.py")
16-
with open(path, "rb") as f:
17-
init_py = f.read().decode("utf-8")
18-
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)
19-
20-
2110
setup(
2211
name="prompt_toolkit",
2312
author="Jonathan Slenders",
24-
version=get_version("prompt_toolkit"),
13+
version="3.0.50",
2514
url="https://github.com/prompt-toolkit/python-prompt-toolkit",
2615
description="Library for building powerful interactive command lines in Python",
2716
long_description=long_description,

Diff for: src/prompt_toolkit/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from __future__ import annotations
1818

1919
import re
20+
from importlib import metadata
2021

2122
# note: this is a bit more lax than the actual pep 440 to allow for a/b/rc/dev without a number
2223
pep440 = re.compile(
@@ -28,7 +29,7 @@
2829
from .shortcuts import PromptSession, print_formatted_text, prompt
2930

3031
# Don't forget to update in `docs/conf.py`!
31-
__version__ = "3.0.50"
32+
__version__ = metadata.version("prompt_toolkit")
3233

3334
assert pep440.match(__version__)
3435

0 commit comments

Comments
 (0)