Skip to content

Commit

Permalink
CLN/CI: import order
Browse files Browse the repository at this point in the history
  • Loading branch information
theOehrly committed Jan 1, 2024
1 parent 5c17e2b commit 110b5db
Show file tree
Hide file tree
Showing 54 changed files with 338 additions and 142 deletions.
34 changes: 31 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

import os

import pytest


def pytest_addoption(parser):
parser.addoption(
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))


Expand Down
15 changes: 9 additions & 6 deletions docs/contributing/devenv_setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://pre-commit.com/>`_ 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 <https://pre-commit.com/>`_ 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
26 changes: 26 additions & 0 deletions docs/contributing/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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/
3 changes: 2 additions & 1 deletion examples/example_fastf1_signalrclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions examples/plot_annotate_corners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions examples/plot_driver_laptimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions examples/plot_gear_shifts_on_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 4 additions & 2 deletions examples/plot_laptimes_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion examples/plot_position_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions examples/plot_speed_on_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion examples/plot_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions examples/plot_team_pace_ranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
21 changes: 12 additions & 9 deletions fastf1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]] = {
Expand Down
18 changes: 15 additions & 3 deletions fastf1/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
25 changes: 20 additions & 5 deletions fastf1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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] = \
Expand Down
9 changes: 5 additions & 4 deletions fastf1/ergast/__init__.py
Original file line number Diff line number Diff line change
@@ -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
)
Loading

0 comments on commit 110b5db

Please sign in to comment.