Ctx mgr to ensure destuction of container-pip-deps.txt

The file container-pip-dependencies.txt was being left a directory when
building the docker image. This meant that it was being packaged when it
wasn't supposed to.

To avoid this, we remove file with the help from a context manager.

The change is minimal and the biggest part of the diff are indentation
changes.

Fixes #739
This commit is contained in:
deeplow 2024-03-04 13:44:32 +00:00
parent 4f08f99e93
commit 297feab63d
No known key found for this signature in database
GPG key ID: 577982871529A52A

View file

@ -31,8 +31,7 @@ def main():
args = parser.parse_args()
print("Exporting container pip dependencies")
export_container_pip_dependencies()
with ContainerPipDependencies():
print("Pulling base image")
subprocess.run(
[
@ -97,7 +96,10 @@ def main():
f.write(image_id)
def export_container_pip_dependencies():
class ContainerPipDependencies:
"""Generates PIP dependencies within container"""
def __enter__(self):
try:
container_requirements_txt = subprocess.check_output(
["poetry", "export", "--only", "container"], universal_newlines=True
@ -110,6 +112,10 @@ def export_container_pip_dependencies():
with open(Path(BUILD_CONTEXT) / REQUIREMENTS_TXT, "w") as f:
f.write(req_txt_pymupdfb_stripped)
def __exit__(self, exc_type, exc_value, exc_tb):
print("Leaving the context...")
os.remove(Path(BUILD_CONTEXT) / REQUIREMENTS_TXT)
if __name__ == "__main__":
sys.exit(main())