Skip to content

Commit

Permalink
Sort and group all imports per PEP8 (isort)
Browse files Browse the repository at this point in the history
via:
  isort --lines-after-imports 2 .
  • Loading branch information
johnhawkinson committed Apr 4, 2021
1 parent a27ff22 commit 0eb9495
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 47 deletions.
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
import sys
from datetime import datetime


Expand All @@ -24,6 +24,7 @@

import mechanicalsoup


# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
Expand Down
4 changes: 3 additions & 1 deletion examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
NOTE: This example will not work if the user has 2FA enabled."""

import argparse
import mechanicalsoup
from getpass import getpass

import mechanicalsoup


parser = argparse.ArgumentParser(description="Login to GitHub.")
parser.add_argument("username")
args = parser.parse_args()
Expand Down
2 changes: 2 additions & 0 deletions examples/example_manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
See example.py for an example using the more advanced StatefulBrowser."""
import argparse

import mechanicalsoup


parser = argparse.ArgumentParser(description="Login to GitHub.")
parser.add_argument("username")
parser.add_argument("password")
Expand Down
1 change: 1 addition & 0 deletions examples/expl_duck_duck_go.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import mechanicalsoup


# Connect to duckduckgo
browser = mechanicalsoup.StatefulBrowser(user_agent="MechanicalSoup")
browser.open("https://duckduckgo.com/")
Expand Down
2 changes: 2 additions & 0 deletions examples/expl_google.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import re

import mechanicalsoup


# Connect to Google
browser = mechanicalsoup.StatefulBrowser()
browser.open("https://www.google.com/")
Expand Down
1 change: 1 addition & 0 deletions examples/expl_httpbin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mechanicalsoup


browser = mechanicalsoup.StatefulBrowser()
browser.open("http://httpbin.org/")

Expand Down
4 changes: 3 additions & 1 deletion examples/expl_qwant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"""

import re
import mechanicalsoup
import urllib.parse

import mechanicalsoup


# Connect to duckduckgo
browser = mechanicalsoup.StatefulBrowser(user_agent='MechanicalSoup')
browser.open("https://lite.qwant.com/")
Expand Down
5 changes: 3 additions & 2 deletions mechanicalsoup/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .utils import LinkNotFoundError
from .__version__ import __version__
from .browser import Browser
from .form import Form, InvalidFormMethod
from .stateful_browser import StatefulBrowser
from .__version__ import __version__
from .utils import LinkNotFoundError


__all__ = ['StatefulBrowser', 'LinkNotFoundError', 'Browser', 'Form',
'InvalidFormMethod', '__version__']
14 changes: 8 additions & 6 deletions mechanicalsoup/browser.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import requests
import tempfile
import urllib
import weakref
import webbrowser

import bs4
import bs4.dammit
import urllib
import requests

from .__version__ import __title__, __version__
from .form import Form
import webbrowser
import tempfile
from .utils import LinkNotFoundError
from .__version__ import __version__, __title__
import weakref


class Browser:
Expand Down
4 changes: 3 additions & 1 deletion mechanicalsoup/form.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import copy
import warnings
from .utils import LinkNotFoundError

from bs4 import BeautifulSoup

from .utils import LinkNotFoundError


class InvalidFormMethod(LinkNotFoundError):
"""This exception is raised when a method of :class:`Form` is used
Expand Down
12 changes: 7 additions & 5 deletions mechanicalsoup/stateful_browser.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from .browser import Browser
from .utils import LinkNotFoundError
from .form import Form
import sys
import re
import bs4
import sys
import urllib

import bs4

from .browser import Browser
from .form import Form
from .utils import LinkNotFoundError


class _BrowserState:
def __init__(self, page=None, url=None, form=None, request=None):
Expand Down
3 changes: 2 additions & 1 deletion tests/setpath.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Add the main directory of the project to sys.path, so that
uninstalled version is tested."""

import sys
import os
import sys


TEST_DIR = os.path.abspath(os.path.dirname(__file__))
PROJ_DIR = os.path.dirname(TEST_DIR)
Expand Down
16 changes: 7 additions & 9 deletions tests/test_browser.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import setpath # noqa:F401, must come before 'import mechanicalsoup'
import mechanicalsoup
import os
import sys
from bs4 import BeautifulSoup
import tempfile
import os
from requests.cookies import RequestsCookieJar

import pytest
import setpath # noqa:F401, must come before 'import mechanicalsoup'
from bs4 import BeautifulSoup
from requests.cookies import RequestsCookieJar
from utils import mock_get, prepare_mock_browser

from utils import (
prepare_mock_browser,
mock_get
)
import mechanicalsoup


def test_submit_online(httpbin):
Expand Down
10 changes: 6 additions & 4 deletions tests/test_form.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import setpath # noqa:F401, must come before 'import mechanicalsoup'
import mechanicalsoup
import bs4
from utils import setup_mock_browser
import sys

import bs4
import pytest
import setpath # noqa:F401, must come before 'import mechanicalsoup'
from utils import setup_mock_browser

import mechanicalsoup


def test_construct_form_fail():
Expand Down
22 changes: 10 additions & 12 deletions tests/test_stateful_browser.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import json
import os
import re
import sys
import tempfile
import json
import webbrowser

import pytest
import setpath # noqa:F401, must come before 'import mechanicalsoup'
import mechanicalsoup
import sys
import re
from bs4 import BeautifulSoup
from utils import (
setup_mock_browser,
prepare_mock_browser,
mock_get,
open_legacy_httpbin
)
import pytest
import webbrowser
from utils import (mock_get, open_legacy_httpbin, prepare_mock_browser,
setup_mock_browser)

import mechanicalsoup


def test_request_forward():
Expand Down
3 changes: 2 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import mechanicalsoup
import pytest

import mechanicalsoup


def test_LinkNotFoundError():
with pytest.raises(mechanicalsoup.LinkNotFoundError):
Expand Down
9 changes: 6 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import mechanicalsoup
import requests_mock
from distutils.version import StrictVersion
import bs4
from urllib.parse import parse_qsl

import bs4
import requests_mock

import mechanicalsoup


"""
Utilities for testing MechanicalSoup.
"""
Expand Down

0 comments on commit 0eb9495

Please sign in to comment.