Update versioninfo.py
[PyUPC-EAN.git] / setup.py
blob2f9ef82da6d8f2dfc14f2adacd0cfcecf2da0abb
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 '''
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the Revised BSD License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 Revised BSD License for more details.
13 Copyright 2011-2023 Game Maker 2k - https://github.com/GameMaker2k
14 Copyright 2011-2023 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16 $FileInfo: setup.py - Last Update: 11/15/2024 Ver. 2.12.0 RC 1 - Author: cooldude2k $
17 '''
19 import re
20 import os
21 import sys
22 import time
23 import datetime
24 import platform
25 import pkg_resources
26 from setuptools import setup, find_packages
28 install_requires = []
29 extras_requires = []
30 # https://github.com/mapproxy/mapproxy/blob/master/setup.py
33 def pillow_installed():
34 """Check if Pillow is installed"""
35 pillow_req = pkg_resources.Requirement.parse('Pillow')
36 try:
37 pkg_resources.get_provider(pillow_req)
38 except pkg_resources.DistributionNotFound:
39 return False
40 else:
41 return True
44 # depend in Pillow if it is installed, otherwise depend on PIL
45 if pillow_installed():
46 extras_requires.append('Pillow')
47 else:
48 extras_requires.append('PIL')
49 extras_requires.append('pycairo')
50 extras_requires_dict = {'drawing_barcodes': extras_requires}
52 pygenbuildinfo = True
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")
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()
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]
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
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]
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
85 pymodule = {}
86 pymodule['version'] = str(setuppy_verinfo_exp[0])+"." + \
87 str(setuppy_verinfo_exp[1])+"."+str(setuppy_verinfo_exp[2])
88 pymodule['versionrc'] = int(setuppy_verinfo_exp[4])
89 pymodule['versionlist'] = (int(setuppy_verinfo_exp[0]), int(setuppy_verinfo_exp[1]), int(
90 setuppy_verinfo_exp[2]), str(setuppy_verinfo_exp[3]), int(setuppy_verinfo_exp[4]))
91 pymodule['verdate'] = str(setuppy_dateinfo_exp[0])+"." + \
92 str(setuppy_dateinfo_exp[1])+"."+str(setuppy_dateinfo_exp[2])
93 pymodule['verdaterc'] = int(setuppy_dateinfo_exp[4])
94 pymodule['verdatelist'] = (int(setuppy_dateinfo_exp[0]), int(setuppy_dateinfo_exp[1]), int(
95 setuppy_dateinfo_exp[2]), str(setuppy_dateinfo_exp[3]), int(setuppy_dateinfo_exp[4]))
96 pymodule['name'] = 'PyUPC-EAN'
97 pymodule['author'] = 'Kazuki Przyborowski'
98 pymodule['authoremail'] = 'kazuki.przyborowski@gmail.com'
99 pymodule['maintainer'] = 'Kazuki Przyborowski'
100 pymodule['maintaineremail'] = 'kazuki.przyborowski@gmail.com'
101 pymodule['description'] = 'A barcode library/module for python.'
102 pymodule['license'] = 'Revised BSD License'
103 pymodule['keywords'] = 'python barcode pyupc-ean pyupcean barcodegenerator barcode-generator barcodelibrary barcode-library barcodes codabar msi code11 code-11 code39 code-39 code93 code-93 code128 code-128 ean ean13 ean-13 ean2 ean-2 ean5 ean-5 ean8 ean-8 itf itf14 itf-14 stf upc upca upc-a upce upc-e gtin2 gtin-2 gtin5 gtin-5 gtin8 gtin-8 gtin12 gtin-12 gtin13 gtin-13 gtin14 gtin-14 ocr-a ocra ocr-b ocrb'
104 pymodule['url'] = 'https://github.com/GameMaker2k/PyUPC-EAN'
105 pymodule['downloadurl'] = 'https://github.com/GameMaker2k/PyUPC-EAN/archive/master.tar.gz'
106 pymodule['packages'] = find_packages()
107 pymodule['packagedata'] = {'upcean/fonts': ['*.otf', '*.ttf'],
108 'upcean/xml': ['*.dtd', '*.xsl', '*.xsd', '*.rng', '*.rnc']}
109 pymodule['includepackagedata'] = True
110 pymodule['installrequires'] = install_requires
111 pymodule['extrasrequires'] = extras_requires_dict
112 pymodule['longdescription'] = 'PyUPC-EAN is a barcode library/module for Python. It supports the barcode formats upc-e, upc-a, ean-13, ean-8, ean-2, ean-5, itf14, codabar, code11, code39, code93, code128, code-128, and msi.'
113 pymodule['platforms'] = 'OS Independent'
114 pymodule['zipsafe'] = False
115 # pymodule['pymodules'] = [y for x in os.walk("upcean") for y in glob.glob(os.path.join(x[0], '*.py'))];
116 pymodule['pymodules'] = []
117 pymodule['classifiers'] = [
118 'Development Status :: 5 - Production/Stable',
119 'Intended Audience :: Customer Service',
120 'Intended Audience :: Developers',
121 'Intended Audience :: Other Audience',
122 'License :: OSI Approved',
123 'License :: OSI Approved :: BSD License',
124 'Natural Language :: English',
125 'Operating System :: MacOS',
126 'Operating System :: MacOS :: MacOS X',
127 'Operating System :: Microsoft',
128 'Operating System :: Microsoft :: Windows',
129 'Operating System :: OS/2',
130 'Operating System :: OS Independent',
131 'Operating System :: POSIX',
132 'Operating System :: Unix',
133 'Programming Language :: Python',
134 'Topic :: Multimedia :: Graphics',
135 'Topic :: Office/Business',
136 'Topic :: Office/Business :: Financial',
137 'Topic :: Office/Business :: Financial :: Point-Of-Sale',
138 'Topic :: Utilities',
139 'Topic :: Software Development',
140 'Topic :: Software Development :: Libraries',
141 'Topic :: Software Development :: Libraries :: Python Modules'
143 if(len(sys.argv) > 1 and (sys.argv[1] == "versioninfo" or sys.argv[1] == "getversioninfo")):
144 import json
145 pymodule_data = json.dumps(pymodule)
146 print(pymodule_data)
147 sys.exit()
148 if(len(sys.argv) > 1 and (sys.argv[1] == "sourceinfo" or sys.argv[1] == "getsourceinfo")):
149 srcinfofilename = os.path.realpath("."+os.path.sep+pkg_resources.to_filename(
150 pymodule['name'])+".egg-info"+os.path.sep+"SOURCES.txt")
151 srcinfofile = open(srcinfofilename, "r")
152 srcinfodata = srcinfofile.read()
153 srcinfofile.close()
154 srcinfolist = srcinfodata.split('\n')
155 srcfilelist = ""
156 srcpdir = os.path.basename(os.path.dirname(os.path.realpath(__file__)))
157 for ifile in srcinfolist:
158 srcfilelist = "."+os.path.sep+srcpdir+os.path.sep+ifile+" "+srcfilelist
159 print(srcfilelist)
160 sys.exit()
161 if(len(sys.argv) > 1 and sys.argv[1] == "cleansourceinfo"):
162 os.system("rm -rfv \""+os.path.realpath("."+os.path.sep+"dist\""))
163 os.system("rm -rfv \""+os.path.realpath("."+os.path.sep +
164 pkg_resources.to_filename(pymodule['name'])+".egg-info\""))
165 sys.exit()
167 if(pygenbuildinfo):
168 mycurtime = datetime.datetime.now()
169 mycurtimetuple = mycurtime.timetuple()
170 mycurtimestamp = int(time.mktime(mycurtimetuple))
171 '''verinfodata = verinfodata.replace('__build_time__ = {"timestamp": None, "year": None, "month": None, "day": None, "hour": None, "minute": None, "second": None};', '__build_time__ = {"timestamp": '+str(mycurtimestamp)+', "year": '+str(mycurtimetuple[0])+', "month": '+str(mycurtimetuple[1])+', "day": '+str(mycurtimetuple[2])+', "hour": '+str(mycurtimetuple[3])+', "minute": '+str(mycurtimetuple[4])+', "second": '+str(mycurtimetuple[5])+'};');'''
172 verinfodata = re.sub("__build_time__ \= \{.*\}\;", '__build_time__ = {"timestamp": '+str(mycurtimestamp)+', "year": '+str(mycurtimetuple[0])+', "month": '+str(
173 mycurtimetuple[1])+', "day": '+str(mycurtimetuple[2])+', "hour": '+str(mycurtimetuple[3])+', "minute": '+str(mycurtimetuple[4])+', "second": '+str(mycurtimetuple[5])+'};', verinfodata)
174 utccurtime = datetime.datetime.utcnow()
175 utccurtimetuple = utccurtime.timetuple()
176 utccurtimestamp = int(time.mktime(utccurtimetuple))
177 '''verinfodata = verinfodata.replace('__build_time_utc__ = {"timestamp": None, "year": None, "month": None, "day": None, "hour": None, "minute": None, "second": None};', '__build_time_utc__ = {"timestamp": '+str(utccurtimestamp)+', "year": '+str(utccurtimetuple[0])+', "month": '+str(utccurtimetuple[1])+', "day": '+str(utccurtimetuple[2])+', "hour": '+str(utccurtimetuple[3])+', "minute": '+str(utccurtimetuple[4])+', "second": '+str(utccurtimetuple[5])+'};');'''
178 verinfodata = re.sub("__build_time_utc__ \= \{.*\}\;", '__build_time_utc__ = {"timestamp": '+str(utccurtimestamp)+', "year": '+str(utccurtimetuple[0])+', "month": '+str(
179 utccurtimetuple[1])+', "day": '+str(utccurtimetuple[2])+', "hour": '+str(utccurtimetuple[3])+', "minute": '+str(utccurtimetuple[4])+', "second": '+str(utccurtimetuple[5])+'};', verinfodata)
180 linuxdist = None
181 try:
182 linuxdist = platform.linux_distribution()
183 except AttributeError:
184 linuxdist = None
185 if(sys.version[0] == "2"):
186 '''verinfodata = verinfodata.replace('__build_python_info__ = {"python_branch": None, "python_build": None, "python_compiler": None, "python_implementation": None, "python_revision": None, "python_version": None, "python_version_tuple": None, "release": None, "system": None, "uname": None, "machine": None, "node": None, "platform": None, "processor": None, "version": None, "java_ver": None, "win32_ver": None, "mac_ver": None, "linux_distribution": None, "libc_ver": None};', '__build_python_info__ = '+str({'python_branch': platform.python_branch(), 'python_build': platform.python_build(), 'python_compiler': platform.python_compiler(), 'python_implementation': platform.python_implementation(), 'python_revision': platform.python_revision(), 'python_version': platform.python_version(), 'python_version_tuple': platform.python_version_tuple(), 'release': platform.release(), 'system': platform.system(), 'uname': platform.uname(), 'machine': platform.machine(), 'node': platform.node(), 'platform': platform.platform(), 'processor': platform.processor(), 'architecture': platform.architecture(), 'version': platform.version(), 'java_ver': platform.java_ver(), 'win32_ver': platform.win32_ver(), 'mac_ver': platform.mac_ver(), 'linux_distribution': linuxdist, 'libc_ver': platform.libc_ver()})+';');'''
187 verinfodata = re.sub("__build_python_info__ \= \{.*\}\;", '__build_python_info__ = '+str({'python_branch': platform.python_branch(), 'python_build': platform.python_build(), 'python_compiler': platform.python_compiler(), 'python_implementation': platform.python_implementation(), 'python_revision': platform.python_revision(), 'python_version': platform.python_version(), 'python_version_tuple': platform.python_version_tuple(), 'release': platform.release(
188 ), 'system': platform.system(), 'uname': platform.uname(), 'machine': platform.machine(), 'node': platform.node(), 'platform': platform.platform(), 'processor': platform.processor(), 'architecture': platform.architecture(), 'version': platform.version(), 'java_ver': platform.java_ver(), 'win32_ver': platform.win32_ver(), 'mac_ver': platform.mac_ver(), 'linux_distribution': linuxdist, 'libc_ver': platform.libc_ver()})+';', verinfodata)
189 if(sys.version[0] == "3"):
190 '''verinfodata = verinfodata.replace('__build_python_info__ = {"python_branch": None, "python_build": None, "python_compiler": None, "python_implementation": None, "python_revision": None, "python_version": None, "python_version_tuple": None, "release": None, "system": None, "uname": None, "machine": None, "node": None, "platform": None, "processor": None, "version": None, "java_ver": None, "win32_ver": None, "mac_ver": None, "linux_distribution": None, "libc_ver": None};', '__build_python_info__ = '+str({'python_branch': platform.python_branch(), 'python_build': platform.python_build(), 'python_compiler': platform.python_compiler(), 'python_implementation': platform.python_implementation(), 'python_revision': platform.python_revision(), 'python_version': platform.python_version(), 'python_version_tuple': platform.python_version_tuple(), 'release': platform.release(), 'system': platform.system(), 'uname': (platform.uname()[0], platform.uname()[1], platform.uname()[2], platform.uname()[3], platform.uname()[4], platform.uname()[5]), 'machine': platform.machine(), 'node': platform.node(), 'platform': platform.platform(), 'processor': platform.processor(), 'architecture': platform.architecture(), 'version': platform.version(), 'java_ver': platform.java_ver(), 'win32_ver': platform.win32_ver(), 'mac_ver': platform.mac_ver(), 'linux_distribution': linuxdist, 'libc_ver': platform.libc_ver()})+';');'''
191 verinfodata = re.sub("__build_python_info__ \= \{.*\}\;", '__build_python_info__ = '+str({'python_branch': platform.python_branch(), 'python_build': platform.python_build(), 'python_compiler': platform.python_compiler(), 'python_implementation': platform.python_implementation(), 'python_revision': platform.python_revision(), 'python_version': platform.python_version(), 'python_version_tuple': platform.python_version_tuple(), 'release': platform.release(), 'system': platform.system(), 'uname': (
192 platform.uname()[0], platform.uname()[1], platform.uname()[2], platform.uname()[3], platform.uname()[4], platform.uname()[5]), 'machine': platform.machine(), 'node': platform.node(), 'platform': platform.platform(), 'processor': platform.processor(), 'architecture': platform.architecture(), 'version': platform.version(), 'java_ver': platform.java_ver(), 'win32_ver': platform.win32_ver(), 'mac_ver': platform.mac_ver(), 'linux_distribution': linuxdist, 'libc_ver': platform.libc_ver()})+';', verinfodata)
193 '''verinfodata = verinfodata.replace('__build_python_is_set__ = False;', '__build_python_is_set__ = True;');'''
194 verinfodata = re.sub("__build_python_is_set__ \= .*\;",
195 '__build_python_is_set__ = True;', verinfodata)
196 verinfofile = open(verinfofilename, "w")
197 verinfofile.write(verinfodata)
198 verinfofile.close()
200 setup(
201 name=pymodule['name'],
202 version=pymodule['version'],
203 author=pymodule['author'],
204 author_email=pymodule['authoremail'],
205 maintainer=pymodule['maintainer'],
206 maintainer_email=pymodule['maintaineremail'],
207 description=pymodule['description'],
208 license=pymodule['license'],
209 keywords=pymodule['keywords'],
210 url=pymodule['url'],
211 download_url=pymodule['downloadurl'],
212 packages=pymodule['packages'],
213 package_data=pymodule['packagedata'],
214 include_package_data=pymodule['includepackagedata'],
215 install_requires=pymodule['installrequires'],
216 extras_require=pymodule['extrasrequires'],
217 long_description=pymodule['longdescription'],
218 platforms=pymodule['platforms'],
219 zip_safe=pymodule['zipsafe'],
220 py_modules=pymodule['pymodules'],
221 classifiers=pymodule['classifiers']