Skip to content

Commit

Permalink
Project sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
lmbelo committed Sep 6, 2023
1 parent e59cf3c commit 32e17c3
Show file tree
Hide file tree
Showing 14 changed files with 356 additions and 251 deletions.
46 changes: 28 additions & 18 deletions .github/workflows/deploy-wheels.yaml → .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ name: Build

on:
push:
branches:
- deploy-pypi-test
- deploy-pypi
# Release branches
#- "[0-9]+.[0-9]+.X"

# Manual run
workflow_dispatch:
Expand All @@ -25,6 +20,8 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v3
Expand Down Expand Up @@ -55,6 +52,8 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v3
Expand Down Expand Up @@ -86,6 +85,8 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v3
Expand All @@ -112,11 +113,13 @@ jobs:
matrix:
python: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11']
include:
- os: [ubuntu-20.04] #ubuntu-latest doesn't supports cp36
- os: [ubuntu-20.04] #ubuntu-latest doesn't support cp36
arch: ["x86_64"]
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v3
Expand Down Expand Up @@ -147,6 +150,8 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v3
Expand Down Expand Up @@ -177,6 +182,8 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v3
Expand All @@ -199,35 +206,38 @@ jobs:
name: Upload to PyPI test
needs: [build_universal_wheel, build_wheels_win_32, build_wheels_win_64, build_wheels_manylinux, build_wheels_macos, build_wheels_macos_arm]
runs-on: ubuntu-latest
# upload to PyPI test only for pushes to 'deploy-pypi-test'
if: github.event_name == 'push' && github.ref == 'refs/heads/deploy-pypi-test'
environment:
name: pypi
url: https://test.pypi.org/project/delphifmx
permissions:
id-token: write
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/download-artifact@v2
with:
name: artifact
path: dist

- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: ${{ secrets.test_pypi_username }}
password: ${{ secrets.test_pypi_password }}
repository_url: https://test.pypi.org/legacy/
repository_url: https://test.pypi.org/legacy/

upload_pypi:
name: Upload to PyPI
needs: [build_universal_wheel, build_wheels_win_32, build_wheels_win_64, build_wheels_manylinux, build_wheels_macos, build_wheels_macos_arm]
runs-on: ubuntu-latest
# upload to PyPI only for pushes to 'deploy-pypi'
if: github.event_name == 'push' && github.ref == 'refs/heads/deploy-pypi'
environment:
name: pypi
url: https://pypi.org/project/delphifmx
permissions:
id-token: write
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v2
with:
name: artifact
path: dist

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: ${{ secrets.pypi_username }}
password: ${{ secrets.pypi_password }}
uses: pypa/gh-action-pypi-publish@release/v1
File renamed without changes.
3 changes: 0 additions & 3 deletions .github/workflows/tests.yaml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
push:
branches:
- main
- test
# Release branches
#- "[0-9]+.[0-9]+.X"

# Manual run
workflow_dispatch:
Expand Down
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
recursive-include delphifmx *.pyd
recursive-include delphifmx *.so
recursive-include delphifmx *.dylib
recursive-include delphifmx docs.xml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Be sure to check out the [PythonFMXBuilder](https://github.com/Embarcadero/Pytho
## eBook and Styles Bundle

There is a free [eBook and styles bundle](https://embt.co/PythonGUIBundle) with 29 custom styles and 50 pages of content.
<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>
<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>

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

Expand Down
156 changes: 156 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import sys
import os
import sys
import shutil
import time
import platform
import distutils.dir_util
from wheel.bdist_wheel import bdist_wheel


'''
BDistWheel forces python and abi wheel tags for binary distributions
'''


class BDistWheel(bdist_wheel):

def finalize_options(self):
bdist_wheel.finalize_options(self)
self.root_is_pure = ("--universal" in sys.argv)


'''
Sort out the platform library for binary distribution and add to the package directory.
Place all libraries onto the package directory for source distribution.
Place the XML doc file onto the package directory.
'''


class PackageDataBuilder():

def __init__(self):
self.pkg_dir = os.path.join(os.curdir, "delphifmx")
self.plat_name = None
for arg in sys.argv:
if arg.startswith("--plat-name=") and (len(arg.split("=")) == 2):
self.plat_name = arg.split("=")[1]

'''
Must run "python setup.py clean --all" between builds.
'''

def clean_up(self):
lib_dirs = [os.path.join(self.pkg_dir, "Win32"),
os.path.join(self.pkg_dir, "Win64"),
os.path.join(self.pkg_dir, "Linux64"),
os.path.join(self.pkg_dir, "OSX64"),
os.path.join(self.pkg_dir, "OSXARM64")]

for lib_dir in lib_dirs:
if os.path.isdir(lib_dir):
shutil.rmtree(lib_dir)

# Wait until the OS remove all dirs
for lib_dir in lib_dirs:
for attempts in range(3):
if not os.path.isdir(lib_dir):
break
else:
time.sleep(1)

'''
Cross-compiling wheel.
This generates a wheel following the cross platform set on --plat-name.
See: https://docs.python.org/3/distutils/builtdist.html#cross-compiling-on-windows
'''

def __check_cross_compiling(self):
is_cross_compiling = False
lib_dir = None

if self.plat_name:
is_cross_compiling = True
if self.plat_name == "win32":
lib_dir = "Win32"
elif self.plat_name == "win_amd64":
lib_dir = "Win64"
elif self.plat_name == "manylinux1_x86_64":
lib_dir = "Linux64"
# macosx_10_9_x86_64
elif self.plat_name.startswith("macosx") and self.plat_name.endswith("x86_64"):
lib_dir = "OSX64"
# macosx_11_0_arm64
elif self.plat_name.startswith("macosx") and self.plat_name.endswith("arm64"):
lib_dir = "OSXARM64"
else:
is_cross_compiling = False

return (is_cross_compiling, lib_dir)

'''
Copy the FMX extension module(s) to the package data folder.
Source distributions and Universal binary distributions will deliver
all library versions. The right one will be loaded by __init__.py.
Platform distributions will deliver only the library that matches the runner.
'''

def __pick_and_copy_libraries(self):
if ("sdist" in sys.argv) or (("bdist_wheel" in sys.argv) and ("--universal" in sys.argv)):
# sdist/bdist[--universal] deploy all extension modules
distutils.dir_util.copy_tree("lib", self.pkg_dir)
else:
# Deploys the current platform extension module only
is_cross_compiling, lib_dir = self.__check_cross_compiling()
if not is_cross_compiling:
plat_sys = platform.system()
plat_mac = platform.machine()
if plat_sys == "Windows":
if (sys.maxsize > 2**32):
# Win x64
lib_dir = "Win64"
else:
# Win x86
lib_dir = "Win32"
elif plat_sys == "Linux":
if plat_mac == "x86_64":
# Linux x86_64
lib_dir = "Linux64"
elif plat_sys == "Darwin":
if plat_mac == "x86_64":
# macOS x86_64
lib_dir = "OSX64"
elif plat_mac == "arm64":
# macOS arm64
lib_dir = "OSXARM64"

if lib_dir:
distutils.dir_util.copy_tree(os.path.join(
"lib", lib_dir), os.path.join(self.pkg_dir, lib_dir))
else:
raise ValueError("Unsupported platform.")

'''
Copy the XML doc file to the package data folder.
The docs.xml file is the result of the compilation of all xml doc files.
'''

def __pick_and_copy_docs(self):
# Copy the doc files to the package folder into the doc subfolder
docs_file = os.path.join("docs", "xml", "docs.xml")
if os.path.exists(docs_file):
pkg_doc_dir = os.path.join(self.pkg_dir, "doc")
if not os.path.exists(pkg_doc_dir):
os.mkdir(pkg_doc_dir)
distutils.file_util.copy_file(
docs_file, os.path.join(pkg_doc_dir, "docs.xml"))

def build_package_data(self):
self.__pick_and_copy_libraries()
self.__pick_and_copy_docs()


def setup():
builder = PackageDataBuilder()
builder.clean_up()
builder.build_package_data()
Loading

0 comments on commit 32e17c3

Please sign in to comment.