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

Adopt pre-commit for linting and formatting #1188

Merged
merged 6 commits into from
Aug 15, 2023
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
29 changes: 21 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ jobs:
- name: Install test dependencies
run: pip install tox

# Lint before running unit tests
- name: Run lint
run: tox -e lint

- name: Run tests
run: |
tox -e tests -- -n 4 tests/test_browser.py tests/test_element_list.py tests/test_request_handler.py tests/test_xpath_concat.py
Expand All @@ -59,8 +55,6 @@ jobs:
strategy:
matrix:
include:
- PY_VER: py37
python-version: 3.7
- PY_VER: py38
python-version: 3.8
- PY_VER: py39
Expand Down Expand Up @@ -101,8 +95,6 @@ jobs:
strategy:
matrix:
include:
- PY_VER: py37
python-version: 3.7
- PY_VER: py38
python-version: 3.8
- PY_VER: py39
Expand All @@ -125,3 +117,24 @@ jobs:
- name: Run Selenium tests
run: |
tox -e tests_selenium -- -n 4 tests/test_element_is_visible.py tests/test_screenshot.py tests/test_shadow_root.py tests/test_mouse_interaction.py tests/test_async_finder.py tests/test_html_snapshot.py tests/test_iframes.py tests/test_popups.py tests/test_webdriver.py tests/test_webdriver_firefox.py tests/test_webdriver_chrome.py;

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: 3.x

- name: install pre-commit
run: pip install pre-commit

- name: pre-commit cache
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: "pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}"
restore-keys: "pre-commit-"

- run: pre-commit run --all-files --show-diff-on-failure
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black

- repo: https://github.com/asottile/reorder_python_imports
rev: v3.10.0
hooks:
- id: reorder-python-imports
args:
- "--py38-plus"

- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
args:
- "--py38-plus"

- repo: https://github.com/asottile/add-trailing-comma
rev: v3.0.1
hooks:
- id: add-trailing-comma

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.282
hooks:
- id: ruff
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ test: dependencies clean
@echo "Running all tests..."
tox -- $(which)

format: clean dependencies
@flake8 --max-line-length 110 ./splinter ./tests

coverage: dependencies clean
@echo "Running all tests with coverage..."
@coverage run run_tests.py -w $(which) && coverage report
Expand Down
2 changes: 1 addition & 1 deletion docs/_templates/genindex.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "!genindex.html" %}

{% block bodyclass %}{% endblock %}
{% block sidebarwrapper %}{% endblock %}
{% block sidebarwrapper %}{% endblock %}
2 changes: 1 addition & 1 deletion docs/_templates/modindex.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% extends "!modindex.html" %}
{% block bodyclass %}{% endblock %}
{% block sidebarwrapper %}{% endblock %}
{% block sidebarwrapper %}{% endblock %}
2 changes: 1 addition & 1 deletion docs/_templates/search.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% extends "!search.html" %}
{% block bodyclass %}{% endblock %}
{% block sidebarwrapper %}{% endblock %}
{% block sidebarwrapper %}{% endblock %}
1 change: 0 additions & 1 deletion docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ Welcome to the Splinter API documentation! Check what's inside:
element-list
request-handling
exceptions

1 change: 0 additions & 1 deletion docs/api/request-handling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ Request handling

.. autoclass:: splinter.request_handler.status_code.StatusCode
:members:

13 changes: 5 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# splinter documentation build configuration file, created by
# sphinx-quickstart on Sat Jan 8 23:31:41 2011.
Expand All @@ -10,12 +9,10 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# sys.path.insert(0, os.path.abspath('.'))

import os
import sys
from datetime import datetime
Expand Down Expand Up @@ -47,8 +44,8 @@
master_doc = "index"

# General information about the project.
project = u"Splinter"
copyright = u"{}, cobrateam".format(datetime.now().year)
project = "Splinter"
copyright = f"{datetime.now().year}, cobrateam"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -109,7 +106,7 @@
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
'collapse_navigation': False,
"collapse_navigation": False,
}

# Add any paths that contain custom themes here, relative to this directory.
Expand Down Expand Up @@ -192,7 +189,7 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
("index", "splinter.tex", u"splinter Documentation", u"andrews medina", "manual")
("index", "splinter.tex", "splinter Documentation", "andrews medina", "manual"),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -223,4 +220,4 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [("index", "splinter", u"splinter Documentation", [u"andrews medina"], 1)]
man_pages = [("index", "splinter", "splinter Documentation", ["andrews medina"], 1)]
2 changes: 1 addition & 1 deletion docs/selenium-keys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ With Splinter's type() method, you can use Selenium's Keys implementation.
browser.type(Keys.RETURN)

The full list of all supported keys can be found at the official Selenium documentation:
`selenium.webdriver.common.keys <https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html>`_
`selenium.webdriver.common.keys <https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html>`_
6 changes: 0 additions & 6 deletions requirements/lint.txt

This file was deleted.

2 changes: 2 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exclude = ["docs"]
line-length = 120
19 changes: 10 additions & 9 deletions samples/test_facebook_events.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# -*- coding: utf-8 -*-

# Copyright 2012 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

"""
This snippet show how to "test" a Facebook feature: the creation of an event.

It creates an event by going to http://www.facebook.com, login and navigate to "Create an event" page.
"""

import os
import unittest
import time
import unittest

from splinter import Browser


Expand All @@ -30,7 +27,7 @@ def do_login_if_need(self, username, password):
self.browser.fill("email", username)
self.browser.fill("pass", password)
self.browser.find_by_css(
'div.menu_login_container input[type="submit"]'
'div.menu_login_container input[type="submit"]',
).first.click()
assert self.browser.is_element_present_by_css("li#navAccount")

Expand All @@ -49,12 +46,15 @@ def test_create_event(self):

# Uploading the picture
picture_path = os.path.join(
os.path.abspath(os.path.dirname(__file__)), "img", "turtles.jpg"
os.path.abspath(os.path.dirname(__file__)),
"img",
"turtles.jpg",
)
self.browser.find_by_css("div.eventEditUpload a.uiButton").first.click()

if not self.browser.is_element_present_by_css(
"iframe#upload_pic_frame", wait_time=10
"iframe#upload_pic_frame",
wait_time=10,
):
self.fail("The upload pic iframe didn't appear :(")

Expand All @@ -68,7 +68,8 @@ def test_create_event(self):
self.browser.fill("name", "Splinter sprint")
self.browser.fill("location", "Rio de Janeiro, Brazil")
self.browser.fill(
"desc", "For more info, check out the #cobratem channel on freenode!"
"desc",
"For more info, check out the #cobratem channel on freenode!",
)

self.browser.find_by_css('label.uiButton input[type="submit"]').first.click()
Expand Down
3 changes: 1 addition & 2 deletions samples/test_google_search.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env python

# Copyright 2012 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

import unittest

from splinter import Browser


Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2012 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
Expand All @@ -10,7 +9,7 @@

def read(filename: str) -> str:
path = os.path.join(os.path.dirname(__file__), filename)
with open(path, "r") as f:
with open(path) as f:
return f.read()


Expand Down
8 changes: 4 additions & 4 deletions splinter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Copyright 2016 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

from splinter.browser import Browser
from splinter.config import Config
from splinter.version import __version_info__, __version__ # NOQA
from splinter.version import __version__ # noqa: F401
from splinter.version import __version_info__ # noqa: F401


__all__ = [
'Browser',
'Config',
"Browser",
"Config",
]
Loading