Skip to content

Commit

Permalink
fix: Try to fix the temp file issue on Windows machines
Browse files Browse the repository at this point in the history
Signed-off-by: Mostafa Moradian <mostafamoradian0@gmail.com>
  • Loading branch information
mostafa committed Mar 9, 2022
1 parent 4be30e2 commit 684d4f0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cyclonedx_py/parser/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) OWASP Foundation. All Rights Reserved.

import os
import os.path
from tempfile import NamedTemporaryFile, _TemporaryFileWrapper # Weak error
from typing import Any, Optional
Expand All @@ -41,9 +42,9 @@ def __init__(self, requirements_content: str) -> None:
parsed_rf = RequirementsFile.from_file(
requirements_content, include_nested=True)
else:
requirements_file = NamedTemporaryFile(mode='w+', delete=True)
requirements_file = NamedTemporaryFile(mode='w+', delete=False)
requirements_file.write(requirements_content)
requirements_file.seek(0)
requirements_file.close()

parsed_rf = RequirementsFile.from_file(
requirements_file.name, include_nested=False)
Expand Down Expand Up @@ -73,7 +74,7 @@ def __init__(self, requirements_content: str) -> None:
))

if requirements_file:
requirements_file.close()
os.unlink(requirements_file.name)


class RequirementsFileParser(RequirementsParser):
Expand Down

0 comments on commit 684d4f0

Please sign in to comment.