Skip to content
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

Add pyupgrade to pre-commit #174

Merged
merged 2 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: "v3.2.0"
hooks:
- id: pyupgrade
args: ["--py37-plus"]

- repo: https://github.com/psf/black
rev: "22.8.0"
hooks:
Expand Down
2 changes: 1 addition & 1 deletion deptry/cli_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"ignore_missing": (),
"ignore_transitive": (),
"ignore_misplaced_dev": (),
"exclude": ("venv", "\.venv", "tests", "\.git", "setup.py"),
"exclude": ("venv", r"\.venv", "tests", r"\.git", "setup.py"),
"extend_exclude": (),
"ignore_notebooks": False,
"skip_obsolete": False,
Expand Down
6 changes: 3 additions & 3 deletions deptry/dependency_getter/requirements_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _check_if_dependency_is_conditional(line: str) -> bool:

@staticmethod
def _line_is_url(line: str) -> Optional[Match[str]]:
return re.search("^(http|https|git\+https)", line)
return re.search(r"^(http|https|git\+https)", line)

@staticmethod
def _extract_name_from_url(line: str) -> Optional[str]:
Expand All @@ -114,12 +114,12 @@ def _extract_name_from_url(line: str) -> Optional[str]:
return match.group(1)

# for url like git+https://github.com/name/python-module.git@0d6dc38d58
match = re.search("\/((?:(?!\/).)*?)\.git", line)
match = re.search(r"\/((?:(?!\/).)*?)\.git", line)
if match:
return match.group(1)

# for url like https://github.com/urllib3/urllib3/archive/refs/tags/1.26.8.zip
match = re.search("\/((?:(?!\/).)*?)\/archive\/", line)
match = re.search(r"\/((?:(?!\/).)*?)\/archive\/", line)
if match:
return match.group(1)

Expand Down
2 changes: 1 addition & 1 deletion deptry/notebook_import_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def extract(self, path_to_ipynb: Path) -> List[str]:

@staticmethod
def _read_ipynb_file(path_to_ipynb: Path) -> Dict[str, Any]:
with open(path_to_ipynb, "r") as f:
with open(path_to_ipynb) as f:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notebook: Dict[str, Any] = json.load(f)
return notebook

Expand Down
2 changes: 1 addition & 1 deletion deptry/python_file_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_all_python_files_in(self, directory: Path) -> List[Path]:
py_regex = re.compile(r".*\.py$") if self.ignore_notebooks else re.compile(r".*\.py$|.*\.ipynb$")

for root, dirs, files in os.walk(directory, topdown=True):
root_without_trailing_dotslash = re.sub("^\./", "", root)
root_without_trailing_dotslash = re.sub(r"^\./", "", root)
if self.exclude and ignore_regex.match(root_without_trailing_dotslash):
dirs[:] = []
continue
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_cli_with_json_output(dir_with_venv_installed):

# assert that there is json output
subprocess.run(shlex.split("poetry run deptry . -o deptry.json"), capture_output=True, text=True)
with open("deptry.json", "r") as f:
with open("deptry.json") as f:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data = json.load(f)
assert set(data["obsolete"]) == {"isort", "requests"}
assert set(data["missing"]) == {"white"}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_json_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_simple(tmp_path):
with run_within_dir(tmp_path):
JsonWriter(json_output="output.json").write(issues={"one": "two", "three": "four"})

with open("output.json", "r") as f:
with open("output.json") as f:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data = json.load(f)

assert data["one"] == "two"
Expand Down