Skip to content

Commit

Permalink
chore: improve ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenanht committed Feb 16, 2024
1 parent 5a2e63d commit a94eb3c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ DOCKER_RUNTIME=runc
# DEVICE=gpu
# DOCKER_RUNTIME=nvidia

CUDA_TAG_IMAGE=12.1.0-cudnn8-runtime-ubuntu22.04
CUDA_TAG_IMAGE=12.2.2-cudnn8-runtime-ubuntu22.04

POETRY_VERSION=1.7.1
PYTHON_VERSION=3.9.17
PYTHON_VERSION=3.9.17
11 changes: 4 additions & 7 deletions .jupyter/jupyter_lab_config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import subprocess
from typing import List

from jupyterlab_code_formatter.formatters import (
SERVER_FORMATTERS,
BaseFormatter,
handle_line_ending_and_magic,
logger,
)

# Configuration file for lab.
Expand Down Expand Up @@ -1170,18 +1168,17 @@ def importable(self) -> bool:
return True

@handle_line_ending_and_magic
def format_code(self, code: str, notebook: bool, args: List[str] = [], **options) -> str:
def format_code(self, code: str, notebook: bool, args: list[str] = [], **options) -> str:
process = subprocess.run(
[self.ruff_bin, "format", "-", "--config", "pyproject.toml"],
["ruff", "format", "-", "--config", "/work/pyproject.toml"],
input=code,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
text=True,
)

if process.stderr:
logger.info(process.stderr)
return code
raise ValueError(process.stderr)
else:
return process.stdout

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"preferences": {
"default_formatter": {
"python": "ruff_format",
"python": ["isort", "ruff_format"],
"R": "formatR",
"rust": "rustfmt",
"c++11": "astyle"
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile_gpu
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,10 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y cuda-cu
bash-completion

ENV LD_LIBRARY_PATH /usr/local/cuda/lib64:${LD_LIBRARY_PATH}

ARG USER_ID
ARG GROUP_ID

# Create group and user
RUN groupadd -f -g ${GROUP_ID} john_dev_group && \
useradd -l -u ${USER_ID} -g john_dev_group john_dev_user
68 changes: 35 additions & 33 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
version: "3.8"
services:
proxy:
image: "traefik:v2.6.1"
container_name: traefik-container
command:
#- "--log.level=DEBUG"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.websecure.address=:443"
- "--entrypoints.websecure.http.tls=true"
- "--entrypoints.web.address=:80"
- "--entrypoints.web.http.redirections.entryPoint.to=websecure"
- "--entrypoints.web.http.redirections.entryPoint.scheme=https"
- "--entrypoints.web.http.redirections.entrypoint.permanent=true"
- "--providers.file.filename=/etc/traefik/configfile.toml"
ports:
- "80:80"
- "8080:8080"
- "443:443"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./ssl:/etc/cert:ro"
- "./ssl/traefik.toml:/etc/traefik/configfile.toml:ro"
labels:
- "traefik.enable=true"
- "traefik.http.routers.proxy.rule=Host(`proxy.${DOMAIN_NAME_LOCAL}`)"
- "traefik.http.routers.proxy.entrypoints=websecure"
- "traefik.http.services.proxy.loadbalancer.server.port=8080"
- "traefik.http.middlewares.limit.buffering.maxRequestBodyBytes=50000000" # Sets the maximum request body to 50Mb
- "traefik.http.middlewares.limit.buffering.memRequestBodyBytes=100000000" # 100Mb
- "traefik.http.middlewares.limit.buffering.maxResponseBodyBytes=100000000" # 100Mb
- "traefik.http.middlewares.limit.buffering.memResponseBodyBytes=100000000" # 100Mb
networks:
john_toolbox_network:
image: "traefik:v2.6.1"
container_name: traefik-container
command:
#- "--log.level=DEBUG"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.websecure.address=:443"
- "--entrypoints.websecure.http.tls=true"
- "--entrypoints.web.address=:80"
- "--entrypoints.web.http.redirections.entryPoint.to=websecure"
- "--entrypoints.web.http.redirections.entryPoint.scheme=https"
- "--entrypoints.web.http.redirections.entrypoint.permanent=true"
- "--providers.file.filename=/etc/traefik/configfile.toml"
ports:
- "80:80"
- "8080:8080"
- "443:443"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./ssl:/etc/cert:ro"
- "./ssl/traefik.toml:/etc/traefik/configfile.toml:ro"
labels:
- "traefik.enable=true"
- "traefik.http.routers.proxy.rule=Host(`proxy.${DOMAIN_NAME_LOCAL}`)"
- "traefik.http.routers.proxy.entrypoints=websecure"
- "traefik.http.services.proxy.loadbalancer.server.port=8080"
- "traefik.http.middlewares.limit.buffering.maxRequestBodyBytes=50000000" # Sets the maximum request body to 50Mb
- "traefik.http.middlewares.limit.buffering.memRequestBodyBytes=100000000" # 100Mb
- "traefik.http.middlewares.limit.buffering.maxResponseBodyBytes=100000000" # 100Mb
- "traefik.http.middlewares.limit.buffering.memResponseBodyBytes=100000000" # 100Mb
networks:
john_toolbox_network:

# ------------------------------------------ JUPYTER NOTEBOOK DEV CONTAINER--------------------------------------------------------
john_dev:
Expand All @@ -48,6 +48,8 @@ services:
CUDA_TAG_IMAGE: ${CUDA_TAG_IMAGE}
POETRY_VERSION: ${POETRY_VERSION}
PYTHON_VERSION: ${PYTHON_VERSION}
USER_ID: ${USER_ID}
GROUP_ID: ${GROUP_ID}
runtime: ${DOCKER_RUNTIME}
command: poetry run jupyter notebook --port=${NOTEBOOK_PORT} --no-browser --ip=0.0.0.0 --allow-root --NotebookApp.token=''
# command: poetry run jupyter lab --port=${NOTEBOOK_PORT} --no-browser --ip=0.0.0.0 --allow-root --NotebookApp.token='' --notebook-dir .
Expand Down
18 changes: 17 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ exclude = '''
'''

[tool.ruff]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"UP", # pyupgrade
]

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
Expand Down Expand Up @@ -153,7 +163,13 @@ cache-dir = "/work/.cache/ruff"

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
select = ["E4", "E7", "E9", "F", "I"]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"C4", # flake8-comprehensions
]
ignore = ["E501", "I001"]

# Allow fix for all enabled rules (when `--fix`) is provided.
Expand Down

0 comments on commit a94eb3c

Please sign in to comment.