Fix torch.hub (fixes #2756) (#2762)

Summary:
Typically `torch.hub.load(...)` doesn't call `pip install`, so our Cython components never get built. We have a hack in our hubconf that builds these components by running the equivalent of `python setup.py build_ext --inplace` using the setuptools sandbox: f6677b6755/hubconf.py (L52-L55).

Unfortunately, this sandbox gets mad if you modify the filesystem, which is what this recent change does: f6677b6755/setup.py (L203-L205). Combined this breaks torch.hub.

The solution is that when we're doing `build_ext`, don't setup the symlinks. This is fine, since `build_ext` doesn't actually build a package, so we don't care about including config or examples.

Pull Request resolved: https://github.com/pytorch/fairseq/pull/2762

Reviewed By: alexeib

Differential Revision: D24430228

Pulled By: myleott

fbshipit-source-id: e05d075a003ddfde196cb8a86b32882d73808015
This commit is contained in:
Myle Ott 2020-10-20 15:43:36 -07:00 committed by Facebook GitHub Bot
parent d6f2c907be
commit 9b0611e678

View File

@ -201,12 +201,14 @@ def get_files(path, relative_to="fairseq"):
try:
# symlink config and examples into fairseq package so package_data accepts them
os.symlink(os.path.join("..", "config"), "fairseq/config")
os.symlink(os.path.join("..", "examples"), "fairseq/examples")
if "build_ext" not in sys.argv[1:]:
os.symlink(os.path.join("..", "config"), "fairseq/config")
os.symlink(os.path.join("..", "examples"), "fairseq/examples")
package_data = {
"fairseq": get_files("fairseq/config") + get_files("fairseq/examples"),
}
do_setup(package_data)
finally:
os.unlink("fairseq/config")
os.unlink("fairseq/examples")
if "build_ext" not in sys.argv[1:]:
os.unlink("fairseq/config")
os.unlink("fairseq/examples")