Skip to content

Commit

Permalink
Merge pull request #68 from Embarcadero/sanitization
Browse files Browse the repository at this point in the history
Project sanitization
  • Loading branch information
checkdigits authored Sep 5, 2023
2 parents 8b6df7e + 60c21be commit 1b31883
Show file tree
Hide file tree
Showing 25 changed files with 1,270 additions and 219 deletions.
32 changes: 15 additions & 17 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 Down Expand Up @@ -78,35 +73,38 @@ jobs:
name: Upload to PyPI test
needs: [build_wheels_win_32, build_wheels_win_64]
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/delphivcl
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_wheels_win_32, build_wheels_win_64]
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/delphivcl/
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.
5 changes: 1 addition & 4 deletions .github/workflows/tests.yaml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ name: Tests
on:
push:
branches:
- main
- test
# Release branches
#- "[0-9]+.[0-9]+.X"
- main

# Manual run
workflow_dispatch:
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
recursive-include delphivcl *.pyd
recursive-include delphivcl docs.xml
133 changes: 133 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
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, "delphivcl")
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")]

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"
else:
is_cross_compiling = False

return (is_cross_compiling, lib_dir)

'''
Copy the VCL 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()
if plat_sys == "Windows":
if (sys.maxsize > 2**32):
# Win x64
lib_dir = "Win64"
else:
# Win x86
lib_dir = "Win32"

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()
81 changes: 46 additions & 35 deletions delphivcl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,58 @@
import sys, os, sys, platform
from os import environ
import importlib, importlib.machinery, importlib.util
import sys
import os
import sys
import platform
import importlib
import importlib.machinery
import importlib.util

class PyVerNotSupported(Exception):
pass

def findmodule():
pyver = f"{sys.version_info.major}.{sys.version_info.minor}"
ossys = platform.system()
libdir = None
def find_extension_module():
py_ver = f"{sys.version_info.major}.{sys.version_info.minor}"
plat_sys = platform.system()
lib_dir = None

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

if ossys == "Windows":
if (sys.maxsize > 2**32):
#Win x64
libdir = "Win64"
if plat_sys == "Windows":
if (sys.maxsize > 2**32):
# Win x64
lib_dir = "Win64"
else:
# Win x86
lib_dir = "Win32"

if lib_dir:
lib_dir = os.path.join(os.path.dirname(
os.path.abspath(__file__)), lib_dir)
if not os.path.exists(lib_dir):
raise ValueError(
"DelphiVCL module not found. \
Try to reinstall the delphivcl package or check for support compatibility.")

for file_name in os.listdir(lib_dir):
if 'DelphiVCL' in file_name:
return os.path.join(lib_dir, os.path.basename(file_name))
raise ValueError(
"DelphiVCL module not found. Try to reinstall the delphivcl package.")
else:
#Win x86
libdir = "Win32"

if libdir:
sdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), libdir)
if not os.path.exists(sdir):
raise ValueError("DelphiVCL module not found. Try to reinstall the delphivcl package or check for support compatibility.")
for fname in os.listdir(sdir):
if 'DelphiVCL' in fname:
return os.path.join(sdir, os.path.basename(fname))
raise ValueError("DelphiVCL module not found. Try to reinstall the delphivcl package.")
else:
raise ValueError("Unsupported platform.")
raise ValueError("Unsupported platform.")


def new_import():
modulefullpath = findmodule()
loader = importlib.machinery.ExtensionFileLoader("DelphiVCL", modulefullpath)
spec = importlib.util.spec_from_file_location("DelphiVCL", modulefullpath,
loader=loader, submodule_search_locations=None)
ld = loader.create_module(spec)
lib_path = find_extension_module()
loader = importlib.machinery.ExtensionFileLoader("DelphiVCL", lib_path)
spec = importlib.util.spec_from_file_location("DelphiVCL",
lib_path,
loader=loader,
submodule_search_locations=None)
loader.create_module(spec)
package = importlib.util.module_from_spec(spec)
sys.modules["delphivcl"] = package
spec.loader.exec_module(package)
return package

#Import the shared lib
package = new_import()

# Import the extension module
package = new_import()
1 change: 0 additions & 1 deletion delphivcl/__version__.py

This file was deleted.

3 changes: 0 additions & 3 deletions experts/README.md

This file was deleted.

Binary file modified lib/Win32/DelphiVCL.pyd
Binary file not shown.
Binary file modified lib/Win64/DelphiVCL.pyd
Binary file not shown.
39 changes: 13 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
[build-system]
requires = ["setuptools>=40.9.0", "wheel"]

[tool.cibuildwheel]
build = ["cp36-win*", "cp37-win*", "cp38-win*", "cp39-win*", "cp310-win*"]
skip = "pp*"
#archs = ["auto"]
#repair-wheel-command = ""

[tool.cibuildwheel.windows]
archs = ["x86", "AMD64"]

[tool.isort]
profile = "black"
multi_line_output = 3

[tool.poetry]
name = "delphivcl"
version = "0.1.18"
description = ""
authors = ["Jim McKeth", "Lucas Belo<lucas.belo@live.com>", "Lucio Montero<lucioric2000@hotmail.com>"]

[tool.poetry.dependencies]
python = ">=3.6<=3.10"

[tool.poetry.dev-dependencies]
pytest = "^6.2.5"
requires = [
"setuptools >= 54",
"setuptools_scm[toml] >= 4, <6",
"setuptools_scm_git_archive",
"wheel >= 0.29.0",
]
build-backend = 'setuptools.build_meta'

[tool.setuptools_scm]
version_scheme = "post-release"
local_scheme = "no-local-version"
write_to = "delphivcl/__version__.py"
git_describe_command = "git describe --dirty --tags --long --match v* --first-parent"
Binary file added samples/ListView/images/add-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/ListView/images/add-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/ListView/images/item-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/ListView/images/item-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/ListView/images/remove-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/ListView/images/remove-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions samples/ListView/listview_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ---------------------------------------------------------------------------------
# Name: listview_project.py
# Purpose: DelphiVCL for Python sample
#
# Author: lmbelo, Priyatham
#
# Created: 08/28/2023
# Copyright: 2020-2023 Embarcadero Technologies, Inc.
# License: https://github.com/Embarcadero/DelphiVCL4Python/blob/main/LICENSE.md
# ---------------------------------------------------------------------------------

from delphivcl import *
from listview_unit import ListViewForm

def main():
Application.Initialize()
Application.Title = 'List View Sample'
MainForm = ListViewForm(Application)
MainForm.Show()
FreeConsole()
Application.Run()

if __name__ == '__main__':
main()
Loading

0 comments on commit 1b31883

Please sign in to comment.