-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If any dependencies had variants based on the platform then the wrong requirements would be rendered out. For example, if I used Chassis on a Windows machine and one of the dependencies had a variant that used the `win32` APIs, then the generated `requirements.txt` would include those packages which would not work when they were installed during the Docker build. Now the dependencies are generated in the same environment that they will be installed in and the `pip compile` and dependency normalization happens in a new pre-stage of the Docker build process.
- Loading branch information
Showing
3 changed files
with
65 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/chassisml/src/chassis/scripts/normalize_requirements.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
|
||
""" | ||
A list of pip requirements that are modified when writing out the container's | ||
`requirements.txt`. | ||
Items in this list are primarily to ensure that large packages that have a | ||
headless variant use the headless variant since the container doesn't use a | ||
display. | ||
""" | ||
REQUIREMENTS_SUBSTITUTIONS = { | ||
"opencv-python=": "opencv-python-headless=" | ||
} | ||
|
||
requirements_txt = "requirements.txt" | ||
|
||
# Post-process the full requirements.txt with automatic replacements. | ||
with open(requirements_txt, "rb") as f: | ||
reqs = f.read().decode() | ||
for old, new in REQUIREMENTS_SUBSTITUTIONS.items(): | ||
reqs = reqs.replace(old, new) | ||
if "torch" in reqs and not os.getenv("GPU").strip() == "true": | ||
reqs = "--extra-index-url https://download.pytorch.org/whl/cpu\n\n" + reqs | ||
with open(requirements_txt, "wb") as f: | ||
f.write(reqs.encode()) |