Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Nov 20, 2023
0 parents commit a8f5a1e
Show file tree
Hide file tree
Showing 33 changed files with 1,542 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/check_updates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: check_updates

on:
workflow_dispatch:
schedule:
# do this once per day
- cron: "0 7 * * *"

jobs:
build:
name: check updates
if: github.repository == 'dprint/dprint-plugin-ruff'
runs-on: ubuntu-latest
timeout-minutes: 45

steps:
- name: Clone repository
uses: actions/checkout@v2
with:
token: ${{ secrets.GH_DPRINTBOT_PAT }}

- uses: denoland/setup-deno@v1
- uses: dsherret/rust-toolchain-file@v1

- name: Run script
run: |
git config user.email "[email protected]"
git config user.name "dprintbot"
deno run -A ./scripts/update.ts
117 changes: 117 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: CI

on: [push, pull_request]

jobs:
build:
name: ${{ matrix.config.kind }} ${{ matrix.config.os }}
runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config:
- os: ubuntu-latest
kind: test_release
- os: ubuntu-latest
kind: test_debug

env:
CARGO_INCREMENTAL: 0
RUST_BACKTRACE: full

steps:
- uses: actions/checkout@v3
- uses: dsherret/rust-toolchain-file@v1
- name: Install wasm32 target
if: matrix.config.kind == 'test_release'
run: rustup target add wasm32-unknown-unknown

- uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}

- name: Build debug
if: matrix.config.kind == 'test_debug'
run: cargo build
- name: Build release
if: matrix.config.kind == 'test_release'
run: cargo build --target wasm32-unknown-unknown --features wasm --release

- name: Test debug
if: matrix.config.kind == 'test_debug'
run: cargo test
- name: Test release
if: matrix.config.kind == 'test_release'
run: cargo test --release

- name: Get tag version
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
id: get_tag_version
run: echo ::set-output name=TAG_VERSION::${GITHUB_REF/refs\/tags\//}

# NPM
- uses: actions/setup-node@v2
if: matrix.config.kind == 'test_release'
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'

- name: Setup and test npm deployment
if: matrix.config.kind == 'test_release'
run: |
cd deployment/npm
npm install
node setup.js ${{ steps.get_tag_version.outputs.TAG_VERSION }}
npm run test
- name: npm publish
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd deployment/npm
npm publish --access public
git reset --hard
# CARGO PUBLISH
# temporarily disabled until Ruff publishes to crates.io
# - name: Cargo login
# if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
# run: cargo login ${{ secrets.CRATES_TOKEN }}

# - name: Cargo publish
# if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
# run: cargo publish

# GITHUB RELEASE
- name: Pre-release
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
run: |
# update config schema to have version
sed -i 's/ruff\/0.0.0/ruff\/${{ steps.get_tag_version.outputs.TAG_VERSION }}/' deployment/schema.json
# rename the wasm file
(cd target/wasm32-unknown-unknown/release/ && mv dprint_plugin_ruff.wasm plugin.wasm)
- name: Release
uses: softprops/action-gh-release@v1
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
target/wasm32-unknown-unknown/release/plugin.wasm
deployment/schema.json
body: |
## Install
[Install](https://dprint.dev/install/) and [setup](https://dprint.dev/setup/) dprint.
Then in your project's directory with a dprint.json file, run:
```shellsession
dprint config add ruff
```
## JS Formatting API
* [JS Formatter](https://github.com/dprint/js-formatter) - Browser/Deno and Node
* [npm package](https://www.npmjs.com/package/@dprint/ruff)
draft: false
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: release

on:
workflow_dispatch:
inputs:
releaseKind:
description: 'Kind of release'
default: 'minor'
type: choice
options:
- patch
- minor
required: true

jobs:
rust:
name: release
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Clone repository
uses: actions/checkout@v3
with:
token: ${{ secrets.GH_DPRINTBOT_PAT }}

- uses: denoland/setup-deno@v1
- uses: dsherret/rust-toolchain-file@v1

- name: Bump version and tag
env:
GITHUB_TOKEN: ${{ secrets.GH_DPRINTBOT_PAT }}
GH_WORKFLOW_ACTOR: ${{ github.actor }}
run: |
git config user.email "${{ github.actor }}@users.noreply.github.com"
git config user.name "${{ github.actor }}"
deno run -A https://raw.githubusercontent.com/dprint/automation/0.8.0/tasks/publish_release.ts --${{github.event.inputs.releaseKind}}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/target
Cargo.lock
deployment/npm/buffer.generated.js
deployment/npm/node_modules
.vscode
3 changes: 3 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
max_width = 120
tab_spaces = 2
edition = "2021"
38 changes: 38 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "dprint-plugin-ruff"
version = "0.0.1"
authors = ["David Sherret <[email protected]>"]
edition = "2021"
homepage = "https://github.com/dprint/dprint-plugin-ruff"
keywords = ["formatting", "formatter", "ruff"]
license = "MIT"
repository = "https://github.com/dprint/dprint-plugin-ruff"
description = "Python formatter for dprint via Ruff."

[lib]
crate-type = ["lib", "cdylib"]

[profile.release]
opt-level = 3
debug = false
lto = true
debug-assertions = false
overflow-checks = false
panic = "abort"

[features]
wasm = ["serde_json", "dprint-core/wasm"]

[dependencies]
anyhow = "1.0.51"
dprint-core = { version = "0.63.3", features = ["formatting"] }
ruff_formatter = { git = "https://github.com/astral-sh/ruff", tag = "v0.1.6" }
ruff_python_ast = { git = "https://github.com/astral-sh/ruff", tag = "v0.1.6" }
ruff_python_formatter = { git = "https://github.com/astral-sh/ruff", tag = "v0.1.6" }
serde = { version = "1.0.108", features = ["derive"] }
serde_json = { version = "1.0", optional = true }

[dev-dependencies]
dprint-development = "0.9.5"
pretty_assertions = "1.4.0"
serde_json = { version = "1.0" }
23 changes: 23 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Ruff: MIT - Copyright (c) 2022 Charles Marsh

The MIT License (MIT)

Copyright (c) 2023 David Sherret

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# dprint-plugin-ruff

[![](https://img.shields.io/crates/v/dprint-plugin-ruff.svg)](https://crates.io/crates/dprint-plugin-ruff) [![CI](https://github.com/dprint/dprint-plugin-ruff/workflows/CI/badge.svg)](https://github.com/dprint/dprint-plugin-ruff/actions?query=workflow%3ACI)

Adapter for [Ruff](https://github.com/astral-sh/ruff) for use as a formatting plugin in [dprint](https://github.com/dprint/dprint).

Formats .py, .pyi, and .ipynb files.

## Install

[Install](https://dprint.dev/install/) and [setup](https://dprint.dev/setup/) dprint.

Then in your project's directory with a dprint.json file, run:

```shellsession
dprint config add ruff
```

## Configuration

To add configuration, specify a `"ruff"` key in your dprint.json:

```jsonc
{
"ruff": {
"indentStyle": "space",
"lineWidth": 100,
"indentWidth": 4
},
"plugins": [
// ...etc...
]
}
```

For an overview of the config, see https://dprint.dev/plugins/ruff/config/

## JS Formatting API

- [JS Formatter](https://github.com/dprint/js-formatter) - Browser/Deno and Node
- [npm package](https://www.npmjs.com/package/@dprint/ruff)

## Versioning

This repo automatically upgrades to the latest version of Ruff once a day. You can check which version of Ruff is being used by looking at the `tag` property in the `ruff_python_formatter` entry in the Cargo.toml file in this repo:

https://github.com/dprint/dprint-plugin-ruff/blob/main/Cargo.toml

At the moment, the version of this plugin does not reflect the version of Ruff. This is just in case there are any small bug fixes that need to be made as this plugin is quite new. After a while I'll try to match the versions.
6 changes: 6 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"imports": {
"automation": "https://raw.githubusercontent.com/dprint/automation/0.8.1/mod.ts",
"octokit": "npm:octokit@^3.1"
}
}
Loading

0 comments on commit a8f5a1e

Please sign in to comment.