File tree Expand file tree Collapse file tree 1 file changed +25
-6
lines changed
Expand file tree Collapse file tree 1 file changed +25
-6
lines changed Original file line number Diff line number Diff line change 11import os
22import json
33import requests
4- import pkg_resources
5-
6- from pkg_resources import DistributionNotFound
4+ import warnings
75
86from types import ModuleType
97
@@ -84,9 +82,30 @@ def _update_user_agent_header(self, options):
8482 def _get_version (self ):
8583 version = ""
8684 try : # nosemgrep : gitlab.bandit.B110
87- version = pkg_resources .require ("razorpay" )[0 ].version
88- except DistributionNotFound : # pragma: no cover
89- pass
85+ # Try importlib.metadata first (modern approach)
86+ try :
87+ import importlib .metadata
88+ from importlib .metadata import PackageNotFoundError
89+ version = importlib .metadata .version ("razorpay" )
90+ except ImportError :
91+ # Fall back to pkg_resources
92+ import pkg_resources
93+ from pkg_resources import DistributionNotFound
94+ version = pkg_resources .require ("razorpay" )[0 ].version
95+ except (PackageNotFoundError , DistributionNotFound , NameError ): # pragma: no cover
96+ # PackageNotFoundError: importlib.metadata couldn't find the package
97+ # DistributionNotFound: pkg_resources couldn't find the package
98+ # NameError: in case the exception classes aren't defined due to import issues
99+
100+ # If all else fails, use the hardcoded version from the package
101+ version = "1.4.3"
102+
103+ warnings .warn (
104+ "Could not detect razorpay package version. Using fallback version."
105+ "This may indicate an installation issue." ,
106+ UserWarning ,
107+ stacklevel = 4
108+ )
90109 return version
91110
92111 def _get_app_details_ua (self ):
You can’t perform that action at this time.
0 commit comments