Last active
June 28, 2024 20:16
-
-
Save LucasRoesler/a16217be6c0f65d8c2b9a61c8387a6f0 to your computer and use it in GitHub Desktop.
My default pyright and ruff configuration for new projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.12.0-slim-bullseye AS build | |
RUN apt-get update && apt-get install -y gcc | |
ENV POETRY_VIRTUALENVS_IN_PROJECT=true \ | |
POETRY_NO_INTERACTION=1 \ | |
POETRY_VIRTUALENVS_OPTIONS_NO_SETUPTOOLS=1 | |
RUN pip install "poetry>=1.8" | |
WORKDIR /app | |
# only install depednencies | |
COPY ./pyproject.toml ./poetry.lock ./ | |
RUN poetry install --no-root --no-directory --only=main | |
# now add the project to the venv | |
COPY ./src /app/src | |
RUN poetry install --only-root | |
FROM python:3.12.0-slim-bullseye AS app | |
# This "enables" the virtualenv that we install in the build stage: | |
ENV PATH="/app/.venv/bin:$PATH" | |
COPY --from=build /app/.venv /app/.venv | |
COPY ./src /app/src | |
WORKDIR /app | |
CMD ["uvicorn", "--host", "0.0.0.0", "--port", "8080", "<REPLACE_WITH_PROJECT_NAME>.main:app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.data | |
*.pyc | |
.task | |
.env | |
.venv | |
.pytest_cache | |
.ruff_cache | |
__pycache__ | |
tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[tool.pyright] | |
# see https://microsoft.github.io/pyright/#/configuration?id=pyright-configuration | |
exclude = [ | |
"**/node_modules", | |
"**/__pycache__", | |
"**/.venv", | |
] | |
reportMissingImports = true | |
typeCheckingMode = "basic" | |
[tool.ruff] | |
# See https://beta.ruff.rs/docs/configuration/ | |
[tool.ruff.lint] | |
select = ["E", "F", "I",] | |
ignore = ["E501"] | |
extend-safe-fixes = ["F601"] | |
[tool.ruff.lint.isort] | |
combine-as-imports = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 3 | |
env: | |
POETRY_VIRTUALENVS_IN_PROJECT: "true" | |
POETRY_VIRTUALENVS_PREFER_ACTIVE_PYTHON: "true" | |
REPOSITORY: "<REPLACE>" | |
APPLICATION_NAME: "<REPLACE>" | |
DOCKER_IMAGE: "{{.REPOSITORY}}/{{.APPLICATION_NAME}}" | |
dotenv: | |
- .env | |
tasks: | |
check_poetry: | |
desc: Check if poetry is installed | |
silent: true | |
internal: true | |
vars: | |
poetry_version: "1.8.2" | |
installed_version: | |
sh: poetry --version 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' || echo "0.0.0" | |
cmds: | |
- echo "you should install poetry version {{.poetry_version}}, you have {{.installed_version}}" | |
status: | |
- | | |
{{ if (lt .installed_version .poetry_version) }} exit 1 {{ else}} exit 0 {{ end }} | |
setup: | |
desc: Create the local development env | |
cmds: | |
- task: python-setup | |
python-setup: | |
desc: Create a python 3 virtualenv | |
deps: | |
- check_poetry | |
cmds: | |
- poetry install | |
sources: | |
- pyproject.toml | |
generates: | |
- ".venv/*" | |
lint: | |
desc: lint the python code | |
deps: | |
- setup | |
cmds: | |
- "poetry run ruff check ." | |
- "poetry run pyright ." | |
- "poetry run typos ." | |
format: | |
desc: format the python code | |
deps: | |
- setup | |
cmds: | |
- "poetry run ruff format ." | |
- "poetry run ruff check --fix-only ." | |
- "poetry run typos -w ." | |
test: | |
desc: Run the tests | |
deps: | |
- setup | |
cmds: | |
- "poetry run pytest . {{.CLI_ARGS}}" | |
clean: | |
desc: Clean the project | |
cmds: | |
- rm -rf tmp | |
- rm -rf .venv | |
- rm -rf .pytest_cache | |
- rm -rf .ruff_cache | |
build: | |
desc: Build the application | |
deps: | |
- setup | |
cmds: | |
- docker build -t {{.DOCKER_IMAGE}} . | |
sources: | |
- Dockerfile | |
- pyproject.toml | |
- src/**/*.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment