-
Notifications
You must be signed in to change notification settings - Fork 235
Refactor the _get_module_version function using importlib and add two more tests #3538
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
Conversation
8d02283 to
c6b3c70
Compare
| "ghostscript": _get_ghostscript_version(), | ||
| } | ||
| ) | ||
| requirements = [Requirement(v).name for v in requires("pygmt")] + ["gdal"] # type: ignore[union-attr] |
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.
Previously, we have to use _get_module_version("osgeo.gdal"), now we can use _get_module_version("gdal").
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.
Nice to see that importlib.metadata.version("gdal") works!
c6b3c70 to
86daafb
Compare
weiji14
left a comment
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.
| "ghostscript": _get_ghostscript_version(), | ||
| } | ||
| ) | ||
| requirements = [Requirement(v).name for v in requires("pygmt")] + ["gdal"] # type: ignore[union-attr] |
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.
Nice to see that importlib.metadata.version("gdal") works!
The private
_get_module_versionfunction was initially added 4 years ago in PR #466. At that time, we supported Python 3.6-3.8 andimportlib.metadatawas not available yet.importlib.metadatawas added in Python 3.8. With this module, getting package version can be greatly simplified.This PR simplifies the
_get_module_versionfunction and also add two more tests related to Ghostscript to increase code coverage by 0.16% (now we reach 98.49%).Without optional packages:
With optional packages: