Skip to content

Commit

Permalink
Add missing __init__.py files for editable PARs
Browse files Browse the repository at this point in the history
Summary:
As per when building the full wheel, make sure we fill in missing
`__init__.py` files.

Reviewed By: asp2insp

Differential Revision: D69825146

fbshipit-source-id: 80084843db8f2132e6c76b789646754fc5b69da9
  • Loading branch information
andrewjcg authored and facebook-github-bot committed Feb 20, 2025
1 parent 89d99b8 commit c7e8e4d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions prelude/python/tools/create_link_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import argparse
import json
import os
from typing import Set


def main() -> None:
Expand All @@ -20,14 +21,36 @@ def main() -> None:

os.makedirs(args.output)

pkgs: Set[str] = set()
pkgs_with_init: Set[str] = set()

def _add_pkg(pkg: str) -> None:
pkgs.add(pkg)
parent = os.path.dirname(pkg)
if parent:
_add_pkg(parent)

for manifest in args.manifests:
with open(manifest, "r") as f:
for dst, src, _ in json.load(f):
# Record pkgs and the ones w/ `__init__.py` files already.
if dst.endswith((".py", ".so")):
pkg = os.path.dirname(dst)
_add_pkg(pkg)
if os.path.basename(dst) == "__init__.py":
pkgs_with_init.add(pkg)

# Create symlink.
dst = os.path.join(args.output, dst)
os.makedirs(os.path.dirname(dst), exist_ok=True)
src = os.path.relpath(src, start=os.path.dirname(dst))
os.symlink(src, dst)

# Create any missing ones.
for pkg in pkgs - pkgs_with_init:
with open(os.path.join(pkg, "__init__.py"), "wb") as _:
pass


if __name__ == "__main__":
main()

0 comments on commit c7e8e4d

Please sign in to comment.