Skip to content

Commit

Permalink
Fix 'cpp_lib.json' file creation and installation
Browse files Browse the repository at this point in the history
ghstack-source-id: 88885d4d1d96ea7e452c7cbe46d6b24383be047b
Pull Request resolved: https://github.com/fairinternal/xformers/pull/426

__original_commit__ = fairinternal/xformers@c5776a283a60df6507f763fa01134cd799b80df0
  • Loading branch information
danthe3rd authored and xFormers Bot committed Jan 13, 2023
1 parent 217b111 commit 6a988dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ install_repo: &install_repo
# Test import.
$CONDA_PYTHON -c 'import sys; sys.path = sys.path[1:]; import xformers'
ls xformers
$CONDA_PYTHON -m xformers.info
install_experimental_repo: &install_experimental_repo
Expand Down
21 changes: 17 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,29 @@ def run(self):
class BuildExtensionWithMetadata(BuildExtension):
def __init__(self, *args, **kwargs) -> None:
self.xformers_build_metadata = kwargs.pop("xformers_build_metadata")
self.pkg_name = "xformers"
self.metadata_json = "cpp_lib.json"
super().__init__(*args, **kwargs)

def build_extensions(self) -> None:
super().build_extensions()
metadata_json = os.path.join(this_dir, "xformers", "cpp_lib.json")
with open(metadata_json, "w+") as fp:
with open(
os.path.join(self.build_lib, self.pkg_name, self.metadata_json), "w+"
) as fp:
json.dump(self.xformers_build_metadata, fp)

def copy_extensions_to_source(self):
"""
Used for `pip install -e .`
Copies everything we built back into the source repo
"""
build_py = self.get_finalized_command("build_py")
package_dir = build_py.get_package_dir(self.pkg_name)
inplace_file = os.path.join(package_dir, self.metadata_json)
regular_file = os.path.join(self.build_lib, self.pkg_name, self.metadata_json)
self.copy_file(regular_file, inplace_file, level=self.verbose)
super().copy_extensions_to_source()


if __name__ == "__main__":

Expand Down Expand Up @@ -360,8 +375,6 @@ def build_extensions(self) -> None:
),
"clean": clean,
},
data_files=[("xformers", ["xformers/cpp_lib.json"])],
include_package_data=True,
url="https://facebookresearch.github.io/xformers/",
python_requires=">=3.7",
author="Facebook AI Research",
Expand Down

0 comments on commit 6a988dd

Please sign in to comment.