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

Ruff E through P #45

Merged
merged 16 commits into from
Feb 7, 2024
Merged
6 changes: 0 additions & 6 deletions .isort.cfg

This file was deleted.

4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ files: '(screenpy_selenium|tests)/.*'
fail_fast: false
repos:
- repo: https://github.com/psf/black
rev: 23.12.1
rev: 24.1.1
hooks:
- id: black
language_version: python3.12
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.11
rev: v0.2.0
hooks:
- id: ruff
- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ black-check:
black:
black .

isort-check:
isort . --check

isort:
isort .

ruff:
ruff check .

Expand All @@ -35,12 +41,12 @@ ruff-fix:
mypy:
mypy .

lint: ruff mypy
lint: isort-check ruff mypy

.PHONY: black-check black ruff ruff-fix mypy lint
.PHONY: black-check black isort-check isort ruff ruff-fix mypy lint

pre-check-in: black-check lint

pre-check-in-fix: black ruff-fix mypy
pre-check-in-fix: black isort ruff-fix mypy

.PHONY: pre-check-in pre-check-in-fix
583 changes: 344 additions & 239 deletions poetry.lock

Large diffs are not rendered by default.

74 changes: 46 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ isort = {version = "*", optional = true}
mypy = {version = "*", optional = true}
pre-commit = {version = "*", optional = true}
pytest = {version = "*", optional = true}
ruff = {version = "*", optional = true}
ruff = {version = ">=0.2.0", optional = true}
Copy link
Member

Choose a reason for hiding this comment

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

What necessitated this change?

Copy link
Contributor Author

@bandophahita bandophahita Feb 7, 2024

Choose a reason for hiding this comment

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

The new rule changes in the pyproject.toml occurred at that version.
[tool.ruff.lint.***]

sphinx = {version = "*", optional = true}
tox = {version = "*", optional = true}

Expand Down Expand Up @@ -107,6 +107,14 @@ build-backend = "poetry.core.masonry.api"
[tool.ruff]
target-version = "py38" # minimum supported version
line-length = 88 # same as Black.

extend-exclude = [
"screenpy_selenium/__init__.py",
"screenpy_selenium/__version__.py",
"docs",
]

[tool.ruff.lint]
select = [
"A", # flake8-builtins
"ANN", # flake8-annotations # coming back to this one later to compare against mypy
Expand All @@ -115,21 +123,21 @@ select = [
"BLE", # flake8-blind-except
"C4", # flake8-comprehensions
"D", # pydocstyle
# "E", # pycodestyle error
# "EM", # flake8-errmsg
# "ERA", # eradicate
# "F", # Pyflakes
# "FA", # flake8-future-annotations
"E", # pycodestyle error
"EM", # flake8-errmsg
"ERA", # eradicate
"F", # Pyflakes
"FA", # flake8-future-annotations
# "FBT", # flake8-boolean-trap
Copy link
Contributor Author

Choose a reason for hiding this comment

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

purposefully skipping FBT for this PR. Will be addressed in it's own at the end.

# "FIX", # flake8-fixme
# "FLY", # flynt
# "I", # isort
# "ICN", # flake8-import-conventions
# "ISC", # flake8-implicit-str-concat
# "PGH", # pygrep-hooks
# "PIE", # flake8-pie
# "PL", # pylint
# "PT", # flake8-pytest-style
"FIX", # flake8-fixme
"FLY", # flynt
"I", # isort
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
# "Q", # flake8-quotes
# "RET", # flake8-return
# "RSE", # flake8-raise
Expand All @@ -153,20 +161,20 @@ ignore = [
"ANN101", # missing self annotation, we only annotate self when we return it.
"ANN102", # missing cls annotation, we only annotate cls when we return it.
]
exclude = [
"screenpy_selenium/__init__.py",
"screenpy_selenium/__version__.py",
"docs",
]


[tool.ruff.lint]
extend-safe-fixes = [
"EM101",
"EM102",
# "TCH001", "TCH002", "TCH003", "TCH004",
# "SIM108"
# maybe?
# "F841",
"C419",
"D200", "D205", "D415",
"PT003", "PT006", "PT018",
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/**" = [
"D", # we don't need public-API-polished docstrings in tests.
"FBT", # using a boolean as a test object is useful!
Expand All @@ -176,20 +184,30 @@ extend-safe-fixes = [
"FA100", # we are purposely testing pacing without future annotations.
]


[tool.ruff.isort]
[tool.ruff.lint.isort]
combine-as-imports = true
split-on-trailing-comma = true
known-first-party = ["screenpy_selenium", "tests"]


[tool.ruff.flake8-pytest-style]
[tool.ruff.lint.flake8-pytest-style]
mark-parentheses = false


[tool.ruff.pycodestyle]
[tool.ruff.lint.pycodestyle]
ignore-overlong-task-comments = true


[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "google"


[tool.isort]
line_length = 88
multi_line_output = 3
include_trailing_comma = true
use_parentheses = true
combine_as_imports = true

skip = [".idea", ".tox", "docs"]
src_paths = ["screenpy_selenium","tests"]
1 change: 1 addition & 0 deletions screenpy_selenium/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
▀▀▀▄▄ █ █▄▄▀ █▀▀ █▀▀ █ █ ░█▄▄█ █▄▄█ ▀▀▀▄▄ █▀▀ █ █▀▀ █ █ ▀█▀ █ █ █ ▀ █
░█▄▄▄█ ▀▀▀ ▀ ▀▀ ▀▀▀ ▀▀▀ ▀ ▀ ░█ ▄▄▄█ ░█▄▄▄█ ▀▀▀ ▀▀▀ ▀▀▀ ▀ ▀ ▀▀▀ ▀▀▀ ▀ ▀
"""

try:
# importlib.metadata is present in Python 3.8 and later
import importlib.metadata as importlib_metadata # type: ignore
Expand Down
10 changes: 6 additions & 4 deletions screenpy_selenium/abilities/browse_the_web.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Enable the actor to browse the web."""

from __future__ import annotations

import os
from typing import Type, TypeVar

Expand Down Expand Up @@ -73,7 +75,8 @@ def using_ios(cls: Type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
"browserName": "Safari",
}
if IOS_CAPABILITIES["platformVersion"] is None:
raise BrowsingError("IOS_DEVICE_VERSION Environment variable must be set.")
msg = "IOS_DEVICE_VERSION Environment variable must be set."
raise BrowsingError(msg)

return cls.using(browser=Remote(hub_url, IOS_CAPABILITIES))

Expand Down Expand Up @@ -105,9 +108,8 @@ def using_android(cls: Type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
"browserName": "Chrome",
}
if ANDROID_CAPABILITIES["platformVersion"] is None:
raise BrowsingError(
"ANDROID_DEVICE_VERSION environment variable must be set."
)
msg = "ANDROID_DEVICE_VERSION environment variable must be set."
raise BrowsingError(msg)

return cls.using(browser=Remote(hub_url, ANDROID_CAPABILITIES))

Expand Down
2 changes: 2 additions & 0 deletions screenpy_selenium/actions/accept_alert.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Accept a javascript alert."""

from __future__ import annotations

from screenpy.actor import Actor
from screenpy.pacing import aside, beat

Expand Down
9 changes: 5 additions & 4 deletions screenpy_selenium/actions/chain.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""A meta-Action to group a series of chainable Actions together."""

from __future__ import annotations

from screenpy.actor import Actor
from screenpy.exceptions import UnableToAct
from screenpy.pacing import beat
Expand Down Expand Up @@ -35,13 +37,12 @@ def describe(self) -> str:
def perform_as(self, the_actor: Actor) -> None:
"""Choreograph the Actions and direct the Actor to perform the chain."""
browser = the_actor.ability_to(BrowseTheWeb).browser
the_chain = ActionChains(browser) # type: ignore[arg-type]
the_chain = ActionChains(browser)

for action in self.actions:
if not isinstance(action, Chainable):
raise UnableToAct(
f"The {action.__class__.__name__} Action cannot be chained."
)
msg = f"The {action.__class__.__name__} Action cannot be chained."
raise UnableToAct(msg)
action.add_to_chain(the_actor, the_chain)
the_chain.perform()

Expand Down
3 changes: 3 additions & 0 deletions screenpy_selenium/actions/clear.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Clear text from an input."""

from __future__ import annotations

from typing import Type, TypeVar

from screenpy.actor import Actor
Expand Down
9 changes: 6 additions & 3 deletions screenpy_selenium/actions/click.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Click on an element."""

from __future__ import annotations

from typing import Optional, Type, TypeVar

from screenpy.actor import Actor
Expand Down Expand Up @@ -57,10 +59,11 @@ def describe(self: SelfClick) -> str:
def perform_as(self: SelfClick, the_actor: Actor) -> None:
"""Direct the Actor to click on the element."""
if self.target is None:
raise UnableToAct(
"Target was not supplied for Click. Provide a Target by using the "
".on() or .on_the() method."
msg = (
"Target was not supplied for Click. "
"Provide a Target by using the .on() or .on_the() method."
)
raise UnableToAct(msg)

element = self.target.found_by(the_actor)

Expand Down
2 changes: 2 additions & 0 deletions screenpy_selenium/actions/dismiss_alert.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Dismiss a javascript alert."""

from __future__ import annotations

from screenpy.actor import Actor
from screenpy.pacing import aside, beat

Expand Down
2 changes: 2 additions & 0 deletions screenpy_selenium/actions/double_click.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Double-click on an element, or wherever the cursor currently is."""

from __future__ import annotations

from typing import Optional, Type, TypeVar

from screenpy.actor import Actor
Expand Down
5 changes: 4 additions & 1 deletion screenpy_selenium/actions/enter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Enter text into an input field, or press keys."""

from __future__ import annotations

from functools import partial
from typing import List, Optional, Type, TypeVar

Expand Down Expand Up @@ -112,10 +114,11 @@ def describe(self: SelfEnter) -> str:
def perform_as(self: SelfEnter, the_actor: Actor) -> None:
"""Direct the Actor to enter the text into the element."""
if self.target is None:
raise UnableToAct(
msg = (
"Target was not supplied for Enter. Provide a Target by using either "
"the .into(), .into_the(), or .on() method."
)
raise UnableToAct(msg)

element = self.target.found_by(the_actor)

Expand Down
3 changes: 3 additions & 0 deletions screenpy_selenium/actions/enter_2fa_token.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Enter a 2-factor authentication code into a text field."""

from __future__ import annotations

from typing import Type, TypeVar

from screenpy.actor import Actor
Expand Down
2 changes: 2 additions & 0 deletions screenpy_selenium/actions/go_back.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Press the browser back button."""

from __future__ import annotations

from screenpy.actor import Actor
from screenpy.pacing import beat

Expand Down
2 changes: 2 additions & 0 deletions screenpy_selenium/actions/go_forward.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Press the browser forward button."""

from __future__ import annotations

from screenpy.actor import Actor
from screenpy.pacing import beat

Expand Down
5 changes: 4 additions & 1 deletion screenpy_selenium/actions/hold_down.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Hold down a specific key or the left mouse button, optionally on an element."""

from __future__ import annotations

import platform
from typing import Optional, Type, TypeVar

Expand Down Expand Up @@ -80,7 +82,8 @@ def add_to_chain(
elif self.key is not None:
the_chain.key_down(self.key)
else:
raise UnableToAct("HoldDown must be told what to hold down.")
msg = "HoldDown must be told what to hold down."
raise UnableToAct(msg)

def __init__(
self: SelfHoldDown, key: Optional[str] = None, lmb: bool = False
Expand Down
9 changes: 6 additions & 3 deletions screenpy_selenium/actions/move_mouse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Move the mouse to a specific element, or by an offset."""

from __future__ import annotations

from typing import Optional, Tuple, Type, TypeVar

from screenpy.actor import Actor
Expand Down Expand Up @@ -106,10 +108,11 @@ def _add_action_to_chain(
elif self.offset is not None:
the_chain.move_by_offset(*self.offset)
else:
raise UnableToAct(
"MoveMouse was given neither coordinates nor a Target. Supply "
"one of these using MoveMouse.by_offset or MoveMouse.to_the."
msg = (
"MoveMouse was given neither coordinates nor a Target. "
"Supply one of these using MoveMouse.by_offset or MoveMouse.to_the."
)
raise UnableToAct(msg)

def describe(self: SelfMoveMouse) -> str:
"""Describe the Action in present tense."""
Expand Down
2 changes: 2 additions & 0 deletions screenpy_selenium/actions/open.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Open a browser on a URL."""

from __future__ import annotations

import os
from typing import Type, TypeVar, Union

Expand Down
2 changes: 2 additions & 0 deletions screenpy_selenium/actions/pause.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Pause just like in ScreenPy, but also be able to do it in a Chain!"""

from __future__ import annotations

from screenpy import Actor
from screenpy.actions import Pause as BasePause
from screenpy.pacing import beat
Expand Down
Loading
Loading