Add license to framework sdist builds#3002
Conversation
Signed-off-by: ksivamani <ksivamani@nvidia.com>
Greptile SummaryThis PR adds the repo-level
Confidence Score: 4/5Safe to merge; the change is purely additive build infrastructure with no impact on runtime library code. The core approach is sound. Two minor cleanup-reliability observations exist: the copy runs at module scope while the unlink is gated on main and specific argv values, and there is no try/finally around the cleanup sequence. Neither issue affects the distributed package contents. Both transformer_engine/jax/setup.py and transformer_engine/pytorch/setup.py carry identical cleanup patterns worth a second look. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[setup.py executed] --> B{license_src.is_file?}
B -- Yes --> C["shutil.copyfile(license_src, license_dst)\n(module scope)"]
B -- No --> D[No license copied]
C --> E["if __name__ == '__main__'"]
D --> E
E --> F["setuptools.setup(..., license_files=('LICENSE',))"]
F --> G{"sdist / bdist_wheel\nin sys.argv?"}
G -- Yes --> H[shutil.rmtree common_headers]
H --> I[shutil.rmtree build_tools]
I --> J{license_dst.is_file?}
J -- Yes --> K[license_dst.unlink]
J -- No --> L[Done]
K --> L
G -- No --> M["LICENSE left in framework dir\n(e.g. for 'install' or 'develop')"]
Reviews (1): Last reviewed commit: "Add license to framework sdist builds" | Re-trigger Greptile |
| if license_dst.is_file(): | ||
| license_dst.unlink() |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
Description
Add license to
transformer-engine-torchandtransformer-engine-jaxPyPI packages.Type of change
Changes
transformer-engine-torchandtransformer-engine-jaxPyPI packages.Checklist: