Skip to content

Conversation

@rng70
Copy link

@rng70 rng70 commented Jun 27, 2024

when pip-requirements-parser package is used to parse the requirements from the string using the RequirementsFile.from_string() method it invokes the following method

    @classmethod
    def from_string(cls, text: str) -> "RequirementsFile":
        """
        Return a new RequirementsFile from a ``text`` string.

        Since pip requirements are deeply based on files, we create a temp file
        to feed to pip even if this feels a bit hackish.
        """
        tmpdir = None
        try:
            tmpdir = Path(str(tempfile.mkdtemp()))
            req_file = tmpdir / "requirements.txt"
            with open(req_file, "w") as rf:
                rf.write(text)
            return cls.from_file(filename=str(req_file), include_nested=False)
        finally:
            if tmpdir and tmpdir.exists():
                shutil.rmtree(path=str(tmpdir), ignore_errors=True)

but the following line invokes the Path() which raises the following exception

    tmpdir = Path(str(tempfile.mkdtemp()))

exception:

Traceback (most recent call last):
  File "{directory}/site-packages/pip_requirements_parser.py", line 270, in from_string
    tmpdir = Path(str(tempfile.mkdtemp()))
             ^^^^
NameError: name 'Path' is not defined

This pr suggests that fix

@ale-rt
Copy link

ale-rt commented Feb 14, 2025

This is a nice fix @pombredanne @DennisClark @tdruez

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants