Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from black to ruff #3080

Merged
merged 7 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.black-formatter",
"charliermarsh.ruff"
],
"settings": {
Expand All @@ -33,11 +32,9 @@
"source.fixAll": true,
"source.organizeImports": true
},
"editor.defaultFormatter": "ms-python.black-formatter",
"ruff.organizeImports": false
"editor.defaultFormatter": "charliermarsh.ruff",
"ruff.organizeImports": true
},
"black-formatter.importStrategy": "useBundled",
"black-formatter.showNotifications": "always",
"ruff.codeAction.fixViolation": {
"enable": true
},
Expand Down
3 changes: 0 additions & 3 deletions .devcontainer/post-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ WORKSPACE_DIR=$(pwd)
python -m pip install --upgrade pip
pip3 install -r demo/requirements.txt -r demo/requirements.behave.txt

# install black for formatting
pip3 install black

# install a version of aries-cloudagent so the pytests can pick up a version
pip3 install aries-cloudagent

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Black Code Formatter Check
name: Ruff Code Formatter and Linting Check

"on":
pull_request:
Expand All @@ -14,7 +14,5 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Black Code Formatter Check
# The version of black should be adjusted at the same time dev
# dependencies are updated.
uses: psf/black@24.4.2
- name: Ruff Format and Lint Check
uses: chartboost/ruff-action@v1
13 changes: 6 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ repos:
stages: [commit-msg]
args: ["--config", ".commitlint.config.js"]
additional_dependencies: ['@commitlint/config-conventional']
- repo: https://github.com/psf/black
# Ensure this is synced with pyproject.toml
rev: 24.4.2
hooks:
- id: black
stages: [commit]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ensure this is synced with pyproject.toml
rev: v0.4.4
rev: v0.5.0
hooks:
# Run the linter
- id: ruff
stages: [commit]
args: [--fix, --exit-non-zero-on-fix]
# Run the formatter
- id: ruff-format
stages: [commit]
args: [--fix, --exit-non-zero-on-fix, --formatter]
47 changes: 16 additions & 31 deletions .vscode-sample/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
]
},
{
"name": "ruff - aries_cloudagent",
"name": "ruff (lint) - aries_cloudagent",
"type": "python",
"request": "launch",
"module": "ruff",
Expand All @@ -71,7 +71,7 @@
"args": ["check", "."]
},
{
"name": "ruff fix - aries_cloudagent",
"name": "ruff fix (lint) - aries_cloudagent",
"type": "python",
"request": "launch",
"module": "ruff",
Expand All @@ -82,7 +82,7 @@
"args": ["check", ".", "--fix"]
},
{
"name": "ruff - current file",
"name": "ruff (lint) - current file",
"type": "python",
"request": "launch",
"module": "ruff",
Expand All @@ -93,52 +93,37 @@
"args": ["check", ".", "${file}"]
},
{
"name": "black (check) - aries_cloudagent",
"name": "ruff fix (lint) - current file",
"type": "python",
"request": "launch",
"module": "black",
"module": "ruff",
"console": "integratedTerminal",
"sudo": true,
"justMyCode": true,
"cwd": "${workspaceFolder}/aries_cloudagent",
"args": [
".",
"--check"
]
"args": ["check", ".", "${file}", "--fix"]
},
{
"name": "black (check) - current file",
"name": "ruff (format) - aries_cloudagent",
"type": "python",
"request": "launch",
"module": "black",
"console": "integratedTerminal",
"justMyCode": true,
"args": [
"${file}",
"--check"
]
},
{
"name": "black (format) - aries_cloudagent",
"type": "python",
"request": "launch",
"module": "black",
"module": "ruff",
"console": "integratedTerminal",
"sudo": true,
"justMyCode": true,
"cwd": "${workspaceFolder}/aries_cloudagent",
"args": [
"."
]
"args": ["format", "."]
},
{
"name": "black (format) - current file",
"name": "ruff (format) - current file",
"type": "python",
"request": "launch",
"module": "black",
"module": "ruff",
"console": "integratedTerminal",
"sudo": true,
"justMyCode": true,
"args": [
"${file}"
]
"cwd": "${workspaceFolder}/aries_cloudagent",
"args": ["format", "${file}"]
}
]
}
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Contributions are made pursuant to the Developer's Certificate of Origin, availa

A configuration for [pre-commit](https://pre-commit.com/) is included in this repository. This is an optional tool to help contributors commit code that follows the formatting requirements enforced by the CI pipeline. Additionally, it can be used to help contributors write descriptive commit messages that can be parsed by changelog generators.

On each commit, pre-commit hooks will run that verify the committed code complies with ruff and is formatted with black. To install the ruff and black checks:
On each commit, pre-commit hooks will run that verify the committed code complies and formats with ruff. To install the ruff checks:

```bash
pre-commit install
Expand Down
2 changes: 1 addition & 1 deletion docs/deploying/ContainerImagesAndGithubActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ variants and between the BC Gov ACA-Py images.
Github Container Registry.
- Integration Tests (`.github/workflows/integrationtests.yml`) - Run on pull
requests (to the hyperledger fork only); runs BDD integration tests.
- Black Format (`.github/workflows/blackformat.yml`) - Run on pull requests;
- Format (`.github/workflows/format.yml`) - Run on pull requests;
checks formatting of files modified by the PR.
- CodeQL (`.github/workflows/codeql.yml`) - Run on pull requests; performs
CodeQL analysis.
Expand Down
2 changes: 0 additions & 2 deletions docs/features/DevReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ The `manage` script is described in detail [here](https://github.com/hyperledger

We use [Ruff](https://github.com/astral-sh/ruff) to enforce a coding style guide.

We use [Black](https://black.readthedocs.io/en/stable/) to automatically format code.

Please write tests for the work that you submit.

Tests should reside in a directory named `tests` alongside the code under test. Generally, there is one test file for each file module under test. Test files _must_ have a name starting with `test_` to be automatically picked up the test runner.
Expand Down
10 changes: 4 additions & 6 deletions docs/features/devcontainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,18 @@ To open ACA-Py in a devcontainer, we open the *root* of this repository. We can

#### devcontainer.json

When the [.devcontainer/devcontainer.json](https://github.com/hyperledger/aries-cloudagent-python/blob/main/.devcontainer/devcontainer.json) is opened, you will see it building... it is building a Python 3.9 image (bash shell) and loading it with all the ACA-Py requirements (and black). We also load a few Visual Studio settings (for running Pytests and formatting with Flake and Black).
When the [.devcontainer/devcontainer.json](https://github.com/hyperledger/aries-cloudagent-python/blob/main/.devcontainer/devcontainer.json) is opened, you will see it building... it is building a Python 3.9 image (bash shell) and loading it with all the ACA-Py requirements. We also load a few Visual Studio settings (for running Pytests and formatting with Ruff).

### Poetry

The Python libraries / dependencies are installed using [`poetry`](https://python-poetry.org). For the devcontainer, we *DO NOT* use virtual environments. This means you will not see or need venv prompts in the terminals and you will not need to run tasks through poetry (ie. `poetry run black .`). If you need to add new dependencies, you will need to add the dependency via poetry *AND* you should rebuild your devcontainer.
The Python libraries / dependencies are installed using [`poetry`](https://python-poetry.org). For the devcontainer, we *DO NOT* use virtual environments. This means you will not see or need venv prompts in the terminals and you will not need to run tasks through poetry (ie. `poetry run ruff check .`). If you need to add new dependencies, you will need to add the dependency via poetry *AND* you should rebuild your devcontainer.

In VS Code, open a Terminal, you should be able to run the following commands:

```bash
python -m aries_cloudagent -v
cd aries_cloudagent
ruff check .
black . --check
poetry --version
```

Expand All @@ -72,10 +71,9 @@ Found 1 error.

#### extensions

We have added Black formatter and Ruff extensions. Although we have added launch settings for both `ruff` and `black`, you can also use the extension commands from the command palette.
We have added Ruff extensions. Although we have added launch settings for both `ruff`, you can also use the extension commands from the command palette.

- `Ruff: Format Document`
- `Ruff: Fix all auto-fixable problems`
- `ruff (format) - aries_cloudagent`

More importantly, these extensions are now added to document save, so files will be formatted and checked. We advise that after each time you rebuild the container that you also perform: `Developer: Reload Window` to ensure the extensions are loaded correctly.

Expand Down
86 changes: 2 additions & 84 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ didcomm-messaging = {version = "^0.1.1a0", optional = true }
pre-commit = "~3.7.0"
# Sync with version in .pre-commit-config.yaml
ruff = "0.5.0"
# Sync with version in .github/workflows/blackformat.yml
# Sync with version in .pre-commit-config.yaml
black = "24.4.2"

sphinx="^5.3.0"
sphinx-rtd-theme=">=0.4.3"
Expand Down
Loading