Skip to content

Commit

Permalink
Merge pull request #70 from praw-dev/fix-dynamic-version-import
Browse files Browse the repository at this point in the history
Move version from const.py to __init__.py for Flit static introspection
  • Loading branch information
LilSpazJoekp committed Nov 27, 2023
2 parents 609ef2f + c456c97 commit a22de4d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion asyncprawcore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 0 additions & 2 deletions asyncprawcore/const.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion asyncprawcore/requestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tools/set_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -89,15 +89,15 @@ 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)
if content == updated:
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)
Expand Down

0 comments on commit a22de4d

Please sign in to comment.