diff --git a/news/2416.bugfix.md b/news/2416.bugfix.md new file mode 100644 index 0000000000..6dc49b8728 --- /dev/null +++ b/news/2416.bugfix.md @@ -0,0 +1 @@ +Do not detect as requirements.txt if the file is a python script. diff --git a/src/pdm/formats/requirements.py b/src/pdm/formats/requirements.py index 6cdfc89b01..6f412a6ec2 100644 --- a/src/pdm/formats/requirements.py +++ b/src/pdm/formats/requirements.py @@ -5,6 +5,7 @@ import hashlib import shlex import urllib.parse +from pathlib import Path from typing import TYPE_CHECKING, Any, Mapping from pdm.formats.base import make_array @@ -98,8 +99,9 @@ def check_fingerprint(project: Project, filename: PathLike) -> bool: try: tomllib.load(fp) except ValueError: - # the file should be a requirements.txt if it not a TOML document. - return True + # the file should be a requirements.txt + # if it's not a TOML document nor py script. + return Path(filename).suffix not in (".py",) else: return False