From c456c97626ca00add73dd3b9b8f223d4410b95ac Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Wed, 18 Oct 2023 20:00:41 -0500 Subject: [PATCH] Move version from const.py to __init__.py for Flit static introspection (cherry picked from commit praw-dev/prawcore@6a6c46383a4cfe648ceb87e8870fa262287f1c6d) --- asyncprawcore/__init__.py | 3 ++- asyncprawcore/const.py | 2 -- asyncprawcore/requestor.py | 5 ++++- tools/set_version.py | 6 +++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/asyncprawcore/__init__.py b/asyncprawcore/__init__.py index c5960e0..4e46719 100644 --- a/asyncprawcore/__init__.py +++ b/asyncprawcore/__init__.py @@ -11,9 +11,10 @@ TrustedAuthenticator, UntrustedAuthenticator, ) -from .const import __version__ from .exceptions import * # noqa: F403 from .requestor import Requestor from .sessions import Session, session logging.getLogger(__package__).addHandler(logging.NullHandler()) + +__version__ = "2.4.1.dev0" diff --git a/asyncprawcore/const.py b/asyncprawcore/const.py index 2f7bf8a..47dd4e6 100644 --- a/asyncprawcore/const.py +++ b/asyncprawcore/const.py @@ -1,8 +1,6 @@ """Constants for the asyncprawcore package.""" import os -__version__ = "2.4.1.dev0" - ACCESS_TOKEN_PATH = "/api/v1/access_token" # noqa: S105 AUTHORIZATION_PATH = "/api/v1/authorize" # noqa: S105 REVOKE_TOKEN_PATH = "/api/v1/revoke_token" # noqa: S105 diff --git a/asyncprawcore/requestor.py b/asyncprawcore/requestor.py index a5830da..65e3caa 100644 --- a/asyncprawcore/requestor.py +++ b/asyncprawcore/requestor.py @@ -7,7 +7,7 @@ import aiohttp from aiohttp import ClientSession -from .const import TIMEOUT, __version__ +from .const import TIMEOUT from .exceptions import InvalidInvocation, RequestException if TYPE_CHECKING: @@ -48,6 +48,9 @@ def __init__( giving up (default: ``asyncprawcore.const.TIMEOUT``). """ + # Imported locally to avoid an import cycle, with __init__ + from . import __version__ + if user_agent is None or len(user_agent) < 7: msg = "user_agent is not descriptive" raise InvalidInvocation(msg) diff --git a/tools/set_version.py b/tools/set_version.py index e07cea7..1a2429b 100755 --- a/tools/set_version.py +++ b/tools/set_version.py @@ -41,7 +41,7 @@ def handle_version(version): def increment_development_version(): - with open("asyncprawcore/const.py") as fp: + with open("asyncprawcore/__init__.py") as fp: version = re.search('__version__ = "([^"]+)"', fp.read()).group(1) parsed_version = valid_version(version) @@ -89,7 +89,7 @@ def update_changelog(version): def update_package(version): - with open("asyncprawcore/const.py") as fp: + with open("asyncprawcore/__init__.py") as fp: content = fp.read() updated = re.sub('__version__ = "([^"]+)"', f'__version__ = "{version}"', content) @@ -97,7 +97,7 @@ def update_package(version): sys.stderr.write("Package version string not changed\n") return False - with open("asyncprawcore/const.py", "w") as fp: + with open("asyncprawcore/__init__.py", "w") as fp: fp.write(updated) print(version)