Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move version from const.py to __init__.py for Flit static introspection #165

Merged
merged 3 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion prawcore/__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 prawcore/const.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Constants for the prawcore 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
8 changes: 6 additions & 2 deletions prawcore/requestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import requests

from .const import TIMEOUT, __version__
import prawcore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do a local relative import.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done as requested 👍


from .const import TIMEOUT
from .exceptions import InvalidInvocation, RequestException

if TYPE_CHECKING:
Expand Down Expand Up @@ -50,7 +52,9 @@ def __init__(
raise InvalidInvocation(msg)

self._http = session or requests.Session()
self._http.headers["User-Agent"] = f"{user_agent} prawcore/{__version__}"
self._http.headers[
"User-Agent"
] = f"{user_agent} prawcore/{prawcore.__version__}"

self.oauth_url = oauth_url
self.reddit_url = reddit_url
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("prawcore/const.py") as fp:
with open("prawcore/__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("prawcore/const.py") as fp:
with open("prawcore/__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("prawcore/const.py", "w") as fp:
with open("prawcore/__init__.py", "w") as fp:
fp.write(updated)

print(version)
Expand Down
Loading