Skip to content

Commit

Permalink
Convert flake8 to ruff (#3855)
Browse files Browse the repository at this point in the history
* Final ruff fixes

* Added fixes

* Removed fixes

* Updated dependencies

* More updates

* revert test change

* Added fixes

* Final change

Co-authored-by: James Maslek <jmaslek11@gmail.com>
  • Loading branch information
colin99d and jmaslek authored Jan 4, 2023
1 parent 052c16f commit be2c2a3
Show file tree
Hide file tree
Showing 14 changed files with 2,247 additions and 293 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ jobs:
key: ${{ runner.os }}-linting-${{ hashFiles('**/poetry.lock') }}
restore-keys: ${{ runner.os }}-linting-${{ hashFiles('**/poetry.lock') }}

- run: pip install bandit black codespell flake8 mypy==0.982 pyupgrade safety pylint==2.15.2 packaging==22
- run: pip install bandit black codespell mypy==0.982 pyupgrade safety pylint==2.15.2 packaging==22 ruff
- run: pip install types-pytz types-requests types-termcolor types-tabulate types-PyYAML types-python-dateutil types-setuptools types-six
- run: bandit -x ./tests -r . || true
- run: black --diff --check .
- run: codespell --ignore-words-list=commun,statics,ro,zar,zlot,jewl,ba,buil,coo,ether,hist,hsi,mape,navagation,operatio,pres,ser,yeld,shold,ist,varian,datas,ake,creat,vie,hel,ket,toke,certi,buidl,ot,te --quiet-level=2 --skip=./tests,.git,*.css,*.csv,*.html,*.ini,*.ipynb,*.js,*.json,*.lock,*.scss,*.txt,*.yaml,./build/pyinstaller,./website/config.toml
- run: flake8 . --count --ignore=E203,W503 --max-line-length=122 --show-source --statistics --exclude ./build/pyinstaller,./website/content
- run: ruff .
- run: mypy --ignore-missing-imports openbb_terminal
- run: shopt -s globstar && pyupgrade --py38-plus **/*.py
- run: safety check
Expand Down
9 changes: 4 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ repos:
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.209'
hooks:
- id: flake8
entry: flake8 --ignore=E203,W503 --max-line-length=122 --exclude ./build/pyinstaller/*
- id: ruff
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell
entry: codespell
args:
[
"--ignore-words-list=te,commun,ro,zar,vie,hel,jewl,zlot,ba,buil,coo,ether,hist,hsi,mape,navagation,operatio,pres,ser,yeld,shold,ist,varian,datas,ake,creat,statics,ket,toke,certi,buidl",
"--ignore-words-list=te,commun,ro,zar,vie,hel,jewl,zlot,ba,buil,coo,ether,hist,hsi,mape,navagation,operatio,pres,ser,yeld,shold,ist,varian,datas,ake,creat,statics,ket,toke,certi,buidl,ot",
"--quiet-level=2",
"--skip=./tests,.git,*.css,*.csv,*.html,*.ini,*.ipynb,*.js,*.json,*.lock,*.scss,*.txt,*.yaml,build/pyinstaller/*,./website/config.toml",
]
Expand Down
6 changes: 3 additions & 3 deletions openbb_terminal/cryptocurrency/due_diligence/dd_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def call_eb(self, other_args: List[str]):
@log_start_end(log=logger)
def call_oi(self, other_args):
"""Process oi command"""
assert isinstance(self.symbol, str)
assert isinstance(self.symbol, str) # noqa: S101
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Expand Down Expand Up @@ -533,7 +533,7 @@ def call_oi(self, other_args):
@log_start_end(log=logger)
def call_liquidations(self, other_args):
"""Process liquidations command"""
assert isinstance(self.symbol, str)
assert isinstance(self.symbol, str) # noqa: S101
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Expand All @@ -557,7 +557,7 @@ def call_liquidations(self, other_args):
@log_start_end(log=logger)
def call_fundrate(self, other_args):
"""Process fundrate command"""
assert isinstance(self.symbol, str)
assert isinstance(self.symbol, str) # noqa: S101
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Expand Down
4 changes: 2 additions & 2 deletions openbb_terminal/custom_prompt_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(
pattern: Optional[Pattern[str]] = None,
) -> None:

assert not (WORD and sentence)
assert not (WORD and sentence) # noqa: S101

self.words = words
self.ignore_case = ignore_case
Expand Down Expand Up @@ -177,7 +177,7 @@ def from_nested_dict(cls, data: dict) -> "NestedCompleter":
elif isinstance(key, str) and isinstance(value, str):
options[key] = options[value]
else:
assert value is None
assert value is None # noqa: S101
options[key] = None

for items in cls.complementary:
Expand Down
2 changes: 1 addition & 1 deletion openbb_terminal/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def log_start_end(func=None, log=None):
-------
Wrapped function
"""
assert callable(func) or func is None # nosec
assert callable(func) or func is None # noqa: S101

def decorator(func):
@functools.wraps(func)
Expand Down
4 changes: 4 additions & 0 deletions openbb_terminal/economy/economy_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from openbb_terminal.rich_config import console


def text_transform(raw_text: str) -> str:
return f"{round(float(raw_text)/100, 3)}%"


def create_new_entry(dataset: Dict[str, pd.DataFrame], query: str) -> Dict:
"""Create a new series based off previously loaded columns
Expand Down
4 changes: 1 addition & 3 deletions openbb_terminal/economy/investingcom_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from openbb_terminal.config_terminal import theme
from openbb_terminal.decorators import log_start_end
from openbb_terminal.economy import investingcom_model
from openbb_terminal.economy.economy_helpers import text_transform
from openbb_terminal.helper_funcs import (
export_data,
plot_autoscale,
Expand Down Expand Up @@ -185,9 +186,6 @@ def truncate_colormap(cmap, minval=0.0, maxval=1.0, n=100):
k += spacing
spacing -= 1

text_transform = (
lambda x: f"{round(float(x)/100, 3)}%"
) # flake8: noqa
t.set_text(text_transform(current_text))
else:
t.set_text(current_text)
Expand Down
8 changes: 7 additions & 1 deletion openbb_terminal/forecast/brnn_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ def get_brnn_data(
Returns
-------
Tuple[List[TimeSeries], List[TimeSeries], List[TimeSeries], Optional[Union[float, ndarray]], type[GlobalForecastingModel]] # noqa: E501
Tuple[
List[TimeSeries],
List[TimeSeries],
List[TimeSeries],
Optional[Union[float, ndarray]],
type[GlobalForecastingModel]
]
Adjusted Data series,
Historical forecast by best RNN model,
list of Predictions,
Expand Down
6 changes: 3 additions & 3 deletions openbb_terminal/reports/reports_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ def call_forecast(self, other_args: List[str]):
# return

try:
import darts # pyright: reportMissingImports=false # noqa: F401, E501 #pylint: disable=import-outside-toplevel, unused-import
from darts import ( # pyright: reportMissingImports=false # noqa: F401, E501 #pylint: disable=import-outside-toplevel, unused-import
utils,
import darts # pyright: reportMissingImports=false # noqa: F401, E501 # pylint: disable=C0415, W0611
from darts import ( # pyright: reportMissingImports=false, pylint: disable=C0415, W0611
utils, # noqa: F401, E501
)

FORECASTING_TOOLKIT_ENABLED = True
Expand Down
4 changes: 2 additions & 2 deletions openbb_terminal/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from openbb_terminal.helper_classes import TerminalStyle
from openbb_terminal import helper_funcs as helper # noqa: F401
from openbb_terminal.reports import widget_helpers as widgets # noqa: F401
from openbb_terminal.cryptocurrency.due_diligence.pycoingecko_model import ( # noqa: F401
Coin,
from openbb_terminal.cryptocurrency.due_diligence.pycoingecko_model import (
Coin, # noqa: F401
)

from openbb_terminal.core.library.breadcrumb import Breadcrumb
Expand Down
Loading

0 comments on commit be2c2a3

Please sign in to comment.