diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 80c7da08a..60990b265 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -91,7 +91,7 @@ jobs:
- name: Install python requirements
run: |
python -m pip install --upgrade pip
- python -m pip install --upgrade build setuptools twine
+ python -m pip install --upgrade build twine
python -m pip install -r requirements/dev.txt
- name: Install FastF1 from sources
@@ -100,12 +100,40 @@ jobs:
- name: Run tests
run: |
- mkdir test_cache # make sure cache dir exists
- git fetch origin --quiet
# ruff with default config
ruff check .
+ run-isort-test:
+ name: Test import order (isort)
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Setup python
+ uses: actions/setup-python@v4
+ with:
+ python-version: '3.12'
+
+ - name: Checkout repo
+ uses: actions/checkout@v4
+
+ - name: Cache pip
+ uses: actions/cache@v3
+ with:
+ path: ~/.cache/pip
+ key: pip-cache-${{ hashFiles('requirements/*.txt') }}
+ restore-keys: |
+ pip-cache
+
+ - name: Install python requirements
+ run: |
+ python -m pip install --upgrade pip
+ python -m pip install -r requirements/dev.txt
+
+ - name: Run isort (check only)
+ run: |
+ python -m isort . --check-only
+
run-readme-render-test:
name: Test readme renders on PyPi
runs-on: ubuntu-latest
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index f8f7dd1d8..c754851b0 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -5,3 +5,9 @@ repos:
hooks:
# Run the linter.
- id: ruff
+
+ - repo: https://github.com/pycqa/isort
+ rev: 5.13.2
+ hooks:
+ - id: isort
+ name: isort (python)
diff --git a/conftest.py b/conftest.py
index 7055fad37..c7aea6b3f 100644
--- a/conftest.py
+++ b/conftest.py
@@ -1,7 +1,7 @@
-import pytest
-
import os
+import pytest
+
def pytest_addoption(parser):
parser.addoption(
diff --git a/docs/conf.py b/docs/conf.py
index 7b7eb9293..2be55d70c 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -8,16 +8,17 @@
# import sys
# sys.path.insert(0, os.path.abspath('../'))
-from datetime import datetime
import os.path
import sys
import warnings
+from datetime import datetime
import plotly.io as pio
from plotly.io._sg_scraper import plotly_sg_scraper
import fastf1
+
sys.path.append(os.path.abspath('extensions'))
diff --git a/docs/contributing/devenv_setup.rst b/docs/contributing/devenv_setup.rst
index ad6fa1ca2..1bb8463d8 100644
--- a/docs/contributing/devenv_setup.rst
+++ b/docs/contributing/devenv_setup.rst
@@ -63,12 +63,15 @@ documentation, run the following command within the :file:`Fast-F1` directory::
python -m pip install -r requirements/dev.txt
-[Optional] Installing pre-commit hooks
-======================================
-You can optionally install `pre-commit `_ hooks.
-These will automatically check code style issues (using the ruff linter) when
-you run ``git commit``. The hooks are defined in the top level
-``.pre-commit-config.yaml`` file. To install the hooks ::
+
+.. _pre_commit_hooks:
+
+Installing pre-commit hooks
+===========================
+It is recommended to install `pre-commit `_ hooks.
+These will automatically check and partially fix code style issues (using the
+ruff linter and isort) when you run ``git commit``. The hooks are defined in
+the top level ``.pre-commit-config.yaml`` file. To install the hooks ::
pip install pre-commit
pre-commit install
diff --git a/docs/contributing/testing.rst b/docs/contributing/testing.rst
index b64e8c7ea..0025d6ed3 100644
--- a/docs/contributing/testing.rst
+++ b/docs/contributing/testing.rst
@@ -51,3 +51,29 @@ not need to be installed, but FastF1 should be)::
.. _command-line parameters: http://doc.pytest.org/en/latest/usage.html
+
+
+==========================
+Linting - Code style tests
+==========================
+
+FastF1 uses Ruff_ and isort_ to ensure that the code has a consistent style and
+is easily readable. All code should conform to the guidelines that are defined
+by PEP8_.
+
+To check whether your code is formatted correctly, run::
+
+ ruff check .
+
+
+To check and correct the import order, run::
+
+ python -m isort .
+
+If you have installed the :ref:`pre-commit hooks `,
+these commands will also be run automatically before each commit.
+
+
+.. _Ruff: https://docs.astral.sh/ruff/
+.. _isort: https://pycqa.github.io/isort/
+.. _PEP8: https://pep8.org/
\ No newline at end of file
diff --git a/examples/example_fastf1_signalrclient.py b/examples/example_fastf1_signalrclient.py
index 1bd77dcb2..f88579db3 100644
--- a/examples/example_fastf1_signalrclient.py
+++ b/examples/example_fastf1_signalrclient.py
@@ -3,9 +3,10 @@
Demonstrates the usage of the SignalRClient
"""
+import logging
+
from fastf1.livetiming.client import SignalRClient
-import logging
log = logging.getLogger()
log.setLevel(logging.DEBUG)
diff --git a/examples/plot_annotate_corners.py b/examples/plot_annotate_corners.py
index 8a576dbac..2931c1228 100644
--- a/examples/plot_annotate_corners.py
+++ b/examples/plot_annotate_corners.py
@@ -8,11 +8,11 @@
# Import FastF1 and load the data. Use the telemetry from the fastest for the
# track map. (You could also use any other lap instead.)
-import fastf1
-
import matplotlib.pyplot as plt
import numpy as np
+import fastf1
+
session = fastf1.get_session(2023, 'Silverstone', 'Q')
session.load()
diff --git a/examples/plot_driver_laptimes.py b/examples/plot_driver_laptimes.py
index 0305d2002..3b1ec0501 100755
--- a/examples/plot_driver_laptimes.py
+++ b/examples/plot_driver_laptimes.py
@@ -4,11 +4,13 @@
Plot a driver's lap times in a race, with color coding for the compounds.
"""
-import fastf1
-import fastf1.plotting
import seaborn as sns
from matplotlib import pyplot as plt
+import fastf1
+import fastf1.plotting
+
+
# The misc_mpl_mods option enables minor grid lines which clutter the plot
fastf1.plotting.setup_mpl(misc_mpl_mods=False)
diff --git a/examples/plot_gear_shifts_on_track.py b/examples/plot_gear_shifts_on_track.py
index c22d8db73..200de7bff 100644
--- a/examples/plot_gear_shifts_on_track.py
+++ b/examples/plot_gear_shifts_on_track.py
@@ -6,12 +6,12 @@
##############################################################################
# Import FastF1 and load the data
-import fastf1
-
import matplotlib.pyplot as plt
-from matplotlib.collections import LineCollection
-from matplotlib import colormaps
import numpy as np
+from matplotlib import colormaps
+from matplotlib.collections import LineCollection
+
+import fastf1
session = fastf1.get_session(2021, 'Austrian Grand Prix', 'Q')
diff --git a/examples/plot_laptimes_distribution.py b/examples/plot_laptimes_distribution.py
index 6c0735016..a269cb9f4 100755
--- a/examples/plot_laptimes_distribution.py
+++ b/examples/plot_laptimes_distribution.py
@@ -3,11 +3,13 @@
Visualizae different drivers' laptime distributions.
"""
-import fastf1
-import fastf1.plotting
import seaborn as sns
from matplotlib import pyplot as plt
+import fastf1
+import fastf1.plotting
+
+
# enabling misc_mpl_mods will turn on minor grid lines that clutters the plot
fastf1.plotting.setup_mpl(mpl_timedelta_support=False, misc_mpl_mods=False)
diff --git a/examples/plot_position_changes.py b/examples/plot_position_changes.py
index c2a803f9c..fff1726a4 100644
--- a/examples/plot_position_changes.py
+++ b/examples/plot_position_changes.py
@@ -5,9 +5,10 @@
Plot the position of each driver at the end of each lap.
"""
-import fastf1.plotting
import matplotlib.pyplot as plt
+import fastf1.plotting
+
fastf1.plotting.setup_mpl(misc_mpl_mods=False)
diff --git a/examples/plot_speed_on_track.py b/examples/plot_speed_on_track.py
index cbef8576c..91fb9acc9 100644
--- a/examples/plot_speed_on_track.py
+++ b/examples/plot_speed_on_track.py
@@ -3,13 +3,13 @@
(Example provided by @JSEHV on Github)
"""
-import fastf1 as ff1
-import numpy as np
import matplotlib as mpl
-
+import numpy as np
from matplotlib import pyplot as plt
from matplotlib.collections import LineCollection
+import fastf1 as ff1
+
##############################################################################
# First, we define some variables that allow us to conveniently control what
diff --git a/examples/plot_strategy.py b/examples/plot_strategy.py
index d9f40ebe0..ef33421a1 100644
--- a/examples/plot_strategy.py
+++ b/examples/plot_strategy.py
@@ -5,9 +5,11 @@
Plot all drivers' tyre strategies during a race.
"""
+from matplotlib import pyplot as plt
+
import fastf1
import fastf1.plotting
-from matplotlib import pyplot as plt
+
###############################################################################
# Load the race session
diff --git a/examples/plot_team_pace_ranking.py b/examples/plot_team_pace_ranking.py
index d5d7f3718..256fb176d 100755
--- a/examples/plot_team_pace_ranking.py
+++ b/examples/plot_team_pace_ranking.py
@@ -3,11 +3,13 @@
Rank team's race pace from the fastest to the slowest.
"""
-import fastf1
-import fastf1.plotting
import seaborn as sns
from matplotlib import pyplot as plt
+import fastf1
+import fastf1.plotting
+
+
# activate the fastf1 color scheme (and no other modifications)
fastf1.plotting.setup_mpl(mpl_timedelta_support=False, misc_mpl_mods=False)
diff --git a/fastf1/__init__.py b/fastf1/__init__.py
index 49f237264..4774166ed 100644
--- a/fastf1/__init__.py
+++ b/fastf1/__init__.py
@@ -99,16 +99,19 @@
from typing import Dict
-from fastf1.events import (get_session, # noqa: F401
- get_testing_session,
- get_event,
- get_events_remaining,
- get_testing_event,
- get_event_schedule)
-
+from fastf1.events import get_session # noqa: F401
+from fastf1.events import ( # noqa: F401
+ get_event,
+ get_event_schedule,
+ get_events_remaining,
+ get_testing_event,
+ get_testing_session
+)
from fastf1.logger import set_log_level # noqa: F401
-
-from fastf1.req import Cache, RateLimitExceededError # noqa: F401
+from fastf1.req import ( # noqa: F401
+ Cache,
+ RateLimitExceededError
+)
_DRIVER_TEAM_MAPPING: Dict[str, Dict[str, str]] = {
diff --git a/fastf1/_api.py b/fastf1/_api.py
index a2308e51e..344d50f10 100644
--- a/fastf1/_api.py
+++ b/fastf1/_api.py
@@ -2,15 +2,27 @@
import datetime
import json
import zlib
-from typing import Dict, Optional, Union
+from typing import (
+ Dict,
+ Optional,
+ Union
+)
import numpy as np
import pandas as pd
from fastf1.internals.pandas_extensions import create_df_fast
-from fastf1.logger import get_logger, soft_exceptions
+from fastf1.logger import (
+ get_logger,
+ soft_exceptions
+)
from fastf1.req import Cache
-from fastf1.utils import recursive_dict_get, to_timedelta, to_datetime
+from fastf1.utils import (
+ recursive_dict_get,
+ to_datetime,
+ to_timedelta
+)
+
_logger = get_logger('api')
diff --git a/fastf1/core.py b/fastf1/core.py
index bdd3c2eb8..06b65da92 100644
--- a/fastf1/core.py
+++ b/fastf1/core.py
@@ -41,10 +41,18 @@
"""
import collections
import re
-from functools import cached_property
-import warnings
import typing
-from typing import Optional, List, Literal, Iterable, Union, Tuple, Any
+import warnings
+from functools import cached_property
+from typing import (
+ Any,
+ Iterable,
+ List,
+ Literal,
+ Optional,
+ Tuple,
+ Union
+)
import numpy as np
import pandas as pd
@@ -53,10 +61,17 @@
from fastf1 import _api as api
from fastf1 import ergast
from fastf1.livetiming.data import LiveTimingData
-from fastf1.mvapi import get_circuit_info, CircuitInfo
-from fastf1.logger import get_logger, soft_exceptions
+from fastf1.logger import (
+ get_logger,
+ soft_exceptions
+)
+from fastf1.mvapi import (
+ CircuitInfo,
+ get_circuit_info
+)
from fastf1.utils import to_timedelta
+
_logger = get_logger(__name__)
D_LOOKUP: List[List] = \
diff --git a/fastf1/ergast/__init__.py b/fastf1/ergast/__init__.py
index 9e4cb95a3..925771b0f 100644
--- a/fastf1/ergast/__init__.py
+++ b/fastf1/ergast/__init__.py
@@ -1,6 +1,7 @@
# imports for exposed names
from fastf1.ergast.interface import Ergast # noqa: F401
-from fastf1.ergast.legacy import \
- fetch_day, \
- fetch_season, \
- fetch_results # noqa: F401
+from fastf1.ergast.legacy import fetch_results # noqa: F401
+from fastf1.ergast.legacy import ( # noqa: F401
+ fetch_day,
+ fetch_season
+)
diff --git a/fastf1/ergast/interface.py b/fastf1/ergast/interface.py
index f5c60466b..b9fb70ed6 100644
--- a/fastf1/ergast/interface.py
+++ b/fastf1/ergast/interface.py
@@ -1,13 +1,17 @@
import copy
import json
-from typing import List, Literal, Optional, Union
+from typing import (
+ List,
+ Literal,
+ Optional,
+ Union
+)
+import pandas as pd
+
+import fastf1.ergast.structure as API
from fastf1 import __version_short__
from fastf1.req import Cache
-import fastf1.ergast.structure as API
-
-
-import pandas as pd
BASE_URL = 'https://ergast.com/api/f1'
diff --git a/fastf1/ergast/legacy.py b/fastf1/ergast/legacy.py
index b22a3b889..ee0a122d2 100644
--- a/fastf1/ergast/legacy.py
+++ b/fastf1/ergast/legacy.py
@@ -1,9 +1,9 @@
import json
import warnings
-from fastf1.req import Cache
from fastf1.ergast.interface import BASE_URL as base_url
from fastf1.ergast.interface import HEADERS as _headers
+from fastf1.req import Cache
def fetch_results(year, gp, session):
diff --git a/fastf1/ergast/sphinx.py b/fastf1/ergast/sphinx.py
index 2e880f53d..94d71bcd8 100644
--- a/fastf1/ergast/sphinx.py
+++ b/fastf1/ergast/sphinx.py
@@ -1,12 +1,16 @@
-import pandas as pd
-from docutils import nodes
-from docutils.parsers.rst import Directive, directives
import json
from typing import get_type_hints
+import pandas as pd
+from docutils import nodes
+from docutils.parsers.rst import (
+ Directive,
+ directives
+)
+
+import fastf1.ergast.structure
from fastf1 import __version__
from fastf1.ergast.interface import ErgastResultFrame
-import fastf1.ergast.structure
class ApiMappingDirective(Directive):
diff --git a/fastf1/events.py b/fastf1/events.py
index 473bd633a..c85714149 100644
--- a/fastf1/events.py
+++ b/fastf1/events.py
@@ -163,10 +163,15 @@
import datetime
import json
import warnings
-from typing import Literal, Union, Optional
+from typing import (
+ Literal,
+ Optional,
+ Union
+)
import dateutil.parser
+
with warnings.catch_warnings():
warnings.filterwarnings(
'ignore', message="Using slow pure-python SequenceMatcher"
@@ -178,11 +183,18 @@
import pandas as pd
import fastf1._api
-from fastf1.core import Session
import fastf1.ergast
-from fastf1.logger import get_logger, soft_exceptions
+from fastf1.core import Session
+from fastf1.logger import (
+ get_logger,
+ soft_exceptions
+)
from fastf1.req import Cache
-from fastf1.utils import recursive_dict_get, to_datetime, to_timedelta
+from fastf1.utils import (
+ recursive_dict_get,
+ to_datetime,
+ to_timedelta
+)
_logger = get_logger(__name__)
diff --git a/fastf1/internals/__init__.py b/fastf1/internals/__init__.py
index d98cb2177..5c838a6bd 100644
--- a/fastf1/internals/__init__.py
+++ b/fastf1/internals/__init__.py
@@ -1,3 +1,4 @@
from fastf1.logger import get_logger
+
internals_logger = get_logger(__name__)
diff --git a/fastf1/internals/pandas_extensions.py b/fastf1/internals/pandas_extensions.py
index a71f99aef..90d6a6891 100644
--- a/fastf1/internals/pandas_extensions.py
+++ b/fastf1/internals/pandas_extensions.py
@@ -1,19 +1,24 @@
-from fastf1.internals import internals_logger as logger
-
from typing import List
import numpy as np
+from pandas import (
+ DataFrame,
+ Index,
+ RangeIndex
+)
+
+from fastf1.internals import internals_logger as logger
+
-from pandas import DataFrame, Index, RangeIndex
try:
# import internal pandas functions and objects
- from pandas.core.internals.construction import \
- _get_axes, \
- BlockPlacement, \
- create_block_manager_from_blocks, \
+ from pandas.core.internals.construction import (
+ BlockPlacement,
+ _get_axes,
+ create_block_manager_from_blocks,
new_block_2d
- from pandas.core.internals.managers import \
- _consolidate
+ )
+ from pandas.core.internals.managers import _consolidate
# verify existence of non-public methods of public objects
if not hasattr(Index, '_with_infer'):
diff --git a/fastf1/livetiming/__main__.py b/fastf1/livetiming/__main__.py
index cc9f1a320..db2741c2d 100644
--- a/fastf1/livetiming/__main__.py
+++ b/fastf1/livetiming/__main__.py
@@ -1,6 +1,10 @@
import argparse
import sys
-from fastf1.livetiming.client import SignalRClient, messages_from_raw
+
+from fastf1.livetiming.client import (
+ SignalRClient,
+ messages_from_raw
+)
def save(args):
diff --git a/fastf1/livetiming/client.py b/fastf1/livetiming/client.py
index cac6b6297..7a8261a60 100644
--- a/fastf1/livetiming/client.py
+++ b/fastf1/livetiming/client.py
@@ -2,13 +2,16 @@
import concurrent.futures
import json
import logging
-import requests
import time
-from typing import Iterable, Optional
+from typing import (
+ Iterable,
+ Optional
+)
-from fastf1.signalr_aio import Connection
+import requests
import fastf1
+from fastf1.signalr_aio import Connection
def messages_from_raw(r: Iterable):
diff --git a/fastf1/livetiming/data.py b/fastf1/livetiming/data.py
index bbd181c4d..e09e5508d 100644
--- a/fastf1/livetiming/data.py
+++ b/fastf1/livetiming/data.py
@@ -2,12 +2,15 @@
Data object for livetiming data
"""
-from datetime import timedelta
-import json
import hashlib
+import json
+from datetime import timedelta
from fastf1.logger import get_logger
-from fastf1.utils import to_datetime, recursive_dict_get
+from fastf1.utils import (
+ recursive_dict_get,
+ to_datetime
+)
_logger = get_logger(__name__)
diff --git a/fastf1/logger.py b/fastf1/logger.py
index 226cdc46e..7f674f040 100644
--- a/fastf1/logger.py
+++ b/fastf1/logger.py
@@ -40,9 +40,8 @@
import functools
import logging
-import warnings
import os
-
+import warnings
from typing import Union
diff --git a/fastf1/mvapi/__init__.py b/fastf1/mvapi/__init__.py
index 7d80f1ef8..391011153 100644
--- a/fastf1/mvapi/__init__.py
+++ b/fastf1/mvapi/__init__.py
@@ -1 +1,4 @@
-from fastf1.mvapi.data import get_circuit_info, CircuitInfo # noqa F401
+from fastf1.mvapi.data import ( # noqa F401
+ CircuitInfo,
+ get_circuit_info
+)
diff --git a/fastf1/mvapi/api.py b/fastf1/mvapi/api.py
index c07864cf4..6dc220710 100644
--- a/fastf1/mvapi/api.py
+++ b/fastf1/mvapi/api.py
@@ -1,11 +1,12 @@
-import requests.exceptions
-
from typing import Optional
+import requests.exceptions
+
from fastf1 import __version_short__
from fastf1.mvapi.internals import _logger
from fastf1.req import Cache
+
PROTO = "https"
HOST = "api.multiviewer.app"
HEADERS = {'User-Agent': f'FastF1/{__version_short__}'}
diff --git a/fastf1/mvapi/data.py b/fastf1/mvapi/data.py
index 9f2888468..58bd81900 100644
--- a/fastf1/mvapi/data.py
+++ b/fastf1/mvapi/data.py
@@ -1,13 +1,13 @@
-import fastf1.core
-from fastf1.mvapi.internals import _logger
-from fastf1.mvapi.api import get_circuit
-
from dataclasses import dataclass
from typing import Optional
import numpy as np
import pandas as pd
+import fastf1.core
+from fastf1.mvapi.api import get_circuit
+from fastf1.mvapi.internals import _logger
+
@dataclass
class CircuitInfo:
diff --git a/fastf1/mvapi/internals.py b/fastf1/mvapi/internals.py
index d24ec42c0..dea1a08df 100644
--- a/fastf1/mvapi/internals.py
+++ b/fastf1/mvapi/internals.py
@@ -1,3 +1,4 @@
from fastf1.logger import get_logger
+
_logger = get_logger('mvapi')
diff --git a/fastf1/plotting.py b/fastf1/plotting.py
index d22454ee5..ff8821f61 100644
--- a/fastf1/plotting.py
+++ b/fastf1/plotting.py
@@ -21,16 +21,20 @@
.. note:: Plotting related functionality is likely to change in a future
release.
"""
-from typing import Dict, List
+import warnings
+from typing import (
+ Dict,
+ List
+)
-import pandas as pd
import numpy as np
-import warnings
+import pandas as pd
+
try:
import matplotlib
- from matplotlib import pyplot as plt
from matplotlib import cycler
+ from matplotlib import pyplot as plt
except ImportError:
warnings.warn("Failed to import optional dependency 'matplotlib'!"
"Plotting functionality will be unavailable!", UserWarning)
@@ -43,6 +47,7 @@
import warnings
+
with warnings.catch_warnings():
warnings.filterwarnings('ignore',
message="Using slow pure-python SequenceMatcher")
diff --git a/fastf1/req.py b/fastf1/req.py
index 1796a71b4..9e2ab4a1a 100644
--- a/fastf1/req.py
+++ b/fastf1/req.py
@@ -25,8 +25,8 @@
import functools
import math
import os
-import re
import pickle
+import re
import sys
import time
from typing import Optional
diff --git a/fastf1/signalr_aio/transports/_parameters.py b/fastf1/signalr_aio/transports/_parameters.py
index 96983b09d..56ff9bfe5 100644
--- a/fastf1/signalr_aio/transports/_parameters.py
+++ b/fastf1/signalr_aio/transports/_parameters.py
@@ -2,7 +2,12 @@
# -*- coding: utf-8 -*-
from json import dumps
-from urllib.parse import urlparse, urlunparse, urlencode
+from urllib.parse import (
+ urlencode,
+ urlparse,
+ urlunparse
+)
+
import requests
diff --git a/fastf1/signalr_aio/transports/_transport.py b/fastf1/signalr_aio/transports/_transport.py
index 6c2dfdf21..ec0edd4a7 100644
--- a/fastf1/signalr_aio/transports/_transport.py
+++ b/fastf1/signalr_aio/transports/_transport.py
@@ -10,17 +10,27 @@
# -----------------------------------
# Internal Imports
from ._parameters import WebSocketParameters
-from ._queue_events import InvokeEvent, CloseEvent
+from ._queue_events import (
+ CloseEvent,
+ InvokeEvent
+)
+
# -----------------------------------
# External Imports
try:
- from ujson import dumps, loads
+ from ujson import (
+ dumps,
+ loads
+ )
except ModuleNotFoundError:
from json import dumps, loads
-import websockets
+
import asyncio
+import websockets
+
+
try:
import uvloop
diff --git a/fastf1/testing/manual_test_all.py b/fastf1/testing/manual_test_all.py
index fff94bcac..d59b34287 100644
--- a/fastf1/testing/manual_test_all.py
+++ b/fastf1/testing/manual_test_all.py
@@ -4,9 +4,10 @@
Any occurring exceptions will be caught and written to a log file.
"""
-import fastf1 as ff1
import traceback
+import fastf1 as ff1
+
# GPs 2019
# NOTES
diff --git a/fastf1/tests/test_api.py b/fastf1/tests/test_api.py
index 9a3f5d7a9..aa0c42c9a 100644
--- a/fastf1/tests/test_api.py
+++ b/fastf1/tests/test_api.py
@@ -1,12 +1,11 @@
-import pytest
-
import datetime
import numpy as np
import pandas as pd
+import pytest
-from fastf1 import Cache
import fastf1._api
+from fastf1 import Cache
def test_timing_data():
diff --git a/fastf1/tests/test_cache.py b/fastf1/tests/test_cache.py
index 7b976a318..5c0e04d0d 100644
--- a/fastf1/tests/test_cache.py
+++ b/fastf1/tests/test_cache.py
@@ -2,9 +2,9 @@
import os
import fastf1._api
+import fastf1.testing
from fastf1 import Cache
from fastf1.logger import LoggingManager
-import fastf1.testing
def test_enable_cache(tmpdir):
@@ -23,9 +23,10 @@ def _test_cache_used_and_clear(tmpdir):
# this test requires using requests_mock to allow running offline
# other tests can depend on fastf1's internal cache (which is tested here)
# for offline running, after they've had one online run
- import fastf1
import requests_mock
+ import fastf1
+
with requests_mock.Mocker() as mocker:
# create a custom requests session here so that requests_mock is
# properly used
diff --git a/fastf1/tests/test_core.py b/fastf1/tests/test_core.py
index 5294577ad..e1b3a0382 100644
--- a/fastf1/tests/test_core.py
+++ b/fastf1/tests/test_core.py
@@ -1,9 +1,13 @@
-import pytest
-
import pandas as pd
+import pytest
import fastf1
-from fastf1.core import DriverResult, Lap, Laps, SessionResults
+from fastf1.core import (
+ DriverResult,
+ Lap,
+ Laps,
+ SessionResults
+)
from fastf1.ergast import Ergast
diff --git a/fastf1/tests/test_ergast.py b/fastf1/tests/test_ergast.py
index 85619a7ad..94e277ac3 100644
--- a/fastf1/tests/test_ergast.py
+++ b/fastf1/tests/test_ergast.py
@@ -1,24 +1,24 @@
+import datetime
import logging
import pandas as pd
import pytest
-import datetime
-
-from fastf1.ergast.interface import \
- Ergast, \
- ErgastResponseMixin, \
- ErgastResultFrame, \
- ErgastResultSeries, \
- ErgastRawResponse
-
import fastf1.ergast.structure as API
-from fastf1.ergast.structure import \
- date_from_ergast, \
- time_from_ergast, \
- timedelta_from_ergast, \
- save_int, \
- save_float
+from fastf1.ergast.interface import (
+ Ergast,
+ ErgastRawResponse,
+ ErgastResponseMixin,
+ ErgastResultFrame,
+ ErgastResultSeries
+)
+from fastf1.ergast.structure import (
+ date_from_ergast,
+ save_float,
+ save_int,
+ time_from_ergast,
+ timedelta_from_ergast
+)
# ############### test structure.py #################################
diff --git a/fastf1/tests/test_example_plots.py b/fastf1/tests/test_example_plots.py
index 0c8ee556e..454b0a4b8 100644
--- a/fastf1/tests/test_example_plots.py
+++ b/fastf1/tests/test_example_plots.py
@@ -1,11 +1,11 @@
import pytest
-
from matplotlib import pyplot as plt
import fastf1
import fastf1.plotting
import fastf1.utils
+
fastf1.plotting.setup_mpl()
# generate baseline with
diff --git a/fastf1/tests/test_input_data_handling.py b/fastf1/tests/test_input_data_handling.py
index 108f8f0e6..3e5304e3a 100644
--- a/fastf1/tests/test_input_data_handling.py
+++ b/fastf1/tests/test_input_data_handling.py
@@ -1,10 +1,9 @@
# test some known special cases
-import pytest
-
import logging
import pandas as pd
+import pytest
import fastf1
import fastf1.ergast
diff --git a/fastf1/tests/test_internals.py b/fastf1/tests/test_internals.py
index 184944fcc..87134198e 100644
--- a/fastf1/tests/test_internals.py
+++ b/fastf1/tests/test_internals.py
@@ -1,8 +1,8 @@
-from fastf1.internals.pandas_extensions import _unsafe_create_df_fast
-
import numpy as np
import pandas as pd
+from fastf1.internals.pandas_extensions import _unsafe_create_df_fast
+
def test_fast_df_creation():
data = {'A': [1, 2, 3], 'B': [1.0, 2.0, 3.0], 3: ['a', 'b', 'c']}
diff --git a/fastf1/tests/test_laps.py b/fastf1/tests/test_laps.py
index d36f98c26..8d88f823a 100644
--- a/fastf1/tests/test_laps.py
+++ b/fastf1/tests/test_laps.py
@@ -1,12 +1,14 @@
-import pytest
-
import datetime
-import pandas as pd
import pandas
+import pandas as pd
+import pytest
import fastf1
-from fastf1.testing.reference_values import LAP_DTYPES, ensure_data_type
+from fastf1.testing.reference_values import (
+ LAP_DTYPES,
+ ensure_data_type
+)
def test_constructor():
diff --git a/fastf1/tests/test_laps_summary.py b/fastf1/tests/test_laps_summary.py
index 46634e85f..93e90d5fe 100644
--- a/fastf1/tests/test_laps_summary.py
+++ b/fastf1/tests/test_laps_summary.py
@@ -1,6 +1,7 @@
# test api laps data stuff; only make sure that nothing crashes
import pytest
+
import fastf1 as ff1
diff --git a/fastf1/tests/test_plotting.py b/fastf1/tests/test_plotting.py
index 57049bf58..84b8a01e0 100644
--- a/fastf1/tests/test_plotting.py
+++ b/fastf1/tests/test_plotting.py
@@ -1,5 +1,11 @@
import pytest
-from fastf1.plotting import TEAM_COLORS, TEAM_TRANSLATE, DRIVER_TRANSLATE, DRIVER_COLORS
+
+from fastf1.plotting import (
+ DRIVER_COLORS,
+ DRIVER_TRANSLATE,
+ TEAM_COLORS,
+ TEAM_TRANSLATE
+)
def test_team_colors_dict_warning():
diff --git a/fastf1/tests/test_project_structure.py b/fastf1/tests/test_project_structure.py
index 1a7e422ab..57c5d6cc1 100644
--- a/fastf1/tests/test_project_structure.py
+++ b/fastf1/tests/test_project_structure.py
@@ -1,6 +1,8 @@
-import pytest
import subprocess
+import pytest
+
+
pytestmark = pytest.mark.prjdoc
diff --git a/fastf1/tests/test_telemetry.py b/fastf1/tests/test_telemetry.py
index 15cf53dd5..3bb6ab0f0 100644
--- a/fastf1/tests/test_telemetry.py
+++ b/fastf1/tests/test_telemetry.py
@@ -1,11 +1,13 @@
-import pytest
-
-import pandas
import numpy
+import pandas
+import pytest
import fastf1.core
-from fastf1.testing.reference_values import \
- (CAR_DATA_DTYPES, POS_DATA_DTYPES, ensure_data_type)
+from fastf1.testing.reference_values import (
+ CAR_DATA_DTYPES,
+ POS_DATA_DTYPES,
+ ensure_data_type
+)
def test_constructor():
diff --git a/fastf1/tests/test_utils.py b/fastf1/tests/test_utils.py
index 7debcef6a..a512b3892 100644
--- a/fastf1/tests/test_utils.py
+++ b/fastf1/tests/test_utils.py
@@ -1,6 +1,9 @@
import datetime
-from fastf1.utils import to_datetime, to_timedelta
+from fastf1.utils import (
+ to_datetime,
+ to_timedelta
+)
def test_to_timedelta():
diff --git a/fastf1/utils.py b/fastf1/utils.py
index 55ad749b2..0b0187d4f 100644
--- a/fastf1/utils.py
+++ b/fastf1/utils.py
@@ -1,8 +1,13 @@
"""This is a collection of various functions."""
import datetime
-from functools import reduce
-from typing import Dict, Tuple, Optional, Union
import warnings
+from functools import reduce
+from typing import (
+ Dict,
+ Optional,
+ Tuple,
+ Union
+)
import numpy as np
import pandas as pd
diff --git a/pyproject.toml b/pyproject.toml
index 4e128dfad..9616e31d0 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -87,3 +87,8 @@ exclude = [
[tool.ruff.per-file-ignores]
"fastf1/_api.py" = ["E501"]
+
+[tool.isort]
+multi_line_output = 3
+force_grid_wrap = 2
+lines_after_imports = 2
diff --git a/requirements/dev.txt b/requirements/dev.txt
index e0f12108b..a0f465cfd 100644
--- a/requirements/dev.txt
+++ b/requirements/dev.txt
@@ -1,5 +1,6 @@
autodocsumm>=0.2.10 # support for sphinx v6
furo
+isort
kaleido
plotly
pre-commit