poetry-plugin-export
poetry-plugin-export copied to clipboard
poetry export -f requirements.txt -o requirements.txt --without-hashes --tree --size
Motivation: I am building a docker image using script: https://github.com/tchaton/sagemaker-torch-template
from jinja2 import Template
CMD = "RUN pip install "
requirements = []
with open("requirements.txt") as file_:
for l in file_:
if ';' in l:
requirements.append(CMD + l.split(';')[0] + '\n')
else:
requirements.append(CMD + l)
with open("docker_template.jinja2") as file_:
template = Template(file_.read())
rendered = template.render(requirements=''.join(requirements))
with open("Dockerfile", "w") as file_:
file_.write(rendered)
I noticed it was faster to build and push when each RUN pip install {{package}} as its own line.
However, the dependencies generated by poetry are ordered by alphabetical order.
I think we could have more options here as a --tree, --size, --date
- --tree options. By ordering packages using hierarchical tree dependencies (c.f poetry show --tree), so it will reduce layers probability to be uncached if new package are added.
- Add a --size. Order parent package by size, so heavier ones are deeper.
- Add a --date. Order parent package by added date to poetry
- [ ] I have searched the issues of this repo and believe that this is not a duplicate.
- [ ] I have searched the documentation and believe that my question is not covered.