Skip to content

Commit b7b6d9d

Browse files
authored
Merge pull request K0lb3#159 from squaresmile/setuptools
Switch to setuptools build backend
2 parents b7d9f77 + 61fe574 commit b7b6d9d

4 files changed

Lines changed: 98 additions & 124 deletions

File tree

‎.github/workflows/python-package.yml‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313
name: ${{ matrix.os }}
1414

1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v3
1717

1818
- name: Set up Python
19-
uses: actions/setup-python@v1
19+
uses: actions/setup-python@v4
2020
with:
2121
python-version: "3.7"
2222

@@ -37,42 +37,51 @@ jobs:
3737
strategy:
3838
fail-fast: false
3939
matrix:
40-
os: ["ubuntu-latest", "macOS-latest", "windows-latest"]
41-
cp: ["cp37", "cp38", "cp39", "cp310"]
40+
os: ["ubuntu-20.04", "windows-2019", "macos-11"]
41+
cp: ["cp37", "cp38", "cp39", "cp310", "cp311"]
4242

4343
timeout-minutes: 30
4444

4545
runs-on: ${{ matrix.os }}
4646
name: ${{ matrix.os }} - ${{ matrix.cp }}
4747

4848
steps:
49-
- uses: actions/checkout@v2
49+
- uses: actions/checkout@v3
5050

5151
- name: Set up Python
52-
uses: actions/setup-python@v1
52+
uses: actions/setup-python@v4
5353
with:
5454
python-version: "3.10"
5555

5656
- name: Install dependencies
5757
run: |
58-
python -m pip install --upgrade pip wheel setuptools hatch
59-
pip install --upgrade twine
58+
python -m pip install --upgrade pip wheel setuptools
59+
python -m pip install --upgrade twine build
6060
6161
- name: Set up QEMU
6262
if: runner.os == 'Linux'
63-
uses: docker/setup-qemu-action@v1
63+
uses: docker/setup-qemu-action@v2
6464
with:
6565
platforms: all
6666

6767
- name: Build wheels
68-
uses: pypa/cibuildwheel@v2.3.1
68+
uses: pypa/cibuildwheel@v2.11.2
6969
env:
7070
CIBW_ARCHS_LINUX: auto aarch64
71+
CIBW_ARCHS_MACOS: x86_64 arm64 universal2
7172
CIBW_BUILD: |
72-
${{ matrix.cp }}-manylinux_x86_64 ${{ matrix.cp }}-manylinux_i686 ${{ matrix.cp }}-manylinux_aarch64 ${{ matrix.cp }}-win_amd64 ${{ matrix.cp }}-win32 ${{ matrix.cp }}-macosx_x86_64
73+
${{ matrix.cp }}-manylinux_x86_64
74+
${{ matrix.cp }}-manylinux_i686
75+
${{ matrix.cp }}-manylinux_aarch64
76+
${{ matrix.cp }}-win_amd64
77+
${{ matrix.cp }}-win32
78+
${{ matrix.cp }}-macosx_x86_64
79+
${{ matrix.cp }}-macosx_arm64
80+
${{ matrix.cp }}-macosx_universal2
7381
CIBW_REPAIR_WHEEL_COMMAND: "" # Disable auditwheel
7482
CIBW_TEST_REQUIRES: pytest
7583
CIBW_TEST_COMMAND: pytest -v -s {package}/tests
84+
CIBW_TEST_SKIP: "*-macosx_arm64 *-macosx_universal2:arm64"
7685

7786
- name: Publish to PyPI
7887
if: success() && github.event_name == 'push' && env.TWINE_PASSWORD != '' && github.ref == 'refs/heads/master'
@@ -81,5 +90,5 @@ jobs:
8190
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
8291
run: |
8392
twine upload ./wheelhouse/*.whl --skip-existing
84-
hatch build -t sdist
93+
python -m build --sdist
8594
twine upload ./dist/*.tar.gz --skip-existing

‎build_hook.py‎

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

‎pyproject.toml‎

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
2-
requires = ["hatchling"]
3-
build-backend = "hatchling.build"
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "UnityPy"
@@ -53,23 +53,5 @@ dynamic = ["version"]
5353
"Homepage" = "https://github.com/K0lb3/UnityPy"
5454
"Bug Tracker" = "https://github.com/K0lb3/UnityPy/issues"
5555

56-
[tool.hatch.version]
57-
# path to the file containing the version number
58-
path = "UnityPy/__init__.py"
59-
60-
[tool.hatch.build.targets.sdist]
61-
# include all files required to build the package
62-
only-include = ["UnityPy", "UnityPyBoost", "tests", "build_hook.py"]
63-
# exclude prebuild files
64-
exclude = ["UnityPy/UnityPyBoost*"]
65-
66-
[tool.hatch.build.targets.wheel]
67-
# UnityPyBoost will be compiled by the hook and added to UnityPy
68-
# therefore UnityPyBoost and hook_build aren't needed
69-
only-include = ["UnityPy", "tests"]
70-
# exclude all prebuild files and all FMOD libs
71-
# the fmod lib for the target platform is force included via the hook
72-
exclude = ["UnityPy/lib/FMOD", "UnityPy/UnityPyBoost*"]
73-
74-
[tool.hatch.build.targets.wheel.hooks.custom]
75-
path = "build_hook.py"
56+
[tool.setuptools.dynamic]
57+
version = { attr = "UnityPy.__version__" }

‎setup.py‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import os
2+
import platform
3+
from setuptools import setup, Extension, find_packages
4+
5+
6+
INSTALL_DIR = os.path.dirname(os.path.realpath(__file__))
7+
UNITYPYBOOST_DIR = os.path.join(INSTALL_DIR, "UnityPyBoost")
8+
9+
10+
def get_fmod_library():
11+
# determine system - Windows, Darwin, Linux, Android
12+
system = platform.system()
13+
if system == "Linux" and "ANDROID_BOOTLOGO" in os.environ:
14+
system = "Android"
15+
# determine architecture
16+
machine = platform.machine()
17+
arch = platform.architecture()[0]
18+
19+
lib_name = ""
20+
if system in ["Windows", "Darwin"]:
21+
lib_name = "fmod.dll" if system == "Windows" else "libfmod.dylib"
22+
if arch == "32bit":
23+
arch = "x86"
24+
elif arch == "64bit":
25+
arch = "x64"
26+
elif system == "Linux":
27+
lib_name = "libfmod.so"
28+
# Raspberry Pi and Linux on arm projects
29+
if "arm" in machine:
30+
if arch == "32bit":
31+
arch = "armhf" if machine.endswith("l") else "arm"
32+
elif arch == "64bit":
33+
return None
34+
elif arch == "32bit":
35+
arch = "x86"
36+
elif arch == "64bit":
37+
arch = "x86_64"
38+
else:
39+
return None
40+
41+
return f"lib/FMOD/{system}/{arch}/{lib_name}"
42+
43+
44+
unitypy_package_data = ["resources/uncompressed.tpk"]
45+
fmod_lib = get_fmod_library()
46+
if fmod_lib is not None:
47+
unitypy_package_data.append(fmod_lib)
48+
49+
50+
# These packages are missing __init__.py so setuptools will warn about unspecified packages
51+
extra_packages = [
52+
"UnityPy.resources",
53+
"UnityPy.tools",
54+
"UnityPy.tools.libil2cpp_helper",
55+
]
56+
57+
58+
setup(
59+
packages=find_packages() + extra_packages,
60+
package_data={"UnityPy": unitypy_package_data},
61+
ext_modules=[
62+
Extension(
63+
"UnityPy.UnityPyBoost",
64+
[
65+
f"UnityPyBoost/{f}"
66+
for f in os.listdir(UNITYPYBOOST_DIR)
67+
if f.endswith(".c")
68+
],
69+
language="c",
70+
include_dirs=[UNITYPYBOOST_DIR],
71+
)
72+
],
73+
)

0 commit comments

Comments
 (0)