Skip to content

Commit

Permalink
Fix linters and formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
mknorps committed Nov 20, 2023
1 parent 8c75ff9 commit d551f11
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 14 deletions.
7 changes: 5 additions & 2 deletions fawltydeps/packages.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Encapsulate the lookup of packages and their provided import names."""

import logging
import os
import platform
import subprocess
import sys
Expand Down Expand Up @@ -311,7 +312,9 @@ def __init__(self, srcs: AbstractSet[PyEnvSource] = frozenset()) -> None:
self.package_dirs: Set[Path] = set(src.path for src in srcs)

@classmethod
def find_package_dirs(cls, path: Path) -> Iterator[Path]:
def find_package_dirs( # pylint: disable=too-many-branches,
cls, path: Path
) -> Iterator[Path]: # pylint: disable=too-many-branches,
"""Return the packages directories corresponding to the given path.
The given 'path' is a user-provided directory path meant to point to
Expand Down Expand Up @@ -349,7 +352,7 @@ def find_package_dirs(cls, path: Path) -> Iterator[Path]:

# Check for packages on Windows
if platform.system() == "Windows":
for site_packages in path.glob("Lib\site-packages"):
for site_packages in path.glob(os.path.join("Lib", "site-packages")):
if site_packages.is_dir():
yield site_packages
found = True
Expand Down
5 changes: 4 additions & 1 deletion fawltydeps/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Common types used across FawltyDeps."""

import os
import platform
import sys
from abc import ABC, abstractmethod
Expand Down Expand Up @@ -157,7 +158,9 @@ def __post_init__(self) -> None:
return # also ok

# Support Windows projects
if platform.system() == "Windows" and self.path.match("Lib\site-packages"):
if platform.system() == "Windows" and self.path.match(
os.path.join("Lib", "site-packages")
):
return # also ok

raise ValueError(f"{self.path} is not a valid dir for Python packages!")
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Fixtures for tests"""
import os
import platform
import sys
import venv
Expand Down
7 changes: 4 additions & 3 deletions tests/test_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def test_list_sources__in_varied_project__lists_all_files(fake_project):
"pyproject.toml",
"setup.py",
"setup.cfg",
"my_venv\Lib\site-packages"
os.path.join("my_venv", "Lib", "site-packages")
if platform.system() == "Windows"
else f"my_venv/lib/python{major}.{minor}/site-packages",
]
Expand Down Expand Up @@ -638,7 +638,8 @@ class ProjectTestVector:
],
expect_logs=[
"INFO:fawltydeps.extract_imports:Finding Python files under {path}",
f"INFO:fawltydeps.extract_imports:Parsing Python file {os.path.join('{path}', 'code.py')}",
"INFO:fawltydeps.extract_imports:Parsing Python file "
f"{os.path.join('{path}', 'code.py')}",
"INFO:fawltydeps.packages:'pandas' was not resolved."
" Assuming it can be imported as 'pandas'.",
],
Expand Down Expand Up @@ -716,7 +717,7 @@ def test_check_json__simple_project__can_report_both_undeclared_and_unused(
},
{
"source_type": "PyEnvSource",
"path": f"{tmp_path}\my_venv\Lib\site-packages"
"path": tmp_path / "my_venv" / "Lib" / "site-packages"
if platform.system() == "Windows"
else f"{tmp_path}/my_venv/lib/python{major}.{minor}/site-packages",
},
Expand Down
7 changes: 3 additions & 4 deletions tests/test_dir_traversal.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Test core functionality of DirectoryTraversal class."""
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
import os
import platform
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from pathlib import Path
from typing import Generic, List, Optional, Tuple, TypeVar, Union

Expand Down Expand Up @@ -281,8 +281,7 @@ class DirectoryTraversalVector(Generic[T]):
marks=pytest.mark.skipif(
platform.system() == "Windows"
and any(
isinstance(entry, RelativeSymlink)
or isinstance(entry, AbsoluteSymlink)
isinstance(entry, (RelativeSymlink, AbsoluteSymlink))
for entry in v.given
),
reason="Symlinks on Windows may be created only by administrators",
Expand Down
3 changes: 2 additions & 1 deletion tests/test_local_env.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Verify behavior of package module looking at a given Python environment."""
import os
import platform
import sys
import venv
Expand Down Expand Up @@ -44,7 +45,7 @@
windows_subdirs = [
"",
"Lib",
f"Lib\site-packages",
os.path.join("Lib", "site-packages"),
]


Expand Down
2 changes: 1 addition & 1 deletion tests/test_types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Verify behavior of our basic types."""

from dataclasses import FrozenInstanceError
import os
from dataclasses import FrozenInstanceError
from pathlib import Path

import pytest
Expand Down
1 change: 0 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import subprocess
import sys
import platform
from dataclasses import dataclass, field, replace
from pathlib import Path
from pprint import pformat
Expand Down

0 comments on commit d551f11

Please sign in to comment.