muff 0.12.11__py3-none-win_amd64.whl

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.
muff/__init__.py ADDED
File without changes
muff/__main__.py ADDED
@@ -0,0 +1,88 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import sys
5
+ import sysconfig
6
+
7
+
8
+ def find_muff_bin() -> str:
9
+ """Return the muff binary path."""
10
+
11
+ muff_exe = "muff" + sysconfig.get_config_var("EXE")
12
+
13
+ scripts_path = os.path.join(sysconfig.get_path("scripts"), muff_exe)
14
+ if os.path.isfile(scripts_path):
15
+ return scripts_path
16
+
17
+ if sys.version_info >= (3, 10):
18
+ user_scheme = sysconfig.get_preferred_scheme("user")
19
+ elif os.name == "nt":
20
+ user_scheme = "nt_user"
21
+ elif sys.platform == "darwin" and sys._framework:
22
+ user_scheme = "osx_framework_user"
23
+ else:
24
+ user_scheme = "posix_user"
25
+
26
+ user_path = os.path.join(
27
+ sysconfig.get_path("scripts", scheme=user_scheme), muff_exe
28
+ )
29
+ if os.path.isfile(user_path):
30
+ return user_path
31
+
32
+ # Search in `bin` adjacent to package root (as created by `pip install --target`).
33
+ pkg_root = os.path.dirname(os.path.dirname(__file__))
34
+ target_path = os.path.join(pkg_root, "bin", muff_exe)
35
+ if os.path.isfile(target_path):
36
+ return target_path
37
+
38
+ # Search for pip-specific build environments.
39
+ #
40
+ # Expect to find muff in <prefix>/pip-build-env-<rand>/overlay/bin/muff
41
+ # Expect to find a "normal" folder at <prefix>/pip-build-env-<rand>/normal
42
+ #
43
+ # See: https://github.com/pypa/pip/blob/102d8187a1f5a4cd5de7a549fd8a9af34e89a54f/src/pip/_internal/build_env.py#L87
44
+ paths = os.environ.get("PATH", "").split(os.pathsep)
45
+ if len(paths) >= 2:
46
+
47
+ def get_last_three_path_parts(path: str) -> list[str]:
48
+ """Return a list of up to the last three parts of a path."""
49
+ parts = []
50
+
51
+ while len(parts) < 3:
52
+ head, tail = os.path.split(path)
53
+ if tail or head != path:
54
+ parts.append(tail)
55
+ path = head
56
+ else:
57
+ parts.append(path)
58
+ break
59
+
60
+ return parts
61
+
62
+ maybe_overlay = get_last_three_path_parts(paths[0])
63
+ maybe_normal = get_last_three_path_parts(paths[1])
64
+ if (
65
+ len(maybe_normal) >= 3
66
+ and maybe_normal[-1].startswith("pip-build-env-")
67
+ and maybe_normal[-2] == "normal"
68
+ and len(maybe_overlay) >= 3
69
+ and maybe_overlay[-1].startswith("pip-build-env-")
70
+ and maybe_overlay[-2] == "overlay"
71
+ ):
72
+ # The overlay must contain the muff binary.
73
+ candidate = os.path.join(paths[0], muff_exe)
74
+ if os.path.isfile(candidate):
75
+ return candidate
76
+
77
+ raise FileNotFoundError(scripts_path)
78
+
79
+
80
+ if __name__ == "__main__":
81
+ muff = find_muff_bin()
82
+ if sys.platform == "win32":
83
+ import subprocess
84
+
85
+ completed_process = subprocess.run([muff, *sys.argv[1:]])
86
+ sys.exit(completed_process.returncode)
87
+ else:
88
+ os.execvp(muff, [muff, *sys.argv[1:]])
Binary file