-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] [doctest] pkg_resources.NullProvider._validate_resource_path and TestWriteEntries.test_invalid_entry_point fail with Python 3.13.0a3 #4196
Comments
I can reproduce directly from the main branch @ 04a6bfe via
|
Still the same result with Python 3.13.0b1 and setuptools @ 544b332 Going to take a closer look. |
The code originating the first failure has the following: msg = "Use of .. or absolute path in a resource path is not allowed."
# Aggressively disallow Windows absolute paths
if ntpath.isabs(path) and not posixpath.isabs(path):
raise ValueError(msg) So I suppose in Python 3.13 |
This is what I discovered as well:
Let me see if this is intentional change in CPython or a bug. |
https://docs.python.org/3.13/library/os.path.html#os.path.isabs
|
I wonder what the function wants to do here. We can check if the first character is a backslash and use that to preserve backward compatibility. However, the docstring actually says "Windows path separators are straight-up disallowed" which was only true for paths starting with them. |
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index 713d9bdfa..0ff232f6d 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -1604,6 +1604,7 @@ is not allowed.
os.path.pardir in path.split(posixpath.sep)
or posixpath.isabs(path)
or ntpath.isabs(path)
+ or path.startswith("\\")
)
if not invalid:
return
@@ -1611,7 +1612,8 @@ is not allowed.
msg = "Use of .. or absolute path in a resource path is not allowed."
# Aggressively disallow Windows absolute paths
- if ntpath.isabs(path) and not posixpath.isabs(path):
+ if ((path.startswith("\\") or ntpath.isabs(path))
+ and not posixpath.isabs(path)):
raise ValueError(msg)
# for compatibility, warn; in future This makes the doctest pass. Is it the intended behavior? |
I think it is a problem with the escaping (because of the docstring)... I suppose the original idea was to verify Does this change make sense? diff --git i/pkg_resources/__init__.py w/pkg_resources/__init__.py
index 713d9bdfa..9f4d90150 100644
--- i/pkg_resources/__init__.py
+++ w/pkg_resources/__init__.py
@@ -1575,7 +1575,7 @@ class NullProvider:
False
Windows path separators are straight-up disallowed.
- >>> vrp(r'\\foo/bar.txt')
+ >>> vrp(r'\\\\foo/bar.txt')
Traceback (most recent call last):
...
ValueError: Use of .. or absolute path in a resource path \
|
Your change also makes the doctest pass. However, do we want to allow paths like |
This is the reference for Windows paths starting with
But the result of the function would still be a warning and taken as invalid, right? |
The second test failure reason is quite simple. In here: setuptools/setuptools/_entry_points.py Lines 18 to 25 in 544b332
setuptools expect AttributeError. importlib.metadata give AssertionError instead. Again, will check if this is intentional or not (however, throwing assertion errors for invalid inputes is bad IMHO). |
Nope. It would be valid (return None, no warning) for paths starting with a single backslash. |
That is weird... invalid = (
os.path.pardir in path.split(posixpath.sep)
or posixpath.isabs(path)
or ntpath.isabs(path)
)
if not invalid:
return Should not return... Instead the function should reach the end with a warning... Anyway, I think that the change you proposed make sense (and it avoids this problem). Thank you! |
Well, it is now False or False or Flase, which is False, which means it will return because
I'll send a PR. |
|
Oh, of course... sorry, messed thoughts! Thank you very much. |
The exception in importlib.metadata has changed. See python/importlib_metadata#488 This make an existing test pass with Python 3.13. Partially fixes pypa#4196
The exception in importlib.metadata has changed. See python/importlib_metadata#488 This makes an existing test pass with Python 3.13. Partially fixes pypa#4196
And #4357 |
Previously, such paths were disallowed implicitly as they were treated as Windows absolute paths. Since Python 3.13, paths starting with a single backslash are not considered Windows-absolute, so we treat them specially. This change makes the existing doctest pass with Python 3.13. Partially fixes #4196
Thank you very much. |
setuptools version
69.0.3
Python version
Python 3.13.0a3
OS
Fedora Linux 40
Additional environment information
This happens in the context of the RPM build of setuptools for Fedora Linux.
Description
Two test fail when building setuptools with Python 3.13.0a3
Expected behavior
Test pass
How to Reproduce
Happy to test it in the RPM environment.
Output
The text was updated successfully, but these errors were encountered: