util.py 577 B

1234567891011121314151617
  1. # Copyright (c) 2016, 2018 Claudiu Popa <pcmanticore@gmail.com>
  2. # Copyright (c) 2021 Pierre Sassoulas <pierre.sassoulas@gmail.com>
  3. # Copyright (c) 2021 Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
  4. # Copyright (c) 2021 Neil Girdhar <mistersheik@gmail.com>
  5. try:
  6. import pkg_resources
  7. except ImportError:
  8. pkg_resources = None # type: ignore[assignment]
  9. def is_namespace(modname):
  10. return (
  11. pkg_resources is not None
  12. and hasattr(pkg_resources, "_namespace_packages")
  13. and modname in pkg_resources._namespace_packages
  14. )