Skip to content

Commit 6109952

Browse files
committed
Initial commit.
0 parents  commit 6109952

20 files changed

+1021
-0
lines changed

.github/workflows/ci.yml

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
name: ${{ matrix.config.kind }} ${{ matrix.config.os }}
8+
runs-on: ${{ matrix.config.os }}
9+
strategy:
10+
matrix:
11+
config:
12+
- os: ubuntu-latest
13+
kind: test_release
14+
- os: ubuntu-latest
15+
kind: test_debug
16+
17+
env:
18+
CARGO_INCREMENTAL: 0
19+
RUST_BACKTRACE: full
20+
21+
steps:
22+
- uses: actions/checkout@v3
23+
- uses: dsherret/rust-toolchain-file@v1
24+
- name: Install wasm32 target
25+
if: matrix.config.kind == 'test_release'
26+
run: rustup target add wasm32-unknown-unknown
27+
28+
- uses: Swatinem/rust-cache@v2
29+
with:
30+
save-if: ${{ github.ref == 'refs/heads/main' }}
31+
32+
- name: Build debug
33+
if: matrix.config.kind == 'test_debug'
34+
run: cargo build
35+
- name: Build release
36+
if: matrix.config.kind == 'test_release'
37+
run: cargo build --target wasm32-unknown-unknown --features wasm --release
38+
39+
- name: Test debug
40+
if: matrix.config.kind == 'test_debug'
41+
run: cargo test
42+
- name: Test release
43+
if: matrix.config.kind == 'test_release'
44+
run: cargo test --release
45+
46+
- name: Get tag version
47+
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
48+
id: get_tag_version
49+
run: echo ::set-output name=TAG_VERSION::${GITHUB_REF/refs\/tags\//}
50+
51+
# todo: waiting on https://github.com/dprint/js-formatter/issues/2
52+
# NPM
53+
# - uses: actions/setup-node@v2
54+
# if: matrix.config.kind == 'test_release'
55+
# with:
56+
# node-version: '18.x'
57+
# registry-url: 'https://registry.npmjs.org'
58+
59+
# - name: Setup and test npm deployment
60+
# if: matrix.config.kind == 'test_release'
61+
# run: |
62+
# cd deployment/npm
63+
# npm install
64+
# node setup.js ${{ steps.get_tag_version.outputs.TAG_VERSION }}
65+
# npm run test
66+
67+
# - name: npm publish
68+
# if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
69+
# env:
70+
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
71+
# run: |
72+
# cd deployment/npm
73+
# npm publish --access public
74+
# git reset --hard
75+
76+
# CARGO PUBLISH
77+
- name: Cargo login
78+
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
79+
run: cargo login ${{ secrets.CRATES_TOKEN }}
80+
81+
- name: Cargo publish
82+
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
83+
run: cargo publish
84+
85+
# GITHUB RELEASE
86+
- name: Pre-release
87+
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
88+
run: |
89+
# update config schema to have version
90+
sed -i 's/jupyter\/0.0.0/jupyter\/${{ steps.get_tag_version.outputs.TAG_VERSION }}/' deployment/schema.json
91+
# rename the wasm file
92+
(cd target/wasm32-unknown-unknown/release/ && mv dprint_plugin_jupyter.wasm plugin.wasm)
93+
- name: Release
94+
uses: softprops/action-gh-release@v1
95+
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
96+
env:
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98+
with:
99+
files: |
100+
target/wasm32-unknown-unknown/release/plugin.wasm
101+
deployment/schema.json
102+
body: |
103+
## Install
104+
105+
[Install](https://dprint.dev/install/) and [setup](https://dprint.dev/setup/) dprint.
106+
107+
Then in your project's directory with a dprint.json file, run:
108+
109+
```shellsession
110+
dprint config add jupyter
111+
```
112+
113+
Then add some additional formatting plugins to format the code blocks with. For example:
114+
115+
```shellsession
116+
dprint config add typescript
117+
dprint config add markdown
118+
dprint config add ruff
119+
```
120+
121+
# ## JS Formatting API
122+
123+
# * [JS Formatter](https://github.com/dprint/js-formatter) - Browser/Deno and Node
124+
# * [npm package](https://www.npmjs.com/package/@dprint/jupyter)
125+
draft: false

.github/workflows/release.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
releaseKind:
7+
description: 'Kind of release'
8+
default: 'minor'
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
required: true
14+
15+
jobs:
16+
rust:
17+
name: release
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 30
20+
21+
steps:
22+
- name: Clone repository
23+
uses: actions/checkout@v3
24+
with:
25+
token: ${{ secrets.GH_DPRINTBOT_PAT }}
26+
27+
- uses: denoland/setup-deno@v1
28+
- uses: dsherret/rust-toolchain-file@v1
29+
30+
- name: Bump version and tag
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GH_DPRINTBOT_PAT }}
33+
GH_WORKFLOW_ACTOR: ${{ github.actor }}
34+
run: |
35+
git config user.email "${{ github.actor }}@users.noreply.github.com"
36+
git config user.name "${{ github.actor }}"
37+
deno run -A https://raw.githubusercontent.com/dprint/automation/0.8.0/tasks/publish_release.ts --${{github.event.inputs.releaseKind}}

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/target
2+
Cargo.lock
3+
deployment/npm/buffer.generated.js
4+
deployment/npm/node_modules
5+
.vscode

.rustfmt.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
max_width = 120
2+
tab_spaces = 2
3+
edition = "2021"

Cargo.toml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[package]
2+
name = "dprint-plugin-jupyter"
3+
version = "0.0.1"
4+
authors = ["David Sherret <[email protected]>"]
5+
edition = "2021"
6+
homepage = "https://github.com/dprint/dprint-plugin-jupyter"
7+
keywords = ["formatting", "formatter", "jupyter"]
8+
license = "MIT"
9+
repository = "https://github.com/dprint/dprint-plugin-jupyter"
10+
description = "Formats code blocks in Jupyter notebooks."
11+
12+
[lib]
13+
crate-type = ["lib", "cdylib"]
14+
15+
[profile.release]
16+
opt-level = 3
17+
debug = false
18+
lto = true
19+
debug-assertions = false
20+
overflow-checks = false
21+
panic = "abort"
22+
23+
[features]
24+
wasm = ["dprint-core/wasm"]
25+
26+
[dependencies]
27+
anyhow = "1.0.51"
28+
dprint-core = { version = "0.63.3", features = ["formatting"] }
29+
jsonc-parser = "0.23.0"
30+
serde = { version = "1.0.108", features = ["derive"] }
31+
serde_json = "1.0"
32+
33+
[dev-dependencies]
34+
dprint-development = "0.9.5"
35+
pretty_assertions = "1.4.0"
36+
serde_json = { version = "1.0" }

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2023 David Sherret
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# dprint-plugin-jupyter
2+
3+
[![](https://img.shields.io/crates/v/dprint-plugin-jupyter.svg)](https://crates.io/crates/dprint-plugin-jupyter) [![CI](https://github.com/dprint/dprint-plugin-jupyter/workflows/CI/badge.svg)](https://github.com/dprint/dprint-plugin-jupyter/actions?query=workflow%3ACI)
4+
5+
Formats code blocks in Jupyter notebook files (`.ipynb`) using dprint plugins.
6+
7+
## Install
8+
9+
[Install](https://dprint.dev/install/) and [setup](https://dprint.dev/setup/) dprint.
10+
11+
Then in your project's directory with a dprint.json file, run:
12+
13+
```shellsession
14+
dprint config add jupyter
15+
```
16+
17+
Then add some additional formatting plugins to format the code blocks with. For example:
18+
19+
```shellsession
20+
dprint config add typescript
21+
dprint config add markdown
22+
dprint config add ruff
23+
```
24+
25+
If you find a code block isn't being formatted with a plugin, please verify it's not a syntax error, then please open an [issue](https://github.com/dprint/dprint-plugin-jupyter/issues) about adding support for that plugin (if you're interested in submitting a PR, it's potentially an easy contribution).
26+
27+
## Configuration
28+
29+
Configuration is handled in other plugins.

deployment/schema.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://plugins.dprint.dev/dprint/dprint-plugin-jupyter/0.0.0/schema.json",
4+
"type": "object",
5+
"properties": {
6+
}
7+
}

dprint.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"exec": {
3+
"commands": [{
4+
"command": "rustfmt",
5+
"exts": ["rs"]
6+
}]
7+
},
8+
"excludes": [
9+
"**/node_modules",
10+
"**/*-lock.json",
11+
"deployment/npm/buffer.generated.js",
12+
"**/target"
13+
],
14+
"plugins": [
15+
"https://plugins.dprint.dev/typescript-0.88.4.wasm",
16+
"https://plugins.dprint.dev/json-0.19.0.wasm",
17+
"https://plugins.dprint.dev/markdown-0.16.2.wasm",
18+
"https://plugins.dprint.dev/toml-0.5.4.wasm",
19+
"https://plugins.dprint.dev/exec-0.4.4.json@c207bf9b9a4ee1f0ecb75c594f774924baf62e8e53a2ce9d873816a408cecbf7"
20+
]
21+
}

rust-toolchain.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "1.74.0"
3+
components = ["clippy", "rustfmt"]

src/configuration/configuration.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use serde::Deserialize;
2+
use serde::Serialize;
3+
4+
#[derive(Default, Clone, Serialize, Deserialize)]
5+
#[serde(rename_all = "camelCase")]
6+
pub struct Configuration {}

src/configuration/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[allow(clippy::module_inception)]
2+
mod configuration;
3+
mod resolve_config;
4+
5+
pub use configuration::*;
6+
pub use resolve_config::*;

src/configuration/resolve_config.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use super::Configuration;
2+
use dprint_core::configuration::*;
3+
4+
/// Resolves configuration from a collection of key value strings.
5+
///
6+
/// # Example
7+
///
8+
/// ```
9+
/// use dprint_core::configuration::ConfigKeyMap;
10+
/// use dprint_core::configuration::resolve_global_config;
11+
/// use dprint_plugin_jupyter::configuration::resolve_config;
12+
///
13+
/// let mut config_map = ConfigKeyMap::new(); // get a collection of key value pairs from somewhere
14+
/// let global_config_result = resolve_global_config(&mut config_map);
15+
///
16+
/// // check global_config_result.diagnostics here...
17+
///
18+
/// let config_result = resolve_config(
19+
/// config_map,
20+
/// &global_config_result.config
21+
/// );
22+
///
23+
/// // check config_result.diagnostics here and use config_result.config
24+
/// ```
25+
pub fn resolve_config(
26+
config: ConfigKeyMap,
27+
_global_config: &GlobalConfiguration,
28+
) -> ResolveConfigurationResult<Configuration> {
29+
let mut diagnostics = Vec::new();
30+
31+
let resolved_config = Configuration {
32+
// todo...
33+
};
34+
35+
diagnostics.extend(get_unknown_property_diagnostics(config));
36+
37+
ResolveConfigurationResult {
38+
config: resolved_config,
39+
diagnostics,
40+
}
41+
}

0 commit comments

Comments
 (0)