Skip to content

Commit

Permalink
Merge pull request #1 from a5chin/feature/actions
Browse files Browse the repository at this point in the history
Fix GitHub Actions
  • Loading branch information
a5chin authored Apr 9, 2024
2 parents 6e22def + a939c67 commit c52b674
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 33 deletions.
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ WORKDIR /opt
ENV RYE_HOME="/opt/rye"
ENV PATH="$RYE_HOME/shims:$PATH"

# hadolint ignore=DL3008
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"oderwat.indent-rainbow",
"pkief.material-icon-theme",
"shardulm94.trailing-spaces",
"usernamehw.errorlens"
"usernamehw.errorlens",
"yzhang.markdown-all-in-one"
],
"settings": {
"python.defaultInterpreterPath": "/opt/rye/shims/python",
Expand Down
17 changes: 16 additions & 1 deletion .github/workflows/build.yml → .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,24 @@ on:
branches: [ main ]

jobs:
docker:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Lint Dockerfile
uses: hadolint/[email protected]
with:
dockerfile: Dockerfile

build:
runs-on: ubuntu-latest

needs: lint
if: ${{ success() }}

steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
39 changes: 36 additions & 3 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,62 @@ on:
branches: [ main ]

jobs:
ci:
lint:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Rye
uses: eifinger/setup-rye@v2
with:
enable-cache: true

- name: Set Rye Config
run: |
curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash
rye config --set-bool behavior.global-python=true
rye config --set-bool behavior.use-uv=true
- name: Set up Python ${{ matrix.python-version }}
run: |
export PYTHONUNBUFFERED=1
rye pin ${{ matrix.python-version }}
rye sync
- name: Lint
run: rye run ruff check --output-format=github .

format:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Rye
uses: eifinger/setup-rye@v2
with:
enable-cache: true

- name: Set Rye Config
run: |
rye config --set-bool behavior.global-python=true
rye config --set-bool behavior.use-uv=true
- name: Set up Python ${{ matrix.python-version }}
run: |
export PYTHONUNBUFFERED=1
rye pin ${{ matrix.python-version }}
rye sync
- name: Format
run: rye run ruff format . --check --diff
21 changes: 15 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Ruff
name: Test

on:
push:
Expand All @@ -7,26 +7,35 @@ on:
branches: [ main ]

jobs:
ci:
pytest:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Rye
uses: eifinger/setup-rye@v2
with:
enable-cache: true

- name: Set Rye Config
run: |
curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash
rye config --set-bool behavior.global-python=true
rye config --set-bool behavior.use-uv=true
- name: Set up Python ${{ matrix.python-version }}
run: |
export PYTHONUNBUFFERED=1
rye pin ${{ matrix.python-version }}
rye sync
- name: Pytest
run: rye run pytest -s
- name: Run Pytest if directory exists
run: |
if [ -d "./tests/" ]; then
rye run pytest -s
fi
17 changes: 14 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@ repos:
rev: v0.3.5
hooks:
- id: ruff
name: ruff
description: "Run 'ruff' for extremely fast Python linting"
name: Ruff check
description: "Run 'ruff check' for extremely fast Python linting"
args: [ --fix ]

- id: ruff-format
name: ruff-format
name: Ruff format
description: "Run 'ruff format' for extremely fast Python formatting"

- repo: https://github.com/hadolint/hadolint
rev: v2.12.0
hooks:
- id: hadolint
name: Lint Dockerfiles
description: Runs hadolint to lint Dockerfiles
language: system
files: ["Dockerfile", ".devcontainer/Dockerfile"]
types: ["dockerfile"]
entry: hadolint
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ WORKDIR /opt
ENV RYE_HOME="/opt/rye"
ENV PATH="$RYE_HOME/shims:$PATH"

# hadolint ignore=DL3008
RUN apt-get update && \
apt-get install -y --no-install-recommends curl \
apt-get install -y --no-install-recommends \
ca-certificates \
curl

Expand Down
121 changes: 121 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# VSCode Dev Container: Python Development with Rye, uv, and Ruff

<div align="center">

[![Rye](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/rye/main/artwork/badge.json)](https://github.com/astral-sh/rye)
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

[![Versions](https://img.shields.io/badge/python-3.9%20|%203.10%20|%203.11%20|%203.12%20-green.svg)](https://github.com/a5chin/python-rye)

[![Ruff](https://github.com/a5chin/python-rye/actions/workflows/ruff.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/ruff.yml)
[![test](https://github.com/a5chin/python-rye/actions/workflows/test.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/test.yml)
[![Docker](https://github.com/a5chin/python-rye/actions/workflows/docker.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/docker.yml)

</div>

## Overview
This repository contains configurations to set up a Python development environment using VSCode's Dev Container feature.
The environment includes Rye, uv, and Ruff.

## Contents
The following are the features.

### Dev Container
- `devcontainer.json`
- settings
- formatOnSave by Ruff
- features
- pre-commit
- extentions
- [charliermarsh.ruff](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff)
- [codezombiech.gitignore](https://marketplace.visualstudio.com/items?itemName=codezombiech.gitignore)
- [eamodio.gitlens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens)
- [kevinrose.vsc-python-indent](https://marketplace.visualstudio.com/items?itemName=kevinrose.vsc-python-indent)
- [mosapride.zenkaku](https://marketplace.visualstudio.com/items?itemName=mosapride.zenkaku)
- [ms-python.python](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
- [njpwerner.autodocstring](https://marketplace.visualstudio.com/items?itemName=njpwerner.autodocstring)
- [oderwat.indent-rainbow](https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow)
- [pkief.material-icon-theme](https://marketplace.visualstudio.com/items?itemName=pkief.material-icon-theme)
- [shardulm94.trailing-spaces](https://marketplace.visualstudio.com/items?itemName=shardulm94.trailing-spaces)
- [usernamehw.errorlens](https://marketplace.visualstudio.com/items?itemName=usernamehw.errorlens)
- [yzhang.markdown-all-in-one](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one)
- `Dockerfile`
- Rye
- `rye config --set-bool behavior.global-python=true`
- `rye config --set-bool behavior.use-uv=true`
- Only Dev dependencies
- `pre-commit`
- `pytest`
- `ruff`

### GitHub Actions
- `docker.yml`
- Workflow to check if you can build with Docker
- `test.yml`
- Workflow to check if all the described tests can be passed with pytest
- `ruff.yml`
- Workflow to check if you can go through Formatter and Linter with Ruff

### Ruff
Ruff can be used to replace Flake8, Black, isort, pydocstyle, pyupgrade, autoflake, etc., and yet run tens to hundreds of times faster than the individual tools.

To change the configuration, it is necessary to rewrite ruff.toml, and [it is recommended](https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules) to set it to ignore conflicts such as the following:
```toml
ignore = [
"COM812", "COM819",
"D100", "D203", "D213", "D300",
"E111", "E114", "E117",
"ISC001", "ISC002",
"Q000", "Q001", "Q002", "Q003",
"W191",
]
```

### pre-commit
The `.pre-commit-config.yaml` file can contain scripts to be executed before commit.

```sh
# Linter
ruff check . --fix

# Formatter
ruff format .
```

### Install
Only sync based on the production lockfile (`requirements.lock`) instead of the development lockfile (`requirements-dev.lock`).

```sh
# Install also include develop dependencies
rye sync

# If you do not want dev dependencies to be installed
rye sync --no-dev
```

## Appendix
### The structure of this repository
```
.
├── .devcontainer
│ ├── devcontainer.json
│ └── Dockerfile
├── Dockerfile
├── .github
│ └── workflows
│ ├── docker.yml
│ ├── ruff.yml
│ └── pytest.yml
├── .gitignore
├── LICENSE
├── .pre-commit-config.yaml
├── pyproject.toml
├── .python-version
├── README.md
├── requirements-dev.lock
├── requirements.lock
├── ruff.toml
└── .vscode
└── settings.json
```
18 changes: 0 additions & 18 deletions main.py

This file was deleted.

0 comments on commit c52b674

Please sign in to comment.