From a339412867d94ad3c2fa99325dc90ce6c6d79c84 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Wed, 22 Nov 2023 12:52:12 +0800 Subject: [PATCH] fix: Do not detect as requirements.txt if the file is a python script Close #2416 Signed-off-by: Frost Ming --- news/2416.bugfix.md | 1 + src/pdm/formats/requirements.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 news/2416.bugfix.md 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