Skip to content

Commit 60c21be

Browse files
committed
Project sanitization
1 parent 1ece2cb commit 60c21be

14 files changed

+258
-211
lines changed

.github/workflows/deploy-wheels.yaml renamed to .github/workflows/pypi.yml

+2-9
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ name: Build
22

33
on:
44
push:
5-
branches:
6-
- deploy-pypi-test
7-
- deploy-pypi
8-
# Release branches
9-
#- "[0-9]+.[0-9]+.X"
105

116
# Manual run
127
workflow_dispatch:
@@ -83,8 +78,7 @@ jobs:
8378
url: https://test.pypi.org/project/delphivcl
8479
permissions:
8580
id-token: write
86-
# upload to PyPI test only for pushes to 'deploy-pypi-test'
87-
if: github.event_name == 'push' && github.ref == 'refs/heads/deploy-pypi-test'
81+
if: github.ref == 'refs/heads/main'
8882
steps:
8983
- uses: actions/download-artifact@v2
9084
with:
@@ -105,8 +99,7 @@ jobs:
10599
url: https://pypi.org/project/delphivcl/
106100
permissions:
107101
id-token: write
108-
# upload to PyPI only for pushes to 'deploy-pypi'
109-
if: github.event_name == 'push' && github.ref == 'refs/heads/deploy-pypi'
102+
if: startsWith(github.ref, 'refs/tags/v')
110103
steps:
111104
- uses: actions/download-artifact@v2
112105
with:

.github/workflows/tests.yaml renamed to .github/workflows/tests.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ name: Tests
33
on:
44
push:
55
branches:
6-
- main
7-
- test
8-
# Release branches
9-
#- "[0-9]+.[0-9]+.X"
6+
- main
107

118
# Manual run
129
workflow_dispatch:

MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
recursive-include delphivcl *.pyd
2+
recursive-include delphivcl docs.xml

build.py

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import sys
2+
import os
3+
import sys
4+
import shutil
5+
import time
6+
import platform
7+
import distutils.dir_util
8+
from wheel.bdist_wheel import bdist_wheel
9+
10+
11+
'''
12+
BDistWheel forces python and abi wheel tags for binary distributions
13+
'''
14+
15+
16+
class BDistWheel(bdist_wheel):
17+
18+
def finalize_options(self):
19+
bdist_wheel.finalize_options(self)
20+
self.root_is_pure = ("--universal" in sys.argv)
21+
22+
23+
'''
24+
Sort out the platform library for binary distribution and add to the package directory.
25+
Place all libraries onto the package directory for source distribution.
26+
Place the XML doc file onto the package directory.
27+
'''
28+
29+
30+
class PackageDataBuilder():
31+
32+
def __init__(self):
33+
self.pkg_dir = os.path.join(os.curdir, "delphivcl")
34+
self.plat_name = None
35+
for arg in sys.argv:
36+
if arg.startswith("--plat-name=") and (len(arg.split("=")) == 2):
37+
self.plat_name = arg.split("=")[1]
38+
39+
'''
40+
Must run "python setup.py clean --all" between builds.
41+
'''
42+
43+
def clean_up(self):
44+
lib_dirs = [os.path.join(self.pkg_dir, "Win32"),
45+
os.path.join(self.pkg_dir, "Win64")]
46+
47+
for lib_dir in lib_dirs:
48+
if os.path.isdir(lib_dir):
49+
shutil.rmtree(lib_dir)
50+
51+
# Wait until the OS remove all dirs
52+
for lib_dir in lib_dirs:
53+
for attempts in range(3):
54+
if not os.path.isdir(lib_dir):
55+
break
56+
else:
57+
time.sleep(1)
58+
59+
'''
60+
Cross-compiling wheel.
61+
This generates a wheel following the cross platform set on --plat-name.
62+
See: https://docs.python.org/3/distutils/builtdist.html#cross-compiling-on-windows
63+
'''
64+
65+
def __check_cross_compiling(self):
66+
is_cross_compiling = False
67+
lib_dir = None
68+
69+
if self.plat_name:
70+
is_cross_compiling = True
71+
if self.plat_name == "win32":
72+
lib_dir = "Win32"
73+
elif self.plat_name == "win_amd64":
74+
lib_dir = "Win64"
75+
else:
76+
is_cross_compiling = False
77+
78+
return (is_cross_compiling, lib_dir)
79+
80+
'''
81+
Copy the VCL extension module(s) to the package data folder.
82+
Source distributions and Universal binary distributions will deliver
83+
all library versions. The right one will be loaded by __init__.py.
84+
Platform distributions will deliver only the library that matches the runner.
85+
'''
86+
87+
def __pick_and_copy_libraries(self):
88+
if ("sdist" in sys.argv) or (("bdist_wheel" in sys.argv) and ("--universal" in sys.argv)):
89+
# sdist/bdist[--universal] deploy all extension modules
90+
distutils.dir_util.copy_tree("lib", self.pkg_dir)
91+
else:
92+
# Deploys the current platform extension module only
93+
is_cross_compiling, lib_dir = self.__check_cross_compiling()
94+
if not is_cross_compiling:
95+
plat_sys = platform.system()
96+
if plat_sys == "Windows":
97+
if (sys.maxsize > 2**32):
98+
# Win x64
99+
lib_dir = "Win64"
100+
else:
101+
# Win x86
102+
lib_dir = "Win32"
103+
104+
if lib_dir:
105+
distutils.dir_util.copy_tree(os.path.join(
106+
"lib", lib_dir), os.path.join(self.pkg_dir, lib_dir))
107+
else:
108+
raise ValueError("Unsupported platform.")
109+
110+
'''
111+
Copy the XML doc file to the package data folder.
112+
The docs.xml file is the result of the compilation of all xml doc files.
113+
'''
114+
115+
def __pick_and_copy_docs(self):
116+
# Copy the doc files to the package folder into the doc subfolder
117+
docs_file = os.path.join("docs", "xml", "docs.xml")
118+
if os.path.exists(docs_file):
119+
pkg_doc_dir = os.path.join(self.pkg_dir, "doc")
120+
if not os.path.exists(pkg_doc_dir):
121+
os.mkdir(pkg_doc_dir)
122+
distutils.file_util.copy_file(
123+
docs_file, os.path.join(pkg_doc_dir, "docs.xml"))
124+
125+
def build_package_data(self):
126+
self.__pick_and_copy_libraries()
127+
self.__pick_and_copy_docs()
128+
129+
130+
def setup():
131+
builder = PackageDataBuilder()
132+
builder.clean_up()
133+
builder.build_package_data()

delphivcl/__init__.py

+46-35
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,58 @@
1-
import sys, os, sys, platform
2-
from os import environ
3-
import importlib, importlib.machinery, importlib.util
1+
import sys
2+
import os
3+
import sys
4+
import platform
5+
import importlib
6+
import importlib.machinery
7+
import importlib.util
48

5-
class PyVerNotSupported(Exception):
6-
pass
79

8-
def findmodule():
9-
pyver = f"{sys.version_info.major}.{sys.version_info.minor}"
10-
ossys = platform.system()
11-
libdir = None
10+
def find_extension_module():
11+
py_ver = f"{sys.version_info.major}.{sys.version_info.minor}"
12+
plat_sys = platform.system()
13+
lib_dir = None
1214

13-
if not (pyver in ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]):
14-
raise PyVerNotSupported(f"DelphiVCL doesn't support Python{pyver}.")
15+
if not (py_ver in ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]):
16+
raise ValueError(f"DelphiVCL doesn't support Python{py_ver}.")
1517

16-
if ossys == "Windows":
17-
if (sys.maxsize > 2**32):
18-
#Win x64
19-
libdir = "Win64"
18+
if plat_sys == "Windows":
19+
if (sys.maxsize > 2**32):
20+
# Win x64
21+
lib_dir = "Win64"
22+
else:
23+
# Win x86
24+
lib_dir = "Win32"
25+
26+
if lib_dir:
27+
lib_dir = os.path.join(os.path.dirname(
28+
os.path.abspath(__file__)), lib_dir)
29+
if not os.path.exists(lib_dir):
30+
raise ValueError(
31+
"DelphiVCL module not found. \
32+
Try to reinstall the delphivcl package or check for support compatibility.")
33+
34+
for file_name in os.listdir(lib_dir):
35+
if 'DelphiVCL' in file_name:
36+
return os.path.join(lib_dir, os.path.basename(file_name))
37+
raise ValueError(
38+
"DelphiVCL module not found. Try to reinstall the delphivcl package.")
2039
else:
21-
#Win x86
22-
libdir = "Win32"
23-
24-
if libdir:
25-
sdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), libdir)
26-
if not os.path.exists(sdir):
27-
raise ValueError("DelphiVCL module not found. Try to reinstall the delphivcl package or check for support compatibility.")
28-
for fname in os.listdir(sdir):
29-
if 'DelphiVCL' in fname:
30-
return os.path.join(sdir, os.path.basename(fname))
31-
raise ValueError("DelphiVCL module not found. Try to reinstall the delphivcl package.")
32-
else:
33-
raise ValueError("Unsupported platform.")
40+
raise ValueError("Unsupported platform.")
41+
3442

3543
def new_import():
36-
modulefullpath = findmodule()
37-
loader = importlib.machinery.ExtensionFileLoader("DelphiVCL", modulefullpath)
38-
spec = importlib.util.spec_from_file_location("DelphiVCL", modulefullpath,
39-
loader=loader, submodule_search_locations=None)
40-
ld = loader.create_module(spec)
44+
lib_path = find_extension_module()
45+
loader = importlib.machinery.ExtensionFileLoader("DelphiVCL", lib_path)
46+
spec = importlib.util.spec_from_file_location("DelphiVCL",
47+
lib_path,
48+
loader=loader,
49+
submodule_search_locations=None)
50+
loader.create_module(spec)
4151
package = importlib.util.module_from_spec(spec)
4252
sys.modules["delphivcl"] = package
4353
spec.loader.exec_module(package)
4454
return package
4555

46-
#Import the shared lib
47-
package = new_import()
56+
57+
# Import the extension module
58+
package = new_import()

delphivcl/__version__.py

-1
This file was deleted.

experts/README.md

-3
This file was deleted.

pyproject.toml

+13-26
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
11
[build-system]
2-
requires = ["setuptools>=40.9.0", "wheel"]
3-
4-
[tool.cibuildwheel]
5-
build = ["cp36-win*", "cp37-win*", "cp38-win*", "cp39-win*", "cp310-win*"]
6-
skip = "pp*"
7-
#archs = ["auto"]
8-
#repair-wheel-command = ""
9-
10-
[tool.cibuildwheel.windows]
11-
archs = ["x86", "AMD64"]
12-
13-
[tool.isort]
14-
profile = "black"
15-
multi_line_output = 3
16-
17-
[tool.poetry]
18-
name = "delphivcl"
19-
version = "0.1.18"
20-
description = ""
21-
authors = ["Jim McKeth", "Lucas Belo<[email protected]>", "Lucio Montero<[email protected]>"]
22-
23-
[tool.poetry.dependencies]
24-
python = ">=3.6<=3.10"
25-
26-
[tool.poetry.dev-dependencies]
27-
pytest = "^6.2.5"
2+
requires = [
3+
"setuptools >= 54",
4+
"setuptools_scm[toml] >= 4, <6",
5+
"setuptools_scm_git_archive",
6+
"wheel >= 0.29.0",
7+
]
8+
build-backend = 'setuptools.build_meta'
9+
10+
[tool.setuptools_scm]
11+
version_scheme = "post-release"
12+
local_scheme = "no-local-version"
13+
write_to = "delphivcl/__version__.py"
14+
git_describe_command = "git describe --dirty --tags --long --match v* --first-parent"

setup.cfg

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[egg_info]
2+
tag_build =
3+
tag_date = 0
4+
tag_svn_revision = 0
5+
6+
[bdist_wheel]
7+
universal = 0
8+
9+
[build_sphinx]
10+
source-dir = docs/source
11+
build-dir = _build
12+
all-files = True
13+
14+
[metadata]
15+
name = delphivcl
16+
version = 1.0.5
17+
description = Delphi VCL for Python
18+
long_description = file: README.md
19+
long_description_content_type = text/markdown; charset=UTF-8
20+
url = https://github.com/Embarcadero/DelphiVCL4Python
21+
author = Lucas Belo, Jim McKeeth
22+
author_email = [email protected]
23+
license = BSD
24+
license_files = ['LICENSE.md']
25+
classifiers =
26+
Intended Audience :: Developers
27+
Topic :: Software Development
28+
License :: Other/Proprietary License
29+
Programming Language :: Python
30+
Programming Language :: Python :: 3
31+
Programming Language :: Python :: 3.6
32+
Programming Language :: Python :: 3.7
33+
Programming Language :: Python :: 3.8
34+
Programming Language :: Python :: 3.9
35+
Programming Language :: Python :: 3.10
36+
Programming Language :: Python :: 3.11
37+
Programming Language :: Python :: 3 :: Only
38+
Operating System :: Microsoft :: Windows
39+
project_urls =
40+
Documentation = https://embarcadero.github.io/DelphiVCL4Python
41+
Source = https://github.com/Embarcadero/DelphiVCL4Python
42+
Tracker = https://github.com/Embarcadero/DelphiVCL4Python/issues
43+
44+
[options]
45+
zip_safe = False
46+
packages = find:
47+
platforms = any
48+
include_package_data = True
49+
install_requires =
50+
python_requires = >=3
51+
setup_requires =
52+
setuptools_scm
53+
cmdclass =
54+
bdist_wheel = build.BDistWheel

0 commit comments

Comments
 (0)