Skip to content

move __version__ and user_agent to library-level constants to improve performance #258

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

Closed
jreiberkyle opened this issue Mar 16, 2021 · 2 comments

Comments

@jreiberkyle
Copy link
Contributor

Consider raising _get_user_agent() to a class or module-level constant instead of a non-public static method for UX as well as performance.

Originally posted by @ericrdunham in #240 (comment)

Jen comments: I like this suggestion. I don't like having to update the user agent to stay up to date with the version. I am not sure I really like the pattern of having a module called __version__.py that basically holds a constant, __version__ = 'blah'.

Possible implementation

add lines to constants.py:

VERSION = 'blah'
USER_AGENT = 'planet_client_python/' + VERSION
@jreiberkyle
Copy link
Contributor Author

All the examples of clients I’m seeing are either specifying version in __version__.py or __init__.py

I’m thinking this is because one needs to be able to get the version from the library with

import planet
planet.__version__

example of user_agent being specified as a module-level constant: https://github.com/encode/httpx/blob/master/httpx/_client.py#L67

@jreiberkyle
Copy link
Contributor Author

result from team discussion: have __version__ specified in either __init__.py or __version__.py

refs:
https://www.python.org/dev/peps/pep-0008/#module-level-dunder-names
https://packaging.python.org/guides/single-sourcing-package-version/#single-sourcing-the-version

@jreiberkyle jreiberkyle added this to the V2 Release milestone Mar 24, 2021
@cholmes cholmes closed this as completed Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants