Skip to content

Commit

Permalink
Improve fixes for ruff/flake8-simplify rule SIM103
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos committed Oct 3, 2024
1 parent ae41609 commit 0b45393
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
10 changes: 5 additions & 5 deletions docs/pip_sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def _is_version_section_title_underline(
self, prev: Optional[str], curr: str
) -> bool:
"""Find a ==== line that marks the version section title."""
if prev is None:
return False
if re.match(r"^=+$", curr) is None:
return False
return not len(curr) < len(prev)
return (
prev is not None
and re.match(r"^=+$", curr) is not None
and len(curr) >= len(prev)
)

def _iter_lines_with_refs(self, lines: Iterable[str]) -> Iterator[str]:
"""Transform the input lines to add a ref before each section title.
Expand Down
10 changes: 5 additions & 5 deletions src/pip/_internal/req/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ def _looks_like_path(name: str) -> bool:
* a path separator is found (either os.path.sep or os.path.altsep);
* a dot is found (which represents the current directory).
"""
if os.path.sep in name:
return True
if os.path.altsep is not None and os.path.altsep in name:
return True
return name.startswith(".")
return (
os.path.sep in name
or (os.path.altsep is not None and os.path.altsep in name)
or name.startswith(".")
)


def _get_url_from_path(path: str, name: str) -> Optional[str]:
Expand Down
9 changes: 4 additions & 5 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,10 @@ def is_installable_dir(path: str) -> bool:
setup.cfg because using it without setup.py is only available for PEP 517
projects, which are already covered by the pyproject.toml check.
"""
if not os.path.isdir(path):
return False
if os.path.isfile(os.path.join(path, "pyproject.toml")):
return True
return os.path.isfile(os.path.join(path, "setup.py"))
return os.path.isdir(path) and (
os.path.isfile(os.path.join(path, "pyproject.toml"))
or os.path.isfile(os.path.join(path, "setup.py"))
)


def read_chunks(
Expand Down
7 changes: 5 additions & 2 deletions src/pip/_internal/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,11 @@ def _should_fetch(cls, dest: str, rev: str) -> bool:
# Git fetch would fail with abbreviated commits.
return False

# Don't fetch if we have the commit locally.
return not cls.has_commit(dest, rev)
if cls.has_commit(dest, rev):
# Don't fetch if we have the commit locally.
return False

return True

@classmethod
def resolve_revision(
Expand Down

0 comments on commit 0b45393

Please sign in to comment.