Skip to content

Commit

Permalink
switch to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Maik Jablonka committed Oct 4, 2023
1 parent 65fee6d commit 01e9e71
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 74 deletions.
76 changes: 32 additions & 44 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[metadata]
name = chemlift
version = 0.0.1-dev
description = Chemical language interfaced fine-tuning of large-language models
description = Chemical language interfaced predictions using large-language models
long_description = file: README.md
long_description_content_type = text/markdown

Expand Down Expand Up @@ -42,15 +42,19 @@ classifiers =
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3 :: Only
keywords =
keywords =
llm
chemistry
lift



[options]
install_requires =
more_itertools
tqdm
transformers
peft
peft
gptchem
datasets
accelerate
Expand Down Expand Up @@ -114,51 +118,35 @@ show_missing = True
exclude_lines =
pragma: no cover
raise NotImplementedError
if __name__ == "__main__":
if TYPE_CHECKING:
def __str__
def __repr__


##########################
# Darglint Configuration #
##########################
[darglint]
docstring_style = sphinx
docstring_style = google
strictness = short

#########################
# Flake8 Configuration #
# (.flake8) #
#########################
[flake8]
ignore =
S301 # pickle
S403 # pickle
S404
S603
W503 # Line break before binary operator (flake8 is wrong)
E203 # whitespace before ':'
exclude =
.tox,
.git,
__pycache__,
docs/source/conf.py,
build,
dist,
tests/fixtures/*,
*.pyc,
*.egg-info,
.cache,
.eggs,
data
max-line-length = 120
max-complexity = 20
import-order-style = pycharm
application-import-names =
chemlift
tests


[tool:pytest]
env_files =
.env
[tool.ruff]
exclude =
".tox"
".git"
"__pycache__"
"docs/source/conf.py"
"build"
"dist"
"tests/fixtures/*"
"*.pyc"
"*.egg-info"
".cache"
".eggs"
"data"
line-length = 120
select =
"C9"
"E"
"F"
"W"

[tool.ruff.mccabe]
max-complexity = 20
2 changes: 0 additions & 2 deletions src/chemlift/icl/fewshotclassifier.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from loguru import logger
from numpy.typing import ArrayLike
from typing import Union
from chemlift.icl.fewshotpredictor import FewShotPredictor
from chemlift.icl.utils import LangChainChatModelWrapper


class FewShotClassifier(FewShotPredictor):
Expand Down
1 change: 0 additions & 1 deletion src/chemlift/icl/fewshotpredictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from numpy.typing import ArrayLike
import enum
from typing import Union
from chemlift.icl.fewshotpredictor import FewShotPredictor
from chemlift.icl.utils import LangChainChatModelWrapper


Expand Down
10 changes: 9 additions & 1 deletion src/chemlift/icl/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
class LangChainChatModelWrapper:
"""Wrapper for chat model to make it accept plain text prompts."""
"""Wrapper for chat model to make it accept plain text prompts.
Examples:
>>> from chemlift.icl.utils import LangChainChatModelWrapper
>>> from langchain.chat_models import ChatOpenAI
>>> model = ChatOpenAI(model="gpt-4")
>>> model = LangChainChatModelWrapper(model)
>>> model.generate(["Hello, how are you?"])
"""

def __init__(self, model):
self.model = model
Expand Down
2 changes: 1 addition & 1 deletion src/chemlift/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def array_of_ints_without_nan(arr):
def try_exccept_nan(f, x):
try:
return f(x)
except:
except Exception:
return np.nan


Expand Down
32 changes: 7 additions & 25 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ envlist =
lint
manifest
pyroma
flake8
rufff
mypy
# documentation linters/checkers
doc8
Expand All @@ -39,20 +39,12 @@ extras =
tests

[testenv:doctests]
description = Test that documentation examples run properly
commands =
xdoctest -m src
deps =
xdoctest
pygments

[testenv:treon]
description = Test that notebooks can run to completion
commants =
treon notebooks/
deps =
treon

[testenv:coverage-clean]
deps = coverage
skip_install = true
Expand Down Expand Up @@ -84,23 +76,13 @@ skip_install = true
commands = check-manifest
description = Check that the MANIFEST.in is written properly and give feedback on how to fix it.

[testenv:flake8]
skip_install = true
[testenv:ruff]
skip_install = false
deps =
darglint
flake8<5.0.0
flake8-black
flake8-bandit
flake8-bugbear
flake8-colors
flake8-docstrings
flake8-isort
flake8-print
pep8-naming
pydocstyle
ruff
commands =
flake8 src/ tests/
description = Run the flake8 tool with several plugins (bandit, docstrings, import order, pep8 naming). See https://cthoyt.com/2020/04/25/how-to-code-with-me-flake8.html for more information.
ruff src/ tests/
description = Run the ruff tool with several plugins (bandit, docstrings, import order, pep8 naming).

[testenv:pyroma]
deps =
Expand Down Expand Up @@ -221,4 +203,4 @@ commands =
bump2version patch
git push
allowlist_externals =
git
git

0 comments on commit 01e9e71

Please sign in to comment.