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

Implement ruff rules A through D #42

Merged
merged 19 commits into from
Feb 2, 2024
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
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

14 changes: 5 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest]

steps:
Expand All @@ -32,15 +32,11 @@ jobs:
- name: Lint with black
run: |
black --check --diff screenpy_selenium
- name: Lint with isort
black --check --diff tests
- name: Lint with ruff
run: |
isort --check-only --diff screenpy_selenium
- name: Lint with flake8
run: |
flake8 --exit-zero screenpy_selenium
ruff check .
- name: Lint with mypy
run: |
mypy screenpy_selenium
- name: Lint with pylint
run: |
pylint screenpy_selenium
mypy tests
4 changes: 2 additions & 2 deletions .github/workflows/poetry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
max-parallel: 9
fail-fast: false
matrix:
python-version: ["3.11"]
python-version: ["3.12"]
os: [ubuntu-latest]
poetry-version: ["1.3.2"]
poetry-version: ["1.6.1"]
bandophahita marked this conversation as resolved.
Show resolved Hide resolved

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
max-parallel: 9
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest]

steps:
Expand Down
46 changes: 17 additions & 29 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
files: 'screenpy_selenium/.*'
files: '(screenpy_selenium|tests)/.*'
fail_fast: false
repos:
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
language_version: python3.11
- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
hooks:
- id: isort
language_version: python3.11
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
language_version: python3.11
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
hooks:
- id: mypy
language_version: python3.11
additional_dependencies: ["PyHamcrest>=2.0.0,<2.1", "selenium>=4.1.0,<4.5"]
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
language_version: python3.12
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.11
hooks:
- id: ruff
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
language_version: python3.12
additional_dependencies: ["PyHamcrest>=2.0.0", "selenium>=4.1.0"]
bandophahita marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 0 additions & 9 deletions .pylintrc

This file was deleted.

25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,28 @@ local_screenpy:
pip install -e ~/projects/screenpy

.PHONY: sync update trunk_screenpy local_screenpy

black-check:
black --check .

black:
black .

ruff:
ruff check .

ruff-fix:
ruff check . --fix --show-fixes

mypy:
mypy .

lint: ruff mypy

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

pre-check-in: black-check lint

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

.PHONY: pre-check-in pre-check-in-fix
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ScreenPy Selenium
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

```
TITLE CARD:
Expand Down
1,369 changes: 775 additions & 594 deletions poetry.lock

Large diffs are not rendered by default.

136 changes: 120 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
[tool.black]
target-version = ['py311']
target-version = ['py312']

extend-exclude = '''
# A regex preceded with ^/ will apply only to files and directories
# in the root of the project.
(
\.idea
| \.git
| \.mypy_cache
| \.tox
| \/docs
| ^/setup.py
)

'''

# This pyproject.toml is setup so it can be used with or without poetry and also
# supports editable installs (PEP 660) without breaking IDE and linter inspection.
Expand Down Expand Up @@ -27,6 +41,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Topic :: Software Development :: Quality Assurance",
Expand All @@ -52,40 +67,129 @@ selenium = ">=4.1.0"
importlib_metadata = {version = "*", python = "3.8.*"}

# convenience packages for development of screenpy only
black = {version = "*", optional = true}
coverage = {version = "*", optional = true}
isort = {version = "*", 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.

Do we still need isort anymore? Doesn't ruff do the needful?

Copy link
Contributor Author

@bandophahita bandophahita Feb 2, 2024

Choose a reason for hiding this comment

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

Technically no.
I've still been using it until ruff implements the combine imports to single line feature. But otherwise no reason to have it in there still. I left it in because it only is installed for dev.

Copy link
Member

Choose a reason for hiding this comment

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

All right, i don't really see a problem with it for now. 👍

mypy = {version = "*", optional = true}
pre-commit = {version = "*", optional = true}
pytest = {version = "*", optional = true}
ruff = {version = "*", optional = true}
sphinx = {version = "*", optional = true}
tox = {version = "*", optional = true}
mypy = {version = "*", optional = true}
black = {version = "*", optional = true}
isort = {version = "*", optional = true}
flake8 = {version = "*", optional = true}
pylint = {version = "*", optional = true}
coverage = {version = "*", optional = true}

[tool.poetry.extras]
dev = [
"pre-commit",
"pytest",
"tox",
"pylint",
]
dev_all = [
"pre-commit",
"pytest",
"tox",
"pylint",
"mypy",
"black",
"isort",
"flake8",
"coverage",
"isort",
Copy link
Member

Choose a reason for hiding this comment

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

Same note about isort.

"mypy",
"pre-commit",
"pytest",
"ruff",
"sphinx",
"tox",
]
test = [
"pytest",
"coverage",
"pytest",
]

[build-system]
requires = ["poetry-core>=1.2.0"]
build-backend = "poetry.core.masonry.api"


[tool.ruff]
target-version = "py38" # minimum supported version
line-length = 88 # same as Black.
select = [
"A", # flake8-builtins
"ANN", # flake8-annotations # coming back to this one later to compare against mypy
"ARG", # flake8-unused-arguments
"B", # flake8-bugbear
"BLE", # flake8-blind-except
"C4", # flake8-comprehensions
"D", # pydocstyle
# "E", # pycodestyle error
# "EM", # flake8-errmsg
# "ERA", # eradicate
# "F", # Pyflakes
# "FA", # flake8-future-annotations
# "FBT", # flake8-boolean-trap
# "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
# "RUF", # ruff specific
# "SIM", # flake8-simplify
# "T10", # flake8-debugger
# "T20", # flake8-print
# "TCH", # flake8-type-checking
# "TRY", # tryceratops
# "UP", # python upgrade
"W", # pycodestyle warning
# "YTT", # flake8-2020

# we would like these someday, but not yet
# "FURB", # refurb
]
ignore = [
"D107", # missing __init__ docstring, we do that in the class docstring.
"D203", # one blank line before class docstring, no thanks!
"D212", # multi line summary first line, we want a one line summary.
"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 = [
# "TCH001", "TCH002", "TCH003", "TCH004",
# "SIM108"
]

[tool.ruff.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!
"PLR", # likewise using specific numbers and strings in tests.
]
"tests/test_pacing.py" = [
"FA100", # we are purposely testing pacing without future annotations.
]


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


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


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


[tool.ruff.pydocstyle]
convention = "google"
4 changes: 1 addition & 3 deletions screenpy_selenium/abilities/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Abilities that enable an Actor to use Selenium.
"""
"""Abilities that enable an Actor to use Selenium."""

from .browse_the_web import BrowseTheWeb

Expand Down
15 changes: 8 additions & 7 deletions screenpy_selenium/abilities/browse_the_web.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Enable the actor to browse the web.
"""
"""Enable the actor to browse the web."""

import os
from typing import Type, TypeVar
Expand Down Expand Up @@ -50,8 +48,9 @@ def using_safari(cls: Type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
@classmethod
def using_ios(cls: Type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
"""
Create and use a default Remote driver instance to connect to a
running Appium server and open Safari on iOS.
Create and use a default Remote driver instance.

Connects to a running Appium server and open Safari on iOS.

Note that Appium requires non-trivial setup to be able to connect
to iPhone simulators. See the Appium documentation to get started:
Expand Down Expand Up @@ -81,8 +80,9 @@ def using_ios(cls: Type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
@classmethod
def using_android(cls: Type[SelfBrowseTheWeb]) -> SelfBrowseTheWeb:
"""
Create and use a default Remote driver instance to connect to a
running Appium server and open Chrome on Android.
Create and use a default Remote driver instance.

Connects to a running Appium server and open Chrome on Android.

Note that Appium requires non-trivial setup to be able to connect
to Android emulators. See the Appium documentation to get started:
Expand Down Expand Up @@ -121,6 +121,7 @@ def forget(self: SelfBrowseTheWeb) -> None:
self.browser.quit()

def __repr__(self: SelfBrowseTheWeb) -> str:
"""Repr."""
return "Browse the Web"

__str__ = __repr__
Expand Down
4 changes: 1 addition & 3 deletions screenpy_selenium/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Actions an Actor can perform using their ability to BrowseTheWeb.
"""
"""Actions an Actor can perform using their ability to BrowseTheWeb."""

from .accept_alert import AcceptAlert
from .chain import Chain
Expand Down
4 changes: 1 addition & 3 deletions screenpy_selenium/actions/accept_alert.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Accept a javascript alert.
"""
"""Accept a javascript alert."""

from screenpy.actor import Actor
from screenpy.pacing import aside, beat
Expand Down
Loading