We have some internal Python packages with the same names as packages on PyPI---say package1, package2, and package3. Occasionally some users install the PyPI versions by mistake, so I'm wondering if there's a standard way to verify they've installed the correct package.
My current idea is in our package0, which does not conflict with PyPI, but does import package1, package2, and package3, to do something like:
# package0.__init__.py
import package1
import package2
import package2
for pkg in [package1, package2, package3]:
try:
assert "our-organization" in pkg.__url__
except (AttributeError, AssertionError) as exc:
raise ImportError(
f"An incorrect version of {module.__name__} was detected. "
"Please ensure you have installed correct internal version and not "
f"a package on PyPI with the same name. ({exc})"
)
Of course, this only works if they load package0, and not if they load package1 directly in say a jupyter notebook or something.
I would suggest using
importlib.metadatato introspect the metadata of the installed packages. You could check for some specific value in the metadata, one of the URLs for example (as you suggest in your question), or a trove classifier maybe (the ones prefixed withPrivate ::might be good candidates since no such trove classifier can ever be on PyPI), or a combination of multiple metadata values.