Skip to content

Commit fe62a26

Browse files
committed
Install from source
1 parent 144132d commit fe62a26

File tree

4 files changed

+58
-44
lines changed

4 files changed

+58
-44
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
run: |
5656
MATRIX_INCLUDE=$(
5757
{
58-
cibuildwheel --print-build-identifiers --platform linux --arch x86_64,aarch64,i686 | grep cp | jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \
58+
cibuildwheel --print-build-identifiers --platform linux --arch all | grep cp | jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \
5959
&& cibuildwheel --print-build-identifiers --platform macos --arch x86_64 | grep cp | jq -nRc '{"only": inputs, "os": "macos-13"}' \
6060
&& cibuildwheel --print-build-identifiers --platform macos --arch arm64 | grep cp | jq -nRc '{"only": inputs, "os": "macos-14"}' \
6161
&& cibuildwheel --print-build-identifiers --platform windows --arch x86,AMD64 | grep cp | jq -nRc '{"only": inputs, "os": "windows-latest"}'
@@ -89,20 +89,8 @@ jobs:
8989
only: ${{ matrix.only }}
9090
env:
9191
CIBW_BUILD_VERBOSITY: 1
92-
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
93-
CIBW_MANYLINUX_PYPY_X86_64_IMAGE: manylinux_2_28
94-
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux_2_28
95-
CIBW_MANYLINUX_PPC64LE_IMAGE: manylinux_2_28
96-
CIBW_MANYLINUX_S390X_IMAGE: manylinux_2_28
97-
CIBW_MANYLINUX_PYPY_AARCH64_IMAGE: manylinux_2_28
98-
CIBW_MANYLINUX_PYPY_I686_IMAGE: manylinux_2_28
99-
CIBW_MUSLLINUX_X86_64_IMAGE: musllinux_1_2
100-
CIBW_MUSLLINUX_I686_IMAGE: musllinux_1_2
101-
CIBW_MUSLLINUX_AARCH64_IMAGE: musllinux_1_2
102-
CIBW_MUSLLINUX_PPC64LE_IMAGE: musllinux_1_2
103-
CIBW_MUSLLINUX_S390X_IMAGE: musllinux_1_2
104-
CIBW_BEFORE_BUILD: bash -c "make install_libmagic"
105-
CIBW_TEST_COMMAND: python -c "import magic; assert magic.Magic(mime=True).from_buffer(b'\x00\x00\x00\x1cftypisom\x00\x00\x02\x00isomiso2mp41\x00') == 'video/mp4'"
92+
CIBW_BEFORE_BUILD: bash "add_libmagic.sh"
93+
CIBW_TEST_COMMAND: python -c "import magic; assert magic.Magic(mime=True).from_buffer(b'\x00\x00\x00\x1cftypiso5\x00\x00\x00\x01isomiso5hlsf\x00\x00') == 'video/mp4'"
10694

10795
- uses: actions/upload-artifact@v4
10896
with:

Makefile

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

add_libmagic.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
install_source() {
6+
version="file-5.45"
7+
(
8+
tmpfile="$(mktemp)" &&
9+
curl -sSLo "${tmpfile}" "https://astron.com/pub/file/${version}.tar.gz" &&
10+
tar xvf "${tmpfile}" &&
11+
cd "${version}" &&
12+
./configure &&
13+
make &&
14+
make install &&
15+
make installcheck &&
16+
cd .. &&
17+
rm -r "${version}"
18+
) || (cd .. && rm -r "${version}" && false)
19+
}
20+
21+
install_precompiled() {
22+
# Mac https://formulae.brew.sh/formula/libmagic
23+
# Debian https://packages.ubuntu.com/libmagic1
24+
# Alpine https://pkgs.alpinelinux.org/package/libmagic
25+
# RHEL https://git.almalinux.org/rpms/file
26+
# Windows https://github.com/julian-r/file-windows
27+
if [ -n "$(which brew)" ]; then
28+
brew install libmagic
29+
elif [ -n "$(which apt-get)" ]; then
30+
apt-get update
31+
apt-get install -y libmagic1
32+
elif [ -n "$(which apk)" ]; then
33+
apk add --update libmagic
34+
elif [ -n "$(which yum)" ]; then
35+
yum install file-libs
36+
else
37+
python -c 'import platform, sysconfig, io, zipfile, urllib.request; assert platform.system() == "Windows"; machine = "x86" if sysconfig.get_platform() == "win32" else "x64"; print(machine); zipfile.ZipFile(io.BytesIO(urllib.request.urlopen(f"https://github.com/julian-r/file-windows/releases/download/v5.44/file_5.44-build104-vs2022-{machine}.zip").read())).extractall(".")' &&
38+
ls -ltra
39+
fi
40+
}
41+
42+
copy_libmagic() {
43+
# on cibuildwheel, the lib needs to exist in the project before running setup.py
44+
# copy lib into the magic dir, regardless of platform
45+
libmagic_path="$(python -c 'from magic.loader import load_lib; print(load_lib()._name)')" &&
46+
cp "${libmagic_path}" "magic" &&
47+
# only on linux: additionally copy compiled db into magic dir
48+
( ( cp "/usr/local/share/misc/magic.mgc" "magic" || cp "/usr/share/misc/magic.mgc" "magic" ) || true ) &&
49+
# check what was copied
50+
ls -ltra magic
51+
}
52+
53+
install_source || install_precompiled
54+
copy_libmagic

magic/loader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def _lib_candidates():
3939
for i in prefixes:
4040
yield os.path.join(here, i)
4141
yield os.path.join(os.path.abspath('.'), i)
42+
yield os.path.join('/usr/local/lib', i)
4243
# on some linux systems (musl/alpine), find_library('magic') returns None
4344
# first try ldconfig with backup string in case of error
4445
yield subprocess.check_output(

0 commit comments

Comments
 (0)