mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
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:
parent
4f08f99e93
commit
297feab63d
1 changed files with 63 additions and 57 deletions
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue