Skip to content

Commit 4e5668d

Browse files
committed
Small refactor to fix off-by-one, lint
1 parent e40c4c1 commit 4e5668d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

setuptools/command/editable_wheel.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,8 @@ def _find_spec(cls, fullname, pkg_path, rest):
772772
init = candidate_path / "__init__.py"
773773
candidates = (candidate_path.with_suffix(x) for x in module_suffixes())
774774
for candidate in chain([init], candidates):
775-
if candidate.is_file() and _check_case(candidate, len(rest)):
775+
last_n = len(rest) + len(candidate.parts) - len(candidate_path.parts)
776+
if candidate.is_file() and _check_case(candidate, last_n):
776777
return spec_from_file_location(fullname, candidate)
777778
778779
@@ -801,17 +802,17 @@ def find_module(cls, fullname):
801802
return None
802803
803804
804-
def _check_case(path, n):
805+
def _check_case(path, last_n):
805806
'''Verify the last `n` parts of the path have correct case.'''
806807
return (
807808
(not sys.flags.ignore_environment and "PYTHONCASEOK" in os.environ)
808809
or (
809810
# check the case of the name by listing its parent directory
810811
path.as_posix() in (p.as_posix() for p in path.parent.iterdir())
811-
# check the case of the next n parent directories the same way
812+
# check the case of the next n - 1 components the same way
812813
and all(
813814
part.as_posix() in (p.as_posix() for p in part.parent.iterdir())
814-
for part in list(path.parents)[:n]
815+
for part in list(path.parents)[:last_n - 1]
815816
)
816817
)
817818
)

setuptools/tests/test_editable_install.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,6 @@ def test_namespace_case_sensitivity(self, tmp_path):
654654
import_module("ns.othername.foo.BAR")
655655

656656

657-
658657
def test_pkg_roots(tmp_path):
659658
"""This test focus in getting a particular implementation detail right.
660659
If at some point in time the implementation is changed for something different,

0 commit comments

Comments
 (0)