Convert flake8 to ruff (#3855)

* 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>
This commit is contained in:
Colin Delahunty
2023-01-04 10:21:31 -05:00
committed by GitHub
parent 052c16f87e
commit be2c2a33d7
14 changed files with 2247 additions and 293 deletions

View File

@@ -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

View File

@@ -13,11 +13,10 @@ 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:
@@ -25,7 +24,7 @@ repos:
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",
]

View File

@@ -498,7 +498,7 @@ class DueDiligenceController(CryptoBaseController):
@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,
@@ -533,7 +533,7 @@ class DueDiligenceController(CryptoBaseController):
@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,
@@ -557,7 +557,7 @@ class DueDiligenceController(CryptoBaseController):
@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,

View File

@@ -53,7 +53,7 @@ class WordCompleter(Completer):
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
@@ -177,7 +177,7 @@ class NestedCompleter(Completer):
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:

View File

@@ -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)

View File

@@ -8,6 +8,10 @@ import pandas as pd
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

View File

@@ -18,6 +18,7 @@ from openbb_terminal.config_plot import PLOT_DPI
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,
@@ -185,9 +186,6 @@ def display_spread_matrix(
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)

View File

@@ -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,

View File

@@ -150,9 +150,9 @@ class ReportController(BaseController):
# 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

View File

@@ -3,8 +3,8 @@ from openbb_terminal.config_terminal import theme # noqa: F401
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

2450
poetry.lock generated vendored

File diff suppressed because it is too large Load Diff

21
pyproject.toml vendored
View File

@@ -112,7 +112,6 @@ packaging = ">=22.0"
[tool.poetry.dev-dependencies]
pytest = "^6.2.2"
pylint = "2.15.2"
flake8 = "^3.9.0"
mypy = "^0.930"
mock = "^4.0.3"
codespell = "^2.0.0"
@@ -134,6 +133,7 @@ pre-commit = "^2.16.0"
pytest-cov = "^3.0.0"
types-six = "^1.16.12"
nbmake = ">0.5.0"
ruff = "^0.0.210"
[tool.poetry.extras]
prediction = ["torch", "pytorch-lightning", "u8darts"]
@@ -150,3 +150,22 @@ build-backend = "poetry.core.masonry.api"
[tool.pydocstyle]
convention = "numpy"
match = '((?!test_).)*\.py'
[tool.ruff]
line-length = 122
target-version = "py38"
# This is an introductory addition of ruff. We should look to adding:
# D: pydocstyle, PD: pandas-vet, I: isort
# All options here: https://github.com/charliermarsh/ruff#supported-rules
select = ["E", "W", "F", "Q", "W", "S", "UP"]
ignore = ["S105", "S106", "S107"]
[tool.ruff.per-file-ignores]
"tests/*" = ["S101"]
[tool.ruff.flake8-import-conventions.aliases]
"matplotlib.pyplot" = "plt"
numpy = "np"
pandas = "pd"
seaborn = "sns"

16
requirements-full.txt vendored
View File

@@ -8,13 +8,11 @@ altair==4.2.0; python_version >= "3.7" and python_full_version < "3.9.7" or pyth
anyio==3.6.2; python_full_version >= "3.6.2" and python_version >= "3.8" and python_version < "4.0"
appdirs==1.4.4
appnope==0.1.3; sys_platform == "darwin" and python_version >= "3.8" and platform_system == "Darwin" and python_full_version >= "3.7.0" and python_full_version < "4.0.0"
arch==5.3.1; python_version >= "3.7"
argon2-cffi-bindings==21.2.0; python_version >= "3.7"
argon2-cffi==21.3.0; python_version >= "3.7"
ascii-magic==1.6; python_version >= "3.5"
astor==0.8.1; python_full_version >= "3.7.1" and python_full_version < "4.0.0" and python_version >= "3.8"
astroid==2.12.12; python_full_version >= "3.7.2"
astropy==5.1.1; python_version >= "3.8"
asttokens==2.0.8; python_version >= "3.8"
async-timeout==4.0.2; python_version >= "3.6" and python_full_version >= "3.7.0"
atomicwrites==1.4.1; sys_platform == "win32" and python_version >= "3.7" and python_full_version >= "3.7.0" and python_full_version < "4.0.0"
@@ -49,7 +47,6 @@ convertdate==2.4.0; python_version >= "3.7" and python_version < "4"
coverage==6.5.0; python_version >= "3.7"
cryptography==38.0.2; python_version >= "3.6"
cssselect==1.1.0; python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.4.0"
cvxpy==1.2.1; python_version >= "3.7"
cycler==0.11.0; python_version >= "3.7"
cython==0.29.32; python_version >= "3.8" and python_full_version < "3.0.0" and sys_platform == "darwin" or python_full_version >= "3.3.0" and sys_platform == "darwin" and python_version >= "3.8"
dateparser==1.1.2; python_version >= "3.5"
@@ -64,7 +61,6 @@ dill==0.3.6; python_version >= "3.7" and python_full_version >= "3.7.2"
distlib==0.3.6; python_version >= "3.7"
dnspython==2.2.1; python_version >= "3.6" and python_version < "4.0"
docutils==0.17.1; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6"
ecos==2.0.10; python_version >= "3.7"
entrypoints==0.4; python_full_version >= "3.7.0" and python_full_version < "4.0.0" and python_version >= "3.7" and (python_version >= "3.7" and python_full_version < "3.9.7" or python_full_version > "3.9.7" and python_version >= "3.7")
ephem==4.1.3; python_version >= "3.7" and python_version < "4"
et-xmlfile==1.1.0; python_version >= "3.6"
@@ -78,7 +74,7 @@ financedatabase==1.0.2
finnhub-python==2.4.15
finviz==1.4.4
finvizfinance==0.14.4; python_version >= "3.5"
flake8==3.9.2; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.5.0")
flake8==3.9.2; python_full_version >= "3.7.0"
fonttools==4.38.0; python_version >= "3.7"
formulaic==0.3.4; python_full_version >= "3.7.1" and python_full_version < "4.0.0" and python_version >= "3.8"
fred==3.1
@@ -160,7 +156,6 @@ nbconvert==6.5.4; python_version >= "3.7"
nbformat==5.7.0; python_full_version >= "3.7.0" and python_full_version < "4.0.0" and python_version >= "3.7"
nbmake==1.3.0; python_full_version >= "3.7.0" and python_full_version < "4.0.0"
nest-asyncio==1.5.6; python_full_version >= "3.7.0" and python_full_version < "4.0.0" and python_version >= "3.7"
networkx==2.8.7; python_version >= "3.8"
nfoursid==1.0.1; python_version >= "3.7"
nodeenv==1.7.0; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.7.0" and python_version >= "3.7"
notebook-shim==0.2.0; python_version >= "3.7"
@@ -171,7 +166,6 @@ oandapyv20==0.6.3
oauthlib==3.2.2; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" and python_version >= "3.6"
onetimepass==1.0.1; python_full_version >= "3.7.1" and python_full_version < "4.0.0"
openpyxl==3.0.10; python_version >= "3.6"
osqp==0.6.2.post5; python_version >= "3.7"
packaging==22.0; python_version >= "3.7"
pandas-datareader==0.10.0; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3.6"
pandas-market-calendars==3.2; python_full_version >= "3.7.0"
@@ -214,7 +208,6 @@ pycparser==2.21; python_version >= "3.6" and python_full_version < "3.0.0" or py
pydantic==1.8.2; python_full_version >= "3.7.0" and python_full_version < "4.0.0"
pydeck==0.8.0b4; python_version >= "3.7" and python_full_version < "3.9.7" or python_full_version > "3.9.7" and python_version >= "3.7"
pydeprecate==0.3.2; python_version >= "3.7"
pyerfa==2.0.0.1; python_version >= "3.8"
pyex==0.5.0
pyflakes==2.3.1; python_full_version >= "3.7.0"
pygments==2.13.0; python_version >= "3.6"
@@ -247,9 +240,8 @@ pytz==2022.5; python_full_version >= "3.7.1" and python_full_version < "4.0.0" a
pyupgrade==2.38.4; python_version >= "3.7"
pywin32==304; sys_platform == "win32" and platform_python_implementation != "PyPy" and python_version >= "3.7"
pywinpty==2.0.8; os_name == "nt" and python_version >= "3.7"
pyyaml==6.0; python_version >= "3.8"
pyyaml==6.0; python_version >= "3.7"
pyzmq==24.0.1; python_full_version >= "3.7.0" and python_full_version < "4.0.0" and python_version >= "3.7"
qdldl==0.1.5.post2; python_version >= "3.7"
quandl==3.7.0; python_version >= "3.6"
rapidfuzz==1.9.1; python_version >= "2.7"
regex==2022.3.2; python_version >= "3.6"
@@ -257,15 +249,14 @@ requests-oauthlib==1.3.1; python_version >= "3.7" and python_full_version < "3.0
requests==2.28.1; python_version >= "3.7" and python_version < "4"
rfc3986==1.5.0; python_version >= "3.8" and python_version < "4.0"
rich==12.6.0; python_full_version >= "3.6.3" and python_full_version < "4.0.0"
riskfolio-lib==3.3.0; python_version >= "3.7"
robin-stocks==2.1.0; python_version >= "3"
rsa==4.9; python_version >= "3.6" and python_version < "4" and (python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3.7")
ruamel.yaml.clib==0.2.7; platform_python_implementation == "CPython" and python_version < "3.11" and python_version >= "3.5"
ruamel.yaml==0.17.21; python_version >= "3"
ruff==0.0.210; python_version >= "3.7"
scikit-learn==1.1.2; python_version >= "3.8" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3.8"
scipy==1.9.3; python_version >= "3.8"
screeninfo==0.6.7
scs==3.2.0; python_version >= "3.7"
seaborn==0.11.2; python_version >= "3.6"
semver==2.13.0; python_version >= "3.7" and python_full_version < "3.0.0" or python_version >= "3.7" and python_full_version < "3.9.7" and python_full_version >= "3.4.0" or python_full_version > "3.9.7"
send2trash==1.8.0; python_version >= "3.7"
@@ -352,7 +343,6 @@ win32-setctime==1.1.0; python_version >= "3.5" and python_full_version >= "3.7.0
wrapt==1.14.1; python_full_version >= "3.7.2" and python_full_version < "4.0.0" and (python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7") and python_version >= "3.8" and python_version < "3.11"
xarray==2022.11.0; python_version >= "3.8"
xgboost==1.7.2; python_version >= "3.8"
xlsxwriter==3.0.3; python_version >= "3.7"
yarl==1.8.1; python_version >= "3.7" and python_full_version >= "3.7.0"
yfinance==0.1.95
zipp==3.10.0; python_version >= "3.7" and python_full_version < "3.9.7" and python_version < "3.10" or python_full_version > "3.9.7" and python_version >= "3.7" and python_version < "3.10"

2
requirements.txt vendored
View File

@@ -57,7 +57,7 @@ financedatabase==1.0.2
finnhub-python==2.4.15
finviz==1.4.4
finvizfinance==0.14.4; python_version >= "3.5"
flake8==3.9.2; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.5.0")
flake8==3.9.2; python_full_version >= "3.7.0"
fonttools==4.38.0; python_version >= "3.7"
formulaic==0.3.4; python_full_version >= "3.7.1" and python_full_version < "4.0.0" and python_version >= "3.8"
fred==3.1