Huiran Yu commited on
Commit
41f1d72
·
1 Parent(s): a069413
Files changed (1) hide show
  1. patch_madmom.py +10 -12
patch_madmom.py CHANGED
@@ -5,6 +5,14 @@ from pathlib import Path
5
 
6
  FUTURE_LINE = "from __future__ import absolute_import, division, print_function"
7
 
 
 
 
 
 
 
 
 
8
  def find_madmom_root() -> Path:
9
  for p in site.getsitepackages():
10
  cand = Path(p) / "madmom"
@@ -25,28 +33,18 @@ def patch_processors(madmom_root: Path) -> None:
25
  proc.write_text(s2, encoding="utf-8")
26
 
27
  def patch_numpy_aliases(madmom_root: Path) -> None:
28
- repls = [
29
- ("np.float", "float"),
30
- ("np.int", "int"),
31
- ("np.bool", "bool"),
32
- ("np.object", "object"),
33
- ]
34
-
35
  patched = 0
36
  for f in madmom_root.rglob("*.py"):
37
  try:
38
  s = f.read_text(encoding="utf-8")
39
  except Exception:
40
  continue
41
-
42
  s2 = s
43
- for a, b in repls:
44
- s2 = s2.replace(a, b)
45
-
46
  if s2 != s:
47
  f.write_text(s2, encoding="utf-8")
48
  patched += 1
49
-
50
  print(f"Patched NumPy aliases in {patched} madmom files")
51
 
52
  def patch_utils_future_safe(madmom_root: Path) -> None:
 
5
 
6
  FUTURE_LINE = "from __future__ import absolute_import, division, print_function"
7
 
8
+ ALIASES = [
9
+ (re.compile(r"\bnp\.float\b"), "float"),
10
+ (re.compile(r"\bnp\.int\b"), "int"),
11
+ (re.compile(r"\bnp\.bool\b"), "bool"),
12
+ (re.compile(r"\bnp\.object\b"), "object"),
13
+ (re.compile(r"\bnp\.complex\b"), "complex"),
14
+ ]
15
+
16
  def find_madmom_root() -> Path:
17
  for p in site.getsitepackages():
18
  cand = Path(p) / "madmom"
 
33
  proc.write_text(s2, encoding="utf-8")
34
 
35
  def patch_numpy_aliases(madmom_root: Path) -> None:
 
 
 
 
 
 
 
36
  patched = 0
37
  for f in madmom_root.rglob("*.py"):
38
  try:
39
  s = f.read_text(encoding="utf-8")
40
  except Exception:
41
  continue
 
42
  s2 = s
43
+ for pat, repl in ALIASES:
44
+ s2 = pat.sub(repl, s2)
 
45
  if s2 != s:
46
  f.write_text(s2, encoding="utf-8")
47
  patched += 1
 
48
  print(f"Patched NumPy aliases in {patched} madmom files")
49
 
50
  def patch_utils_future_safe(madmom_root: Path) -> None: