in usort/config.py [0:0]
def with_first_party(self, filename: Path) -> "Config":
"""
Infer first-party top-level names; this only works for the common case of
a single package, but not multiple, or modules (pure-python or extensions).
In those cases, you should explicitly set `known_first_party` in the config.
This code as-is should work for something like running against a site-packages
dir, but if we broaden to support multiple top-level names, it would find too
much.
To disable this code entirely, set `first_party_detection=false` in the config.
"""
p = filename
while True:
# Stop on root (hopefully works on Windows)
if p.parent == p:
break
# Stop on different volume
if p.exists() and p.stat().st_dev != p.parent.stat().st_dev:
break
if (p.parent / "__init__.py").exists():
p = p.parent
else:
break
if (p / "__init__.py").exists():
self.known[p.name] = CAT_FIRST_PARTY
return self