Skip to content

Commit 32e17c3

Browse files
committed
Project sanitization
1 parent e59cf3c commit 32e17c3

14 files changed

+356
-251
lines changed

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

+28-18
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:
@@ -25,6 +20,8 @@ jobs:
2520
steps:
2621
- name: Check out repository
2722
uses: actions/checkout@v3
23+
with:
24+
fetch-depth: 0
2825

2926
- name: Set up Python ${{ matrix.python }}
3027
uses: actions/setup-python@v3
@@ -55,6 +52,8 @@ jobs:
5552
steps:
5653
- name: Check out repository
5754
uses: actions/checkout@v3
55+
with:
56+
fetch-depth: 0
5857

5958
- name: Set up Python ${{ matrix.python }}
6059
uses: actions/setup-python@v3
@@ -86,6 +85,8 @@ jobs:
8685
steps:
8786
- name: Check out repository
8887
uses: actions/checkout@v3
88+
with:
89+
fetch-depth: 0
8990

9091
- name: Set up Python ${{ matrix.python }}
9192
uses: actions/setup-python@v3
@@ -112,11 +113,13 @@ jobs:
112113
matrix:
113114
python: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11']
114115
include:
115-
- os: [ubuntu-20.04] #ubuntu-latest doesn't supports cp36
116+
- os: [ubuntu-20.04] #ubuntu-latest doesn't support cp36
116117
arch: ["x86_64"]
117118
steps:
118119
- name: Check out repository
119120
uses: actions/checkout@v3
121+
with:
122+
fetch-depth: 0
120123

121124
- name: Set up Python ${{ matrix.python }}
122125
uses: actions/setup-python@v3
@@ -147,6 +150,8 @@ jobs:
147150
steps:
148151
- name: Check out repository
149152
uses: actions/checkout@v3
153+
with:
154+
fetch-depth: 0
150155

151156
- name: Set up Python ${{ matrix.python }}
152157
uses: actions/setup-python@v3
@@ -177,6 +182,8 @@ jobs:
177182
steps:
178183
- name: Check out repository
179184
uses: actions/checkout@v3
185+
with:
186+
fetch-depth: 0
180187

181188
- name: Set up Python ${{ matrix.python }}
182189
uses: actions/setup-python@v3
@@ -199,35 +206,38 @@ jobs:
199206
name: Upload to PyPI test
200207
needs: [build_universal_wheel, build_wheels_win_32, build_wheels_win_64, build_wheels_manylinux, build_wheels_macos, build_wheels_macos_arm]
201208
runs-on: ubuntu-latest
202-
# upload to PyPI test only for pushes to 'deploy-pypi-test'
203-
if: github.event_name == 'push' && github.ref == 'refs/heads/deploy-pypi-test'
209+
environment:
210+
name: pypi
211+
url: https://test.pypi.org/project/delphifmx
212+
permissions:
213+
id-token: write
214+
if: github.ref == 'refs/heads/main'
204215
steps:
205216
- uses: actions/download-artifact@v2
206217
with:
207218
name: artifact
208219
path: dist
209220

210221
- name: Publish package to TestPyPI
211-
uses: pypa/gh-action-pypi-publish@master
222+
uses: pypa/gh-action-pypi-publish@release/v1
212223
with:
213-
user: ${{ secrets.test_pypi_username }}
214-
password: ${{ secrets.test_pypi_password }}
215-
repository_url: https://test.pypi.org/legacy/
224+
repository_url: https://test.pypi.org/legacy/
216225

217226
upload_pypi:
218227
name: Upload to PyPI
219228
needs: [build_universal_wheel, build_wheels_win_32, build_wheels_win_64, build_wheels_manylinux, build_wheels_macos, build_wheels_macos_arm]
220229
runs-on: ubuntu-latest
221-
# upload to PyPI only for pushes to 'deploy-pypi'
222-
if: github.event_name == 'push' && github.ref == 'refs/heads/deploy-pypi'
230+
environment:
231+
name: pypi
232+
url: https://pypi.org/project/delphifmx
233+
permissions:
234+
id-token: write
235+
if: startsWith(github.ref, 'refs/tags/v')
223236
steps:
224237
- uses: actions/download-artifact@v2
225238
with:
226239
name: artifact
227240
path: dist
228241

229242
- name: Publish package to PyPI
230-
uses: pypa/gh-action-pypi-publish@master
231-
with:
232-
user: ${{ secrets.pypi_username }}
233-
password: ${{ secrets.pypi_password }}
243+
uses: pypa/gh-action-pypi-publish@release/v1

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

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

118
# Manual run
129
workflow_dispatch:

MANIFEST.in

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
recursive-include delphifmx *.pyd
2+
recursive-include delphifmx *.so
3+
recursive-include delphifmx *.dylib
4+
recursive-include delphifmx docs.xml

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Be sure to check out the [PythonFMXBuilder](https://github.com/Embarcadero/Pytho
1414
## eBook and Styles Bundle
1515

1616
There is a free [eBook and styles bundle](https://embt.co/PythonGUIBundle) with 29 custom styles and 50 pages of content.
17-
<a href="https://embt.co/PythonGUIBundle"><img alt="Download the free eBook and Python styles bundle." width="750" src="https://raw.githubusercontent.com/Embarcadero/PythonFMXBuilder/main/images/30_Banner_Ebook_GGetting%20Started%20with%20Python%20GUI_830x256.jpg"></a>
17+
<a href="https://embt.co/PythonGUIBundle"><img alt="Download the free eBook and Python styles bundle." width="750" src="https://github.com/Embarcadero/DelphiFMX4Python/blob/main/images/30_Banner_Ebook_Getting_Started_with_Python_GUI_830x256.jpg?raw=true"></a>
1818

1919
You can see the June 2022 live stream replay covering [PythonFMX and related projects](https://youtu.be/Ccfe0rbwgcM).
2020

build.py

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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, "delphifmx")
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+
os.path.join(self.pkg_dir, "Linux64"),
47+
os.path.join(self.pkg_dir, "OSX64"),
48+
os.path.join(self.pkg_dir, "OSXARM64")]
49+
50+
for lib_dir in lib_dirs:
51+
if os.path.isdir(lib_dir):
52+
shutil.rmtree(lib_dir)
53+
54+
# Wait until the OS remove all dirs
55+
for lib_dir in lib_dirs:
56+
for attempts in range(3):
57+
if not os.path.isdir(lib_dir):
58+
break
59+
else:
60+
time.sleep(1)
61+
62+
'''
63+
Cross-compiling wheel.
64+
This generates a wheel following the cross platform set on --plat-name.
65+
See: https://docs.python.org/3/distutils/builtdist.html#cross-compiling-on-windows
66+
'''
67+
68+
def __check_cross_compiling(self):
69+
is_cross_compiling = False
70+
lib_dir = None
71+
72+
if self.plat_name:
73+
is_cross_compiling = True
74+
if self.plat_name == "win32":
75+
lib_dir = "Win32"
76+
elif self.plat_name == "win_amd64":
77+
lib_dir = "Win64"
78+
elif self.plat_name == "manylinux1_x86_64":
79+
lib_dir = "Linux64"
80+
# macosx_10_9_x86_64
81+
elif self.plat_name.startswith("macosx") and self.plat_name.endswith("x86_64"):
82+
lib_dir = "OSX64"
83+
# macosx_11_0_arm64
84+
elif self.plat_name.startswith("macosx") and self.plat_name.endswith("arm64"):
85+
lib_dir = "OSXARM64"
86+
else:
87+
is_cross_compiling = False
88+
89+
return (is_cross_compiling, lib_dir)
90+
91+
'''
92+
Copy the FMX extension module(s) to the package data folder.
93+
Source distributions and Universal binary distributions will deliver
94+
all library versions. The right one will be loaded by __init__.py.
95+
Platform distributions will deliver only the library that matches the runner.
96+
'''
97+
98+
def __pick_and_copy_libraries(self):
99+
if ("sdist" in sys.argv) or (("bdist_wheel" in sys.argv) and ("--universal" in sys.argv)):
100+
# sdist/bdist[--universal] deploy all extension modules
101+
distutils.dir_util.copy_tree("lib", self.pkg_dir)
102+
else:
103+
# Deploys the current platform extension module only
104+
is_cross_compiling, lib_dir = self.__check_cross_compiling()
105+
if not is_cross_compiling:
106+
plat_sys = platform.system()
107+
plat_mac = platform.machine()
108+
if plat_sys == "Windows":
109+
if (sys.maxsize > 2**32):
110+
# Win x64
111+
lib_dir = "Win64"
112+
else:
113+
# Win x86
114+
lib_dir = "Win32"
115+
elif plat_sys == "Linux":
116+
if plat_mac == "x86_64":
117+
# Linux x86_64
118+
lib_dir = "Linux64"
119+
elif plat_sys == "Darwin":
120+
if plat_mac == "x86_64":
121+
# macOS x86_64
122+
lib_dir = "OSX64"
123+
elif plat_mac == "arm64":
124+
# macOS arm64
125+
lib_dir = "OSXARM64"
126+
127+
if lib_dir:
128+
distutils.dir_util.copy_tree(os.path.join(
129+
"lib", lib_dir), os.path.join(self.pkg_dir, lib_dir))
130+
else:
131+
raise ValueError("Unsupported platform.")
132+
133+
'''
134+
Copy the XML doc file to the package data folder.
135+
The docs.xml file is the result of the compilation of all xml doc files.
136+
'''
137+
138+
def __pick_and_copy_docs(self):
139+
# Copy the doc files to the package folder into the doc subfolder
140+
docs_file = os.path.join("docs", "xml", "docs.xml")
141+
if os.path.exists(docs_file):
142+
pkg_doc_dir = os.path.join(self.pkg_dir, "doc")
143+
if not os.path.exists(pkg_doc_dir):
144+
os.mkdir(pkg_doc_dir)
145+
distutils.file_util.copy_file(
146+
docs_file, os.path.join(pkg_doc_dir, "docs.xml"))
147+
148+
def build_package_data(self):
149+
self.__pick_and_copy_libraries()
150+
self.__pick_and_copy_docs()
151+
152+
153+
def setup():
154+
builder = PackageDataBuilder()
155+
builder.clean_up()
156+
builder.build_package_data()

0 commit comments

Comments
 (0)