Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions transformer_engine/jax/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
shutil.rmtree(build_tools_copy)
shutil.copytree(build_tools_dir, build_tools_copy)

license_src = current_file_path.parent.parent / "LICENSE"
license_dst = current_file_path / "LICENSE"
if license_src.is_file():
shutil.copyfile(license_src, license_dst)
Comment on lines +45 to +48
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 License file copied at module scope, cleanup only in __main__

The shutil.copyfile call runs unconditionally at import time (module scope), while license_dst.unlink() only executes when __name__ == "__main__" and specific build commands are in sys.argv. If any tooling inspects or imports this file without running it as __main__ (e.g., certain PEP 517 build-backend introspection steps), the LICENSE file will be copied to the framework source directory and never removed. Placing the copy inside the if __name__ == "__main__": block — mirroring how common_headers_dir is handled — would keep the lifecycle symmetric. The same issue is present in transformer_engine/pytorch/setup.py.



from build_tools.build_ext import get_build_ext
from build_tools.utils import copy_common_headers, min_python_version_str
Expand Down Expand Up @@ -131,7 +136,10 @@ def get_cuda_major_version() -> int:
python_requires=f">={min_python_version_str()}",
install_requires=install_requires,
tests_require=test_requirements(),
license_files=("LICENSE",),
)
if any(x in sys.argv for x in (".", "sdist", "bdist_wheel")):
shutil.rmtree(common_headers_dir)
shutil.rmtree("build_tools")
if license_dst.is_file():
license_dst.unlink()
Comment on lines +144 to +145
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Cleanup may be skipped on exception

shutil.rmtree("build_tools") runs before license_dst.unlink() with no error handling between them. If the rmtree call raises (e.g., the directory was never created because NVTE_RELEASE_BUILD was unset and build_tools_dir didn't exist), the unlink never runs and transformer_engine/jax/LICENSE is left behind in the source tree. A try/finally block would make cleanup reliable regardless of intermediate failures. The same pattern applies to transformer_engine/pytorch/setup.py.

8 changes: 8 additions & 0 deletions transformer_engine/pytorch/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
shutil.rmtree(build_tools_copy)
shutil.copytree(build_tools_dir, build_tools_copy)

license_src = current_file_path.parent.parent / "LICENSE"
license_dst = current_file_path / "LICENSE"
if license_src.is_file():
shutil.copyfile(license_src, license_dst)


from build_tools.build_ext import get_build_ext
from build_tools.utils import copy_common_headers, min_python_version_str
Expand Down Expand Up @@ -177,7 +182,10 @@ def run(self):
python_requires=f">={min_python_version_str()}",
install_requires=install_requires,
tests_require=test_requirements(),
license_files=("LICENSE",),
)
if any(x in sys.argv for x in (".", "sdist", "bdist_wheel")):
shutil.rmtree(common_headers_dir)
shutil.rmtree("build_tools")
if license_dst.is_file():
license_dst.unlink()
Loading