@@ -50,20 +50,38 @@ def pillow_installed():
5050extras_requires_dict = {'drawing_barcodes' : extras_requires }
5151
5252pygenbuildinfo = True
53- verinfofilename = os .path .realpath (
54- "." + os .path .sep + "upcean" + os .path .sep + "versioninfo.py" )
55- verinfofile = open (verinfofilename , "r" )
56- verinfodata = verinfofile .read ()
57- verinfofile .close ()
58- setuppy_verinfo_esc = re .escape ("__version_info__ = (" )+ "(.*)" + re .escape (");" )
59- setuppy_verinfo = re .findall (setuppy_verinfo_esc , verinfodata )[0 ]
60- setuppy_verinfo_exp = [vergetspt .strip ().replace ("\" " , "" )
61- for vergetspt in setuppy_verinfo .split (',' )]
62- setuppy_dateinfo_esc = re .escape (
63- "__version_date_info__ = (" )+ "(.*)" + re .escape (");" )
64- setuppy_dateinfo = re .findall (setuppy_dateinfo_esc , verinfodata )[0 ]
65- setuppy_dateinfo_exp = [vergetspt .strip ().replace ("\" " , "" )
66- for vergetspt in setuppy_dateinfo .split (',' )]
53+ # Open and read the version info file in a Python 2/3 compatible way
54+ verinfofilename = os .path .realpath ("." + os .path .sep + "upcean" + os .path .sep + "versioninfo.py" )
55+
56+ # Use `with` to ensure the file is properly closed after reading
57+ # In Python 2, open defaults to text mode; in Python 3, it’s better to specify encoding
58+ open_kwargs = {'encoding' : 'utf-8' } if sys .version_info [0 ] >= 3 else {}
59+ with open (verinfofilename , "r" , ** open_kwargs ) as verinfofile :
60+ verinfodata = verinfofile .read ()
61+
62+ # Define the regex pattern for extracting version info
63+ # We ensure the pattern works correctly in both Python 2 and 3 by escaping the strings properly
64+ version_pattern = "__version_info__ = \(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*['\" ]([\w\s]+)['\" ]\s*,\s*(\d+)\s*\)"
65+ setuppy_verinfo = re .findall (version_pattern , verinfodata )[0 ]
66+
67+ # If version info is found, process it; handle the case where no match is found
68+ if setuppy_verinfo :
69+ setuppy_verinfo_exp = setuppy_verinfo
70+ else :
71+ print ("Version info not found." )
72+ setuppy_verinfo_exp = None # Handle missing version info gracefully
73+
74+ # Define the regex pattern for extracting version date info
75+ date_pattern = "__version_date_info__ = \(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*['\" ]([\w\s]+)['\" ]\s*,\s*(\d+)\s*\)"
76+ setuppy_dateinfo = re .findall (date_pattern , verinfodata )[0 ]
77+
78+ # If date info is found, process it; handle the case where no match is found
79+ if setuppy_dateinfo :
80+ setuppy_dateinfo_exp = setuppy_dateinfo
81+ else :
82+ print ("Date info not found." )
83+ setuppy_dateinfo_exp = None # Handle missing date info gracefully
84+
6785pymodule = {}
6886pymodule ['version' ] = str (setuppy_verinfo_exp [0 ])+ "." + \
6987 str (setuppy_verinfo_exp [1 ])+ "." + str (setuppy_verinfo_exp [2 ])
0 commit comments