File: copy_typings_stubs_on_success.py

package info (click to toggle)
opencv 4.10.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 282,092 kB
  • sloc: cpp: 1,178,079; xml: 682,621; python: 49,092; lisp: 31,150; java: 25,469; ansic: 11,039; javascript: 6,085; sh: 1,214; cs: 601; perl: 494; objc: 210; makefile: 173
file content (45 lines) | stat: -rw-r--r-- 1,441 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import argparse
import warnings
import os
import sys

if sys.version_info >= (3, 8, ):
    # shutil.copytree received the `dirs_exist_ok` parameter
    from functools import partial
    import shutil

    copy_tree = partial(shutil.copytree, dirs_exist_ok=True)
else:
    from distutils.dir_util import copy_tree


def main():
    args = parse_arguments()
    py_typed_path = os.path.join(args.stubs_dir, 'py.typed')
    if not os.path.isfile(py_typed_path):
        warnings.warn(
            '{} is missing, it means that typings stubs generation is either '
            'failed or has been skipped. Ensure that Python 3.6+ is used for '
            'build and there is no warnings during Python source code '
            'generation phase.'.format(py_typed_path)
        )
        return
    copy_tree(args.stubs_dir, args.output_dir)


def parse_arguments():
    parser = argparse.ArgumentParser(
        description='Copies generated typing stubs only when generation '
        'succeeded. This is identified by presence of the `py.typed` file '
        'inside typing stubs directory.'
    )
    parser.add_argument('--stubs_dir', type=str,
                        help='Path to directory containing generated typing '
                        'stubs file')
    parser.add_argument('--output_dir', type=str,
                        help='Path to output directory')
    return parser.parse_args()


if __name__ == '__main__':
    main()