Skip to content

Commit

Permalink
Fix new mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kislyuk committed Aug 4, 2024
1 parent 932a28e commit 380acbb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion argcomplete/scripts/activate_global_python_argcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def install_to_destination(dest):


def get_consent():
assert args is not None
if args.yes is True:
return True
while True:
Expand Down Expand Up @@ -140,7 +141,7 @@ def main():
if args.dest != "-" and not os.path.exists(args.dest):
parser.error(f"directory {args.dest} was specified via --dest, but it does not exist")
destinations.append(args.dest)
elif site.ENABLE_USER_SITE and site.USER_SITE in argcomplete.__file__:
elif site.ENABLE_USER_SITE and site.USER_SITE and site.USER_SITE in argcomplete.__file__:
print(
"Argcomplete was installed in the user site local directory. Defaulting to user installation.", file=sys.stderr
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,43 @@ def main():
if line.startswith("# EASY-INSTALL-SCRIPT"):
import pkg_resources

dist, script = re.match("# EASY-INSTALL-SCRIPT: '(.+)','(.+)'", line).groups()
re_match = re.match("# EASY-INSTALL-SCRIPT: '(.+)','(.+)'", line)
assert re_match is not None
dist, script = re_match.groups()
if "PYTHON_ARGCOMPLETE_OK" in pkg_resources.get_distribution(dist).get_metadata("scripts/" + script):
return 0
elif line.startswith("# EASY-INSTALL-ENTRY-SCRIPT"):
dist, group, name = re.match("# EASY-INSTALL-ENTRY-SCRIPT: '(.+)','(.+)','(.+)'", line).groups()
re_match = re.match("# EASY-INSTALL-ENTRY-SCRIPT: '(.+)','(.+)','(.+)'", line)
assert re_match is not None
dist, group, name = re_match.groups()
import pkgutil

import pkg_resources

module_name = pkg_resources.get_distribution(dist).get_entry_info(group, name).module_name
with open(pkgutil.get_loader(module_name).get_filename()) as mod_fh:
entry_point_info = pkg_resources.get_distribution(dist).get_entry_info(group, name)
assert entry_point_info is not None
module_name = entry_point_info.module_name
with open(pkgutil.get_loader(module_name).get_filename()) as mod_fh: # type: ignore
if "PYTHON_ARGCOMPLETE_OK" in mod_fh.read(1024):
return 0
elif line.startswith("# EASY-INSTALL-DEV-SCRIPT"):
for line2 in lines:
if line2.startswith("__file__"):
filename = re.match("__file__ = '(.+)'", line2).group(1)
re_match = re.match("__file__ = '(.+)'", line2)
assert re_match is not None
filename = re_match.group(1)
with open(filename) as mod_fh:
if "PYTHON_ARGCOMPLETE_OK" in mod_fh.read(1024):
return 0
elif line.startswith("# PBR Generated"):
module = re.search("from (.*) import", head).groups()[0]
re_match = re.search("from (.*) import", head)
assert re_match is not None
module = re_match.groups()[0]
import pkgutil

import pkg_resources

with open(pkgutil.get_loader(module).get_filename()) as mod_fh:
with open(pkgutil.get_loader(module).get_filename()) as mod_fh: # type: ignore
if "PYTHON_ARGCOMPLETE_OK" in mod_fh.read(1024):
return 0

Expand Down

0 comments on commit 380acbb

Please sign in to comment.