Huiran Yu commited on
Commit
8129c83
·
1 Parent(s): ea8b7ec

patch madmom

Browse files
Files changed (1) hide show
  1. Dockerfile +65 -21
Dockerfile CHANGED
@@ -25,6 +25,7 @@ RUN pip install --no-cache-dir --no-build-isolation madmom
25
  RUN python - <<'PY'
26
  import site, pathlib, re
27
 
 
28
  pkg_root = None
29
  for p in site.getsitepackages():
30
  cand = pathlib.Path(p) / "madmom"
@@ -34,32 +35,75 @@ for p in site.getsitepackages():
34
  if pkg_root is None:
35
  raise SystemExit("madmom package not found")
36
 
37
- repls = [
38
- ("from collections import MutableSequence", "from collections.abc import MutableSequence"),
39
- ("np.float", "float"), # or "np.float64"
40
- ("np.int", "int"),
41
- ("np.bool", "bool"),
42
- ("np.object", "object"),
43
- ]
44
-
45
- patched = 0
46
- for f in pkg_root.rglob("*.py"):
47
- try:
48
- s = f.read_text(encoding="utf-8")
49
- except Exception:
50
- continue
51
- s2 = s
52
- for a, b in repls:
53
- s2 = s2.replace(a, b)
54
  if s2 != s:
55
- f.write_text(s2, encoding="utf-8")
56
- patched += 1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
- print(f"Patched {patched} madmom files under {pkg_root}")
 
59
  PY
60
 
61
 
62
- RUN python -c "import setuptools, pkg_resources; print('setuptools OK')"
63
 
64
  # Copy the rest of the repo
65
  COPY . /app
 
25
  RUN python - <<'PY'
26
  import site, pathlib, re
27
 
28
+ # locate madmom package
29
  pkg_root = None
30
  for p in site.getsitepackages():
31
  cand = pathlib.Path(p) / "madmom"
 
35
  if pkg_root is None:
36
  raise SystemExit("madmom package not found")
37
 
38
+ # 1) Fix processors.py: MutableSequence import for py3.10+
39
+ proc = pkg_root / "processors.py"
40
+ if proc.exists():
41
+ s = proc.read_text(encoding="utf-8")
42
+ s2 = s.replace("from collections import MutableSequence",
43
+ "from collections.abc import MutableSequence")
 
 
 
 
 
 
 
 
 
 
 
44
  if s2 != s:
45
+ proc.write_text(s2, encoding="utf-8")
46
+ print("Patched", proc)
47
+
48
+ # 2) Fix numpy aliases if present (np.float etc.)
49
+ for f in [pkg_root / "io" / "__init__.py"]:
50
+ if f.exists():
51
+ s = f.read_text(encoding="utf-8")
52
+ s2 = (s.replace("np.float", "float")
53
+ .replace("np.int", "int")
54
+ .replace("np.bool", "bool")
55
+ .replace("np.object", "object"))
56
+ if s2 != s:
57
+ f.write_text(s2, encoding="utf-8")
58
+ print("Patched", f)
59
+
60
+ # 3) Fix Python2 type names in madmom/utils/__init__.py
61
+ u = pkg_root / "utils" / "__init__.py"
62
+ if not u.exists():
63
+ raise SystemExit("madmom/utils/__init__.py not found")
64
+
65
+ s = u.read_text(encoding="utf-8")
66
+
67
+ # Inject compatibility definitions near the top (after imports)
68
+ # We'll add them right after the first import block.
69
+ lines = s.splitlines(True)
70
+ insert_at = 0
71
+ for i, line in enumerate(lines):
72
+ # after the last consecutive import line at the top
73
+ if line.startswith("import ") or line.startswith("from "):
74
+ insert_at = i + 1
75
+ elif i > 0:
76
+ break
77
+
78
+ compat = """
79
+ # --- Compatibility for Python 3 ---
80
+ try:
81
+ basestring
82
+ except NameError:
83
+ basestring = str
84
+
85
+ try:
86
+ integer
87
+ except NameError:
88
+ integer = int
89
+ # ---------------------------------
90
+ """
91
+
92
+ # Only insert if not already present
93
+ if "basestring = str" not in s:
94
+ lines.insert(insert_at, compat)
95
+ s = "".join(lines)
96
+
97
+ # Ensure string_types / integer_types are well-defined even if old code is weird
98
+ s = re.sub(r"string_types\s*=\s*basestring", "string_types = (str,)", s)
99
+ s = re.sub(r"integer_types\s*=\s*\(int,\s*integer\)", "integer_types = (int,)", s)
100
 
101
+ u.write_text(s, encoding="utf-8")
102
+ print("Patched", u)
103
  PY
104
 
105
 
106
+ RUN python -c "import madmom; print('madmom import OK')"
107
 
108
  # Copy the rest of the repo
109
  COPY . /app