-
Notifications
You must be signed in to change notification settings - Fork 59
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
Replace pkg_resources #232
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
01e9f36
Replace deprecated PdfMerger with PdfWriter by updating PyPDF2 2.12.*…
odkhang 036bbde
Merge branch 'fossasia:development' into development
odkhang 75694ef
remove package file
odkhang 5519f43
Replace PyPDF2 by pypdf
odkhang bd0dd3b
Merge branch 'development' into development
mariobehling de92169
Merge branch 'fossasia:development' into development
odkhang 30d8dc5
Implement option to add link to privacy policy
odkhang 155bd54
Revert "Implement option to add link to privacy policy"
odkhang bb15072
Merge branch 'fossasia:development' into development
odkhang 97070a2
Merge branch 'fossasia:development' into development
odkhang 0fc9b51
Merge branch 'fossasia:development' into development
odkhang ee8f607
Merge branch 'fossasia:development' into development
odkhang 4014fe4
Replace pkg_resources with import importlib_metadata
odkhang d42f03c
Fix code review
odkhang 9d89dad
Improve logging by passing variables as parameters
odkhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from django.apps import AppConfig, apps | ||
from django.conf import settings | ||
from django.core.exceptions import ImproperlyConfigured | ||
import importlib.metadata | ||
|
||
|
||
class PluginType(Enum): | ||
|
@@ -53,12 +54,38 @@ def __init__(self, *args, **kwargs): | |
raise ImproperlyConfigured("A pretix plugin config should have a PretixPluginMeta inner class.") | ||
|
||
if hasattr(self.PretixPluginMeta, 'compatibility') and not os.environ.get("PRETIX_IGNORE_CONFLICTS") == "True": | ||
import pkg_resources | ||
try: | ||
pkg_resources.require(self.PretixPluginMeta.compatibility) | ||
except pkg_resources.VersionConflict as e: | ||
print("Incompatible plugins found!") | ||
print("Plugin {} requires you to have {}, but you installed {}.".format( | ||
self.name, e.req, e.dist | ||
)) | ||
sys.exit(1) | ||
self.check_compatibility() | ||
|
||
def check_compatibility(self): | ||
""" | ||
Checks for compatibility of the plugin based on specified version requirements. | ||
|
||
This method verifies if the currently installed versions of required packages match | ||
the versions specified in the plugin's compatibility requirements. If a version | ||
mismatch is found or a required package is not installed, it prints an error message | ||
and exits the program. | ||
|
||
Steps: | ||
1. Iterates over the compatibility requirements specified in `self.PretixPluginMeta.compatibility`. | ||
2. For each requirement, it splits the package name and the required version. | ||
3. Fetches the installed version of the package using `importlib.metadata.version`. | ||
4. Compares the installed version with the required version. | ||
5. If a mismatch is found, prints an error message and exits the program. | ||
6. If a required package is not found, catches the `PackageNotFoundError`, prints an error message, | ||
and exits the program. | ||
|
||
Raises: | ||
SystemExit: If a version conflict or missing package is detected, the program exits. | ||
""" | ||
try: | ||
for requirement in self.PretixPluginMeta.compatibility: | ||
package_name, _, required_version = requirement.partition("==") | ||
installed_version = importlib.metadata.version(package_name) | ||
if installed_version != required_version: | ||
print("Incompatible plugins found!") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use |
||
print(f"Plugin {self.name} requires you to have {package_name}=={required_version}, " | ||
f"but you installed {package_name}=={installed_version}.") | ||
sys.exit(1) | ||
except importlib.metadata.PackageNotFoundError as e: | ||
print(f"Package not found: {e}") | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please move this import line to the top. Separate import lines to 3 groups as
PEP8
recommendation.