hermetic-python-magic 0.4.27__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tim Hörmann
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
====
|
|
25
|
+
|
|
26
|
+
Portions of this package are distributed under the following copyright notice:
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
The MIT License (MIT)
|
|
30
|
+
|
|
31
|
+
Copyright (c) 2001-2014 Adam Hupp
|
|
32
|
+
|
|
33
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
34
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
35
|
+
in the Software without restriction, including without limitation the rights
|
|
36
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
37
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
38
|
+
furnished to do so, subject to the following conditions:
|
|
39
|
+
|
|
40
|
+
The above copyright notice and this permission notice shall be included in all
|
|
41
|
+
copies or substantial portions of the Software.
|
|
42
|
+
|
|
43
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
44
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
45
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
46
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
47
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
48
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
49
|
+
SOFTWARE.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
====
|
|
53
|
+
|
|
54
|
+
Portions of this package are distributed under the following copyright notice:
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
$File: LEGAL.NOTICE,v 1.15 2006/05/03 18:48:33 christos Exp $
|
|
58
|
+
Copyright (c) Ian F. Darwin 1986, 1987, 1989, 1990, 1991, 1992, 1994, 1995.
|
|
59
|
+
Software written by Ian F. Darwin and others;
|
|
60
|
+
maintained 1994- Christos Zoulas.
|
|
61
|
+
|
|
62
|
+
This software is not subject to any export provision of the United States
|
|
63
|
+
Department of Commerce, and may be exported to any country or planet.
|
|
64
|
+
|
|
65
|
+
Redistribution and use in source and binary forms, with or without
|
|
66
|
+
modification, are permitted provided that the following conditions
|
|
67
|
+
are met:
|
|
68
|
+
1. Redistributions of source code must retain the above copyright
|
|
69
|
+
notice immediately at the beginning of the file, without modification,
|
|
70
|
+
this list of conditions, and the following disclaimer.
|
|
71
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
72
|
+
notice, this list of conditions and the following disclaimer in the
|
|
73
|
+
documentation and/or other materials provided with the distribution.
|
|
74
|
+
|
|
75
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
76
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
77
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
78
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
79
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
80
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
81
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
82
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
83
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
84
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
85
|
+
SUCH DAMAGE.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: hermetic-python-magic
|
|
3
|
+
Version: 0.4.27
|
|
4
|
+
Summary: hermetic python-magic with bundled libmagic
|
|
5
|
+
License: The MIT License (MIT)
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2026 Tim Hörmann
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
====
|
|
29
|
+
|
|
30
|
+
Portions of this package are distributed under the following copyright notice:
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
The MIT License (MIT)
|
|
34
|
+
|
|
35
|
+
Copyright (c) 2001-2014 Adam Hupp
|
|
36
|
+
|
|
37
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
38
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
39
|
+
in the Software without restriction, including without limitation the rights
|
|
40
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
41
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
42
|
+
furnished to do so, subject to the following conditions:
|
|
43
|
+
|
|
44
|
+
The above copyright notice and this permission notice shall be included in all
|
|
45
|
+
copies or substantial portions of the Software.
|
|
46
|
+
|
|
47
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
48
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
49
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
50
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
51
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
52
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
53
|
+
SOFTWARE.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
====
|
|
57
|
+
|
|
58
|
+
Portions of this package are distributed under the following copyright notice:
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
$File: LEGAL.NOTICE,v 1.15 2006/05/03 18:48:33 christos Exp $
|
|
62
|
+
Copyright (c) Ian F. Darwin 1986, 1987, 1989, 1990, 1991, 1992, 1994, 1995.
|
|
63
|
+
Software written by Ian F. Darwin and others;
|
|
64
|
+
maintained 1994- Christos Zoulas.
|
|
65
|
+
|
|
66
|
+
This software is not subject to any export provision of the United States
|
|
67
|
+
Department of Commerce, and may be exported to any country or planet.
|
|
68
|
+
|
|
69
|
+
Redistribution and use in source and binary forms, with or without
|
|
70
|
+
modification, are permitted provided that the following conditions
|
|
71
|
+
are met:
|
|
72
|
+
1. Redistributions of source code must retain the above copyright
|
|
73
|
+
notice immediately at the beginning of the file, without modification,
|
|
74
|
+
this list of conditions, and the following disclaimer.
|
|
75
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
76
|
+
notice, this list of conditions and the following disclaimer in the
|
|
77
|
+
documentation and/or other materials provided with the distribution.
|
|
78
|
+
|
|
79
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
80
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
81
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
82
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
83
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
84
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
85
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
86
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
87
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
88
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
89
|
+
SUCH DAMAGE.
|
|
90
|
+
|
|
91
|
+
Requires-Python: >=3.10
|
|
92
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# hermetic-python-magic
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Replace python-magic's loader with our hermetic version."""
|
|
2
|
+
# ruff: noqa: INP001
|
|
3
|
+
|
|
4
|
+
import ctypes
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
PARENT = Path(__file__).parent
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def load_lib() -> ctypes.CDLL:
|
|
13
|
+
"""Load the bundled libmagic library."""
|
|
14
|
+
ext = ".dylib" if sys.platform == "darwin" else ".dll" if sys.platform == "win32" else ".so"
|
|
15
|
+
|
|
16
|
+
bundled_lib = PARENT.absolute() / f"libmagic{ext}"
|
|
17
|
+
bundled_mgc = PARENT.absolute() / "magic.mgc"
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
cdll = ctypes.CDLL(str(bundled_lib))
|
|
21
|
+
except OSError as e:
|
|
22
|
+
raise ImportError(
|
|
23
|
+
f"python-magic: failed to find libmagic. Check your installation: \n{e}"
|
|
24
|
+
) from e
|
|
25
|
+
|
|
26
|
+
if not os.getenv("MAGIC"):
|
|
27
|
+
os.environ["MAGIC"] = str(bundled_mgc)
|
|
28
|
+
|
|
29
|
+
return cdll
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Build standalone magic."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import shlex
|
|
9
|
+
import shutil
|
|
10
|
+
import subprocess
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import TYPE_CHECKING
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from collections.abc import Mapping, Sequence
|
|
17
|
+
|
|
18
|
+
from _typeshed import StrPath
|
|
19
|
+
from pdm.backend.hooks.base import Context
|
|
20
|
+
|
|
21
|
+
logger = logging.getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
PARENT = Path(__file__).parent
|
|
24
|
+
|
|
25
|
+
# FILE VERSION 5.47
|
|
26
|
+
FILE_COMMIT = "7d20612996567ecedec7f5c58f7bf15c2cf42c19"
|
|
27
|
+
# PYTHON-MAGIC VERSION 0.4.27
|
|
28
|
+
PYTHON_MAGIC_COMMIT = "b443195104d89363b93a547584c1a12fce3b57ec"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def run_sh(cmd: Sequence[str], cwd: StrPath, env: Mapping[str, str]) -> None:
|
|
32
|
+
"""Execute command."""
|
|
33
|
+
if sys.platform == "win32":
|
|
34
|
+
subprocess.check_call(["bash", "-c", shlex.join(cmd)], cwd=cwd, env=env) # noqa: S603,S607
|
|
35
|
+
else:
|
|
36
|
+
subprocess.check_call(cmd, cwd=cwd, env=env) # noqa: S603
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def pdm_build_initialize(context: Context) -> None:
|
|
40
|
+
"""Initialize PDM build by downloading source and building libmagic."""
|
|
41
|
+
if context.target == "sdist":
|
|
42
|
+
return
|
|
43
|
+
|
|
44
|
+
env = os.environ.copy()
|
|
45
|
+
root: Path = context.root
|
|
46
|
+
|
|
47
|
+
file_src = root / "file"
|
|
48
|
+
pm_src = root / "python-magic"
|
|
49
|
+
patches = root / "patches"
|
|
50
|
+
|
|
51
|
+
# clone source
|
|
52
|
+
run_sh(["git", "clone", "https://github.com/file/file"], cwd=root, env=env)
|
|
53
|
+
run_sh(["git", "reset", "--hard", FILE_COMMIT], cwd=file_src, env=env)
|
|
54
|
+
run_sh(["git", "clone", "https://github.com/ahupp/python-magic"], cwd=root, env=env)
|
|
55
|
+
run_sh(["git", "reset", "--hard", PYTHON_MAGIC_COMMIT], cwd=pm_src, env=env)
|
|
56
|
+
|
|
57
|
+
hermetic = root / "hermetic"
|
|
58
|
+
hermetic.mkdir(parents=True)
|
|
59
|
+
target_dir = hermetic / "magic"
|
|
60
|
+
|
|
61
|
+
shutil.copytree(pm_src / "magic", target_dir)
|
|
62
|
+
|
|
63
|
+
# manual fixes
|
|
64
|
+
for f in target_dir.iterdir():
|
|
65
|
+
if f.suffix in {".py", ".pyi"}:
|
|
66
|
+
content = f.read_text()
|
|
67
|
+
|
|
68
|
+
# replace `from magic import(...)`
|
|
69
|
+
content = re.sub(
|
|
70
|
+
r"^([>\s]+)from\s+magic\s+import([\s(])",
|
|
71
|
+
r"\1from hermetic.magic import\2",
|
|
72
|
+
content,
|
|
73
|
+
flags=re.MULTILINE,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# replace `import magic[,\s]`
|
|
77
|
+
content = re.sub(
|
|
78
|
+
r"^([>\s]+)import\s+magic([,\s])",
|
|
79
|
+
r"\1import hermetic.magic as magic\2",
|
|
80
|
+
content,
|
|
81
|
+
flags=re.MULTILINE,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
f.write_text(content)
|
|
85
|
+
|
|
86
|
+
# copy patches
|
|
87
|
+
for f in patches.iterdir():
|
|
88
|
+
target_path = target_dir / f.relative_to(patches)
|
|
89
|
+
target_path.parent.mkdir(parents=True, exist_ok=True)
|
|
90
|
+
shutil.copyfile(f, target_path)
|
|
91
|
+
|
|
92
|
+
# build libmagic
|
|
93
|
+
env["CFLAGS"] = env.get("CFLAGS", "") + " -fPIC"
|
|
94
|
+
|
|
95
|
+
# Windows lacks native POSIX regex. MSYS2 provides gnurx, so we must link it.
|
|
96
|
+
if sys.platform == "win32":
|
|
97
|
+
env["LDFLAGS"] = env.get("LDFLAGS", "") + " -lgnurx"
|
|
98
|
+
|
|
99
|
+
run_sh(["autoreconf", "-f", "-i"], cwd=file_src, env=env)
|
|
100
|
+
run_sh(["./configure", "--enable-shared", "--disable-static"], cwd=file_src, env=env)
|
|
101
|
+
run_sh(["make", "clean"], cwd=file_src, env=env)
|
|
102
|
+
run_sh(["make"], cwd=file_src, env=env)
|
|
103
|
+
|
|
104
|
+
ext = ".dylib" if sys.platform == "darwin" else ".dll" if sys.platform == "win32" else ".so"
|
|
105
|
+
libs_dir = file_src / "src" / ".libs"
|
|
106
|
+
found_lib: Path | None = None
|
|
107
|
+
|
|
108
|
+
for f in libs_dir.glob(f"*magic*{ext}*"):
|
|
109
|
+
if f.is_symlink():
|
|
110
|
+
continue # skip links
|
|
111
|
+
found_lib = f
|
|
112
|
+
break
|
|
113
|
+
|
|
114
|
+
if not found_lib:
|
|
115
|
+
raise RuntimeError(f"Failed to find built *magic*{ext}* in {libs_dir}")
|
|
116
|
+
|
|
117
|
+
# copy built libraries
|
|
118
|
+
dest_lib = target_dir / f"libmagic{ext}"
|
|
119
|
+
shutil.copyfile(found_lib, dest_lib)
|
|
120
|
+
dest_lib.chmod(0o755)
|
|
121
|
+
|
|
122
|
+
mgc_path = file_src / "magic" / "magic.mgc"
|
|
123
|
+
shutil.copyfile(mgc_path, target_dir / "magic.mgc")
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "hermetic-python-magic"
|
|
3
|
+
version = "0.4.27"
|
|
4
|
+
description = "hermetic python-magic with bundled libmagic"
|
|
5
|
+
requires-python = ">=3.10"
|
|
6
|
+
dependencies = []
|
|
7
|
+
|
|
8
|
+
[project.license]
|
|
9
|
+
file = "LICENSE"
|
|
10
|
+
|
|
11
|
+
[build-system]
|
|
12
|
+
requires = [
|
|
13
|
+
"pdm-backend",
|
|
14
|
+
]
|
|
15
|
+
build-backend = "pdm.backend"
|
|
16
|
+
|
|
17
|
+
[tool.pdm.build]
|
|
18
|
+
setup-script = "pdm_build.py"
|
|
19
|
+
is-purelib = false
|
|
20
|
+
includes = [
|
|
21
|
+
"hermetic/",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"README.md",
|
|
24
|
+
]
|
|
25
|
+
source-includes = [
|
|
26
|
+
"patches/",
|
|
27
|
+
]
|
|
28
|
+
excludes = [
|
|
29
|
+
".git/",
|
|
30
|
+
"**/.git/",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[tool.ruff]
|
|
34
|
+
line-length = 100
|
|
35
|
+
extend-exclude = [
|
|
36
|
+
"file",
|
|
37
|
+
"python-magic",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[tool.ruff.lint]
|
|
41
|
+
select = [
|
|
42
|
+
"ALL",
|
|
43
|
+
]
|
|
44
|
+
ignore = [
|
|
45
|
+
"D203",
|
|
46
|
+
"D211",
|
|
47
|
+
"D213",
|
|
48
|
+
"EM101",
|
|
49
|
+
"COM812",
|
|
50
|
+
"EM102",
|
|
51
|
+
"TRY003",
|
|
52
|
+
]
|