comparison env/bin/python-argcomplete-check-easy-install-script @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 #!/Users/cmdms/OneDrive-UOB/Development/Projects/2021/sam-consensus-v3/env/bin/python3
2
3 # Copyright 2012-2019, Andrey Kislyuk and argcomplete contributors.
4 # Licensed under the Apache License. See https://github.com/kislyuk/argcomplete for more info.
5
6 '''
7 This script is part of the Python argcomplete package (https://github.com/kislyuk/argcomplete).
8 It is used to check if an EASY-INSTALL-SCRIPT wrapper redirects to a script that contains the string
9 "PYTHON_ARGCOMPLETE_OK". If you have enabled global completion in argcomplete, the completion hook will run it every
10 time you press <TAB> in your shell.
11
12 Usage:
13 python-argcomplete-check-easy-install-script <input executable file>
14 '''
15
16 import sys
17
18 if len(sys.argv) != 2:
19 sys.exit(__doc__)
20
21 sys.tracebacklimit = 0
22
23 with open(sys.argv[1]) as fh:
24 line1, head = fh.read(1024).split("\n", 1)[:2]
25 if line1.startswith('#') and ('py' in line1 or 'Py' in line1):
26 import re
27 lines = head.split("\n", 12)
28 for line in lines:
29 if line.startswith("# EASY-INSTALL-SCRIPT"):
30 import pkg_resources
31 dist, script = re.match("# EASY-INSTALL-SCRIPT: '(.+)','(.+)'", line).groups()
32 if "PYTHON_ARGCOMPLETE_OK" in pkg_resources.get_distribution(dist).get_metadata('scripts/' + script):
33 exit(0)
34 elif line.startswith("# EASY-INSTALL-ENTRY-SCRIPT"):
35 dist, group, name = re.match("# EASY-INSTALL-ENTRY-SCRIPT: '(.+)','(.+)','(.+)'", line).groups()
36 import pkg_resources, pkgutil
37 module_name = pkg_resources.get_distribution(dist).get_entry_info(group, name).module_name
38 with open(pkgutil.get_loader(module_name).get_filename()) as mod_fh:
39 if "PYTHON_ARGCOMPLETE_OK" in mod_fh.read(1024):
40 exit(0)
41 elif line.startswith("# EASY-INSTALL-DEV-SCRIPT"):
42 for line2 in lines:
43 if line2.startswith('__file__'):
44 filename = re.match("__file__ = '(.+)'", line2).group(1)
45 with open(filename) as mod_fh:
46 if "PYTHON_ARGCOMPLETE_OK" in mod_fh.read(1024):
47 exit(0)
48 elif line.startswith("# PBR Generated"):
49 module = re.search("from (.*) import", head).groups()[0]
50 import pkg_resources, pkgutil
51 with open(pkgutil.get_loader(module).get_filename()) as mod_fh:
52 if "PYTHON_ARGCOMPLETE_OK" in mod_fh.read(1024):
53 exit(0)
54
55 exit(1)