-
Notifications
You must be signed in to change notification settings - Fork 306
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
Add version as an importable variable and remove dependency on pkg_resources
#566
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR !
Just one comment, LGTM otherwise.
datadog/util/config.py
Outdated
def get_pkg_version(): | ||
""" | ||
Resolve `datadog` package version. | ||
""" | ||
if not pkg: | ||
return u"unknown" | ||
|
||
dist = pkg.get_distribution("datadog") | ||
# Normalize case for Windows systems | ||
dist_loc = os.path.normcase(dist.location) | ||
here = os.path.normcase(__file__) | ||
if not here.startswith(dist_loc): | ||
# not installed, but there is another version that *is* | ||
raise pkg.DistributionNotFound | ||
|
||
return dist.version | ||
|
||
|
||
def get_version(): | ||
""" | ||
Resolve `datadog` package version. | ||
""" | ||
try: | ||
return get_pkg_version() | ||
except pkg.DistributionNotFound: | ||
return u"Please install `datadog` with setup.py" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep these two functions for compatibility, in case some people use it in their code.
Just make them return the __version__
variable, and maybe add a comment in the docstring we're keeping them for compatibility but user should import __version__
from version
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 done
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
pkg_resources
What does this PR do?
Remove the dependency on
pkg_resources
by moving the version todatadog/version.py
Description of the Change
importing of
pkg_resources
can be slow as it does a lot of import-time processing (see pypa/setuptools#926, pypa/setuptools#510)This change moves the version from
setup.py
into a file inside the datadog module so that it can be imported from other locations in the code (most notably it can be imported from the dogstatsd module without causing a circular import)Alternate Designs
This document outlines the possible approaches: https://packaging.python.org/guides/single-sourcing-package-version/
pkg_resources
Possible Drawbacks
The main drawback is that it is a change to the release process, which may cause a small amount of friction when releasing a new version.
Verification Process
python setup.py --version
Review checklist (to be filled by reviewers)
changelog/
label attached. If applicable it should have thebackward-incompatible
label attached.do-not-merge/
label attached.kind/
andseverity/
labels attached at least.