From f1e5bf4e665758bf31261288d5d0172b06083bcb Mon Sep 17 00:00:00 2001 From: Andrey Bozhko Date: Sat, 6 Apr 2024 03:44:45 +0000 Subject: [PATCH] use uv and ruff --- .devcontainer/Dockerfile | 14 ++---- .github/workflows/ci.yml | 13 ++++-- .gitignore | 3 ++ pyproject.toml | 13 +++++- reqs/requirements-dev.txt | 55 ++++-------------------- reqs/requirements.txt | 10 +---- src/expense_bot/repositories/__init__.py | 3 +- 7 files changed, 40 insertions(+), 71 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 72b9863..6bd49b7 100755 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,16 +1,13 @@ FROM python:3.9-buster@sha256:a21bc1f5190fa4f5d13dbdec6adc8d65ae2d3025411ecab367f616831dd570cb -RUN pip install --no-cache-dir --upgrade pip==22.3.1 setuptools==65.6.3 wheel==0.42.0 +RUN pip install --no-cache-dir --upgrade pip==22.3.1 setuptools==65.6.3 wheel==0.43.0 \ + && pip install --no-cache-dir uv -ENV PIP_PREFIX=/usr/local/share/pip_global -ENV PATH=${PATH}:${PIP_PREFIX}/bin -ENV PYTHONPATH=${PYTHONPATH}:${PIP_PREFIX}/lib/python3.9/site-packages:/workspaces/expense-bot/src +ENV PYTHONPATH=${PYTHONPATH}:/workspaces/expense-bot/src RUN groupadd docker && \ useradd -r -u 1001 -g docker vscode && \ mkdir -p /home/vscode && \ - chown -R vscode:docker /home/vscode && \ - mkdir -p ${PIP_PREFIX} && \ - chown -R vscode:docker ${PIP_PREFIX} + chown -R vscode:docker /home/vscode RUN apt-get update \ && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \ @@ -24,6 +21,3 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* USER vscode - -RUN pip install --no-cache-dir 'pip-tools==6.12.1' 'wheel==0.42.0' \ - && pip install --no-cache-dir pylint mypy black flake8 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0574f55..c067209 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,11 +23,11 @@ jobs: - name: Install Dependencies run: | - python -m pip install --upgrade pip - python -m venv venv + python -m pip install --upgrade uv + uv venv venv source venv/bin/activate - pip install --upgrade pip setuptools wheel - pip install -r reqs/requirements.txt -r reqs/requirements-dev.txt + uv pip install --upgrade setuptools wheel + uv pip install -r reqs/requirements.txt -r reqs/requirements-dev.txt - name: Run Tests (pytest) env: @@ -61,3 +61,8 @@ jobs: run: | source venv/bin/activate pylint src/ + + - name: Lint Code (ruff) + run: | + source venv/bin/activate + ruff check src/ diff --git a/.gitignore b/.gitignore index bbd636c..0d4181d 100644 --- a/.gitignore +++ b/.gitignore @@ -152,6 +152,9 @@ dmypy.json # Cython debug symbols cython_debug/ +# ruff +.ruff_cache/ + # PyCharm # JetBrains specific template is maintained in a separate JetBrains.gitignore that can # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore diff --git a/pyproject.toml b/pyproject.toml index 83fc326..08d7ade 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,9 +27,10 @@ dev = [ "flake8-pyproject", "google-api-python-client-stubs", "mypy", - "pip-tools", "pylint", "pytest", + "ruff", + "setuptools==65.6.3", "wheel", ] @@ -55,3 +56,13 @@ line_length = 78 [tool.pylint.main] good-names = ["dt", "dp"] disable = ["R0801", "R0903"] + +[tool.ruff.lint] +select = [ + "E", + "F", + "B", + "SIM", + "I", + "R", +] diff --git a/reqs/requirements-dev.txt b/reqs/requirements-dev.txt index 46530c3..9f15e73 100644 --- a/reqs/requirements-dev.txt +++ b/reqs/requirements-dev.txt @@ -1,13 +1,8 @@ -# -# This file is autogenerated by pip-compile with Python 3.9 -# by the following command: -# -# pip-compile --extra=dev --output-file=reqs/requirements-dev.txt --resolver=backtracking pyproject.toml -# +# This file was autogenerated by uv via the following command: +# uv pip compile --extra=dev pyproject.toml -o reqs/requirements-dev.txt aiofiles==23.2.1 # via aiogram aiogram==3.2.0 - # via expense-bot (pyproject.toml) aiohttp==3.9.3 # via aiogram aiosignal==1.2.0 @@ -23,18 +18,12 @@ attrs==21.4.0 # aiohttp # pytest awslambdaric==2.0.4 - # via expense-bot (pyproject.toml) black==24.3.0 - # via expense-bot (pyproject.toml) boto3==1.20.32 - # via expense-bot (pyproject.toml) botocore==1.23.32 # via # boto3 - # expense-bot (pyproject.toml) # s3transfer -build==1.0.3 - # via pip-tools cachetools==5.2.0 # via google-auth certifi==2023.7.22 @@ -44,19 +33,14 @@ certifi==2023.7.22 charset-normalizer==2.0.12 # via requests click==8.1.3 - # via - # black - # pip-tools + # via black dill==0.3.5.1 # via pylint exceptiongroup==1.0.1 # via pytest flake8==6.0.0 - # via - # expense-bot (pyproject.toml) - # flake8-pyproject + # via flake8-pyproject flake8-pyproject==1.2.2 - # via expense-bot (pyproject.toml) frozenlist==1.3.0 # via # aiohttp @@ -64,11 +48,8 @@ frozenlist==1.3.0 google-api-core==2.8.1 # via google-api-python-client google-api-python-client==2.50.0 - # via - # expense-bot (pyproject.toml) - # google-api-python-client-stubs + # via google-api-python-client-stubs google-api-python-client-stubs==1.11.0 - # via expense-bot (pyproject.toml) google-auth==2.7.0 # via # google-api-core @@ -86,8 +67,6 @@ idna==3.3 # via # requests # yarl -importlib-metadata==6.8.0 - # via build iniconfig==1.1.1 # via pytest isort==5.10.1 @@ -109,7 +88,6 @@ multidict==6.0.2 # aiohttp # yarl mypy==1.0.1 - # via expense-bot (pyproject.toml) mypy-extensions==0.4.3 # via # black @@ -117,12 +95,9 @@ mypy-extensions==0.4.3 packaging==24.0 # via # black - # build # pytest pathspec==0.9.0 # via black -pip-tools==6.12.1 - # via expense-bot (pyproject.toml) platformdirs==2.5.2 # via # black @@ -148,21 +123,20 @@ pydantic-core==2.14.5 pyflakes==3.0.1 # via flake8 pylint==2.14.1 - # via expense-bot (pyproject.toml) pyparsing==3.0.9 # via httplib2 -pyproject-hooks==1.0.0 - # via build pytest==7.2.0 - # via expense-bot (pyproject.toml) python-dateutil==2.8.2 # via botocore requests==2.31.0 # via google-api-core rsa==4.8 # via google-auth +ruff==0.3.5 s3transfer==0.5.2 # via boto3 +setuptools==65.6.3 + # via astroid simplejson==3.17.2 # via awslambdaric six==1.16.0 @@ -173,11 +147,9 @@ six==1.16.0 tomli==2.0.1 # via # black - # build # flake8-pyproject # mypy # pylint - # pyproject-hooks # pytest tomlkit==0.11.0 # via pylint @@ -197,17 +169,8 @@ urllib3==1.26.18 # via # botocore # requests -wheel==0.42.0 - # via - # expense-bot (pyproject.toml) - # pip-tools +wheel==0.43.0 wrapt==1.14.1 # via astroid yarl==1.7.2 # via aiohttp -zipp==3.17.0 - # via importlib-metadata - -# The following packages are considered to be unsafe in a requirements file: -# pip -# setuptools diff --git a/reqs/requirements.txt b/reqs/requirements.txt index f1158b1..2533795 100644 --- a/reqs/requirements.txt +++ b/reqs/requirements.txt @@ -1,13 +1,8 @@ -# -# This file is autogenerated by pip-compile with Python 3.9 -# by the following command: -# -# pip-compile --output-file=reqs/requirements.txt --resolver=backtracking pyproject.toml -# +# This file was autogenerated by uv via the following command: +# uv pip compile pyproject.toml -o reqs/requirements.txt aiofiles==23.2.1 # via aiogram aiogram==3.2.0 - # via expense-bot (pyproject.toml) aiohttp==3.9.3 # via aiogram aiosignal==1.2.0 @@ -33,7 +28,6 @@ frozenlist==1.3.0 google-api-core==2.8.1 # via google-api-python-client google-api-python-client==2.50.0 - # via expense-bot (pyproject.toml) google-auth==2.7.0 # via # google-api-core diff --git a/src/expense_bot/repositories/__init__.py b/src/expense_bot/repositories/__init__.py index b760a53..1cc1f59 100644 --- a/src/expense_bot/repositories/__init__.py +++ b/src/expense_bot/repositories/__init__.py @@ -21,8 +21,7 @@ def __init__(self): self._storage: _StorageType = defaultdict(list) def get_all(self, *, dt: date) -> Iterable[ExpenseItem]: - vals = self._storage[dt] if dt in self._storage else [] - return vals + return self._storage.get(dt) or [] def add(self, item: ExpenseItem, /, *, dt: date): self._storage[dt].append(item)