Debian Codegraph @

tools/wheels/check_license.py

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 #!/usr/bin/python3
2 """
3 check_license.py [MODULE]
4
5 Check the presence of a LICENSE.txt in the installed module directory,
6 and that it appears to contain text prevalent for a scikit-misc binary
7 distribution.
8
9 """
10 import argparse
11 import io
12 import re
13 import sys
14 from pathlib import Path
15
16
17 def check_text(text):
18 ok = "Copyright (c)" in text and re.search(
19 r"This binary distribution of \w+ also bundles the following software",
20 text,
21 re.IGNORECASE
22 )
23 return ok
24
25
26 def main():
27 p = argparse.ArgumentParser(usage=__doc__.rstrip())
28 p.add_argument("module", nargs="?", default="skmisc")
29 args = p.parse_args()
30
31 # Drop '' from sys.path
32 sys.path.pop(0)
33
34 # Find module path
35 __import__(args.module)
36 mod = sys.modules[args.module]
37
38 # Check license text
39 module_file = Path(mod.__file__) # type: ignore
40 license_txt = module_file.parent / "LICENSE.txt"
41 with io.open(license_txt, "r", encoding="utf-8") as f:
42 text = f.read()
43
44 ok = check_text(text)
45 if not ok:
46 print(
47 "ERROR: License text {} does not contain expected "
48 "text fragments\n".format(license_txt)
49 )
50 print(text)
51 sys.exit(1)
52
53 sys.exit(0)
54
55
56 if __name__ == "__main__":
57 main()