Skip to content

Commit 1b31883

Browse files
authored
Merge pull request #68 from Embarcadero/sanitization
Project sanitization
2 parents 8b6df7e + 60c21be commit 1b31883

25 files changed

+1270
-219
lines changed

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

Lines changed: 15 additions & 17 deletions
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:
@@ -78,35 +73,38 @@ jobs:
7873
name: Upload to PyPI test
7974
needs: [build_wheels_win_32, build_wheels_win_64]
8075
runs-on: ubuntu-latest
81-
# upload to PyPI test only for pushes to 'deploy-pypi-test'
82-
if: github.event_name == 'push' && github.ref == 'refs/heads/deploy-pypi-test'
76+
environment:
77+
name: pypi
78+
url: https://test.pypi.org/project/delphivcl
79+
permissions:
80+
id-token: write
81+
if: github.ref == 'refs/heads/main'
8382
steps:
8483
- uses: actions/download-artifact@v2
8584
with:
8685
name: artifact
8786
path: dist
8887

8988
- name: Publish package to TestPyPI
90-
uses: pypa/gh-action-pypi-publish@master
89+
uses: pypa/gh-action-pypi-publish@release/v1
9190
with:
92-
user: ${{ secrets.test_pypi_username }}
93-
password: ${{ secrets.test_pypi_password }}
94-
repository_url: https://test.pypi.org/legacy/
91+
repository_url: https://test.pypi.org/legacy/
9592

9693
upload_pypi:
9794
name: Upload to PyPI
9895
needs: [build_wheels_win_32, build_wheels_win_64]
9996
runs-on: ubuntu-latest
100-
# upload to PyPI only for pushes to 'deploy-pypi'
101-
if: github.event_name == 'push' && github.ref == 'refs/heads/deploy-pypi'
97+
environment:
98+
name: pypi
99+
url: https://pypi.org/project/delphivcl/
100+
permissions:
101+
id-token: write
102+
if: startsWith(github.ref, 'refs/tags/v')
102103
steps:
103104
- uses: actions/download-artifact@v2
104105
with:
105106
name: artifact
106107
path: dist
107108

108109
- name: Publish package to PyPI
109-
uses: pypa/gh-action-pypi-publish@master
110-
with:
111-
user: ${{ secrets.pypi_username }}
112-
password: ${{ secrets.pypi_password }}
110+
uses: pypa/gh-action-pypi-publish@release/v1

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

Lines changed: 1 addition & 4 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 133 additions & 0 deletions
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

Lines changed: 46 additions & 35 deletions
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

Lines changed: 0 additions & 1 deletion
This file was deleted.

experts/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

lib/Win32/DelphiVCL.pyd

220 KB
Binary file not shown.

lib/Win64/DelphiVCL.pyd

381 KB
Binary file not shown.

pyproject.toml

Lines changed: 13 additions & 26 deletions
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"

samples/ListView/images/add-16.png

125 Bytes
Loading

samples/ListView/images/add-32.png

159 Bytes
Loading

samples/ListView/images/item-16.png

329 Bytes
Loading

samples/ListView/images/item-32.png

605 Bytes
Loading

samples/ListView/images/remove-16.png

101 Bytes
Loading

samples/ListView/images/remove-32.png

132 Bytes
Loading

samples/ListView/listview_project.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# ---------------------------------------------------------------------------------
2+
# Name: listview_project.py
3+
# Purpose: DelphiVCL for Python sample
4+
#
5+
# Author: lmbelo, Priyatham
6+
#
7+
# Created: 08/28/2023
8+
# Copyright: 2020-2023 Embarcadero Technologies, Inc.
9+
# License: https://github.com/Embarcadero/DelphiVCL4Python/blob/main/LICENSE.md
10+
# ---------------------------------------------------------------------------------
11+
12+
from delphivcl import *
13+
from listview_unit import ListViewForm
14+
15+
def main():
16+
Application.Initialize()
17+
Application.Title = 'List View Sample'
18+
MainForm = ListViewForm(Application)
19+
MainForm.Show()
20+
FreeConsole()
21+
Application.Run()
22+
23+
if __name__ == '__main__':
24+
main()

0 commit comments

Comments
 (0)