|
| 1 | +import setuptools, os, sys, platform, shutil |
| 2 | + |
| 3 | +#Force platform wheel |
| 4 | +try: |
| 5 | + from wheel.bdist_wheel import bdist_wheel as _bdist_wheel |
| 6 | + class bdist_wheel(_bdist_wheel): |
| 7 | + def finalize_options(self): |
| 8 | + _bdist_wheel.finalize_options(self) |
| 9 | + self.root_is_pure = False |
| 10 | +except ImportError: |
| 11 | + bdist_wheel = None |
| 12 | + |
| 13 | +#Find sys/machine file |
| 14 | +def buildfilepath(): |
| 15 | + ossys = platform.system() |
| 16 | + platmac = platform.machine() |
| 17 | + platmacshort = "" |
| 18 | + sfilename = "" |
| 19 | + if ossys == "Windows": |
| 20 | + sfilename = "DelphiVCL.pyd" |
| 21 | + if platmac.endswith('64'): |
| 22 | + #Win x64 |
| 23 | + platmacshort = "Win64" |
| 24 | + else: |
| 25 | + #Win x86 |
| 26 | + platmacshort = "Win32" |
| 27 | + |
| 28 | + pyversionstrshort = f"{sys.version_info.major}{sys.version_info.minor}" |
| 29 | + |
| 30 | + return f"DelphiVCL_{platmacshort}_{pyversionstrshort}{os.sep}{sfilename}" |
| 31 | + |
| 32 | +#Copy target file from lib to pkg folder |
| 33 | +def copylibfiletopkg(slibfile, spkgfile): |
| 34 | + spkgdirname = os.path.dirname(spkgfile) |
| 35 | + if not os.path.exists(spkgdirname): |
| 36 | + os.makedirs(spkgdirname) |
| 37 | + shutil.copy(slibfile, spkgfile) |
| 38 | + |
| 39 | + #libdirname = os.path.dirname(slibfile) |
| 40 | + #shutil.rmtree(libdirname) |
| 41 | + |
| 42 | +#Validate lib paths |
| 43 | +def validatelibpaths(slibdir, slibfile): |
| 44 | + print(f"Check for lib dir: {slibdir}") |
| 45 | + if not os.path.exists(f"{slibdir}"): |
| 46 | + raise ValueError(f"Invalid lib path: {slibdir}") |
| 47 | + |
| 48 | + print(f"Check for lib path: {slibfile}") |
| 49 | + if not os.path.exists(slibfile): |
| 50 | + raise ValueError(f"Invalid lib path: {slibfile}") |
| 51 | + |
| 52 | +#Validate pkg paths |
| 53 | +def validatepkgpaths(spkgfile): |
| 54 | + print(f"Check for pkg path: {spkgfile}") |
| 55 | + if not os.path.exists(spkgfile): |
| 56 | + raise ValueError(f"Invalid pkg path: {spkgfile}") |
| 57 | + |
| 58 | +def isdistprocess(): |
| 59 | + sdir = os.path.join(os.curdir, "delphivcl") |
| 60 | + for fname in os.listdir(sdir): |
| 61 | + if 'DelphiVCL' in fname: |
| 62 | + return True |
| 63 | + return False |
| 64 | + |
| 65 | +def distprocess(): |
| 66 | + sdir = os.path.join(os.curdir, "delphivcl") |
| 67 | + for fname in os.listdir(sdir): |
| 68 | + if 'DelphiVCL' in fname: |
| 69 | + return os.path.basename(fname) |
| 70 | + return None |
| 71 | + |
| 72 | +def buildprocess(): |
| 73 | + spath = buildfilepath() |
| 74 | + sfilename = os.path.basename(spath) |
| 75 | + |
| 76 | + slibdir = os.path.join(os.curdir, "lib") |
| 77 | + slibfile = os.path.join(slibdir, spath) |
| 78 | + |
| 79 | + spkgdir = os.path.join(os.curdir, "delphivcl") |
| 80 | + spkgfile = os.path.join(spkgdir, sfilename) |
| 81 | + |
| 82 | + validatelibpaths(slibdir, slibfile) |
| 83 | + copylibfiletopkg(slibfile, spkgfile) |
| 84 | + validatepkgpaths(spkgfile) |
| 85 | + |
| 86 | + return sfilename |
| 87 | + |
| 88 | +sfilename = None |
| 89 | +print("Check for process type") |
| 90 | +if isdistprocess(): |
| 91 | + print("Found a distribution process") |
| 92 | + sfilename = distprocess() |
| 93 | +else: |
| 94 | + print("Found a build process") |
| 95 | + sfilename = buildprocess() |
| 96 | + |
| 97 | +print("Working with file: ", sfilename) |
| 98 | + |
| 99 | +"""def list_files(startpath): |
| 100 | + for root, dirs, files in os.walk(startpath): |
| 101 | + level = root.replace(startpath, '').count(os.sep) |
| 102 | + indent = ' ' * 4 * (level) |
| 103 | + print('{}{}/'.format(indent, os.path.basename(root))) |
| 104 | + subindent = ' ' * 4 * (level + 1) |
| 105 | + for f in files: |
| 106 | + print('{}{}'.format(subindent, f)) |
| 107 | + |
| 108 | +list_files(f"{os.curdir}")""" |
| 109 | + |
| 110 | +def get_release_version(): |
| 111 | + """Creates a new version incrementing by 1 the number of build specified in the |
| 112 | + DelphiVCL-0-01/__version__.py file.""" |
| 113 | + lcals = locals() |
| 114 | + gbals = globals() |
| 115 | + with open(os.path.join(os.getcwd(), "delphivcl", "__version__.py"), "rt") as opf: |
| 116 | + opffilecontents = opf.read() |
| 117 | + retvalue = exec(opffilecontents, gbals, lcals) |
| 118 | + versorigstr = lcals["__version__"] |
| 119 | + return versorigstr |
| 120 | + |
| 121 | +versnewstr = get_release_version() |
| 122 | + |
| 123 | +with open("README.md", "r") as fh: |
| 124 | + long_description = fh.read() |
| 125 | + |
| 126 | +setuptools.setup( |
| 127 | + name="delphivcl", |
| 128 | + version=versnewstr, |
| 129 | + description="Delphi VCL for Python", |
| 130 | + author="Lucas Belo, Jim McKeeth", |
| 131 | + author_email="lucas.belo@live.com", |
| 132 | + long_description=long_description, |
| 133 | + long_description_content_type="text/markdown", |
| 134 | + packages=["delphivcl"], |
| 135 | + package_data={"delphivcl": [sfilename]}, |
| 136 | + classifiers=[ |
| 137 | + 'Development Status :: 1 - Planning', |
| 138 | + 'Intended Audience :: Developers', |
| 139 | + 'Topic :: Software Development', |
| 140 | + 'License :: OSI Approved :: BSD License', |
| 141 | + 'Programming Language :: Python', |
| 142 | + 'Programming Language :: Python :: 3', |
| 143 | + 'Programming Language :: Python :: 3.7', |
| 144 | + 'Programming Language :: Python :: 3.6', |
| 145 | + 'Programming Language :: Python :: 3.8', |
| 146 | + 'Programming Language :: Python :: 3.9', |
| 147 | + 'Programming Language :: Python :: 3 :: Only', |
| 148 | + 'Operating System :: Microsoft :: Windows', |
| 149 | + ], |
| 150 | + cmdclass={'bdist_wheel': bdist_wheel}, |
| 151 | +) |
0 commit comments