Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Nov 24, 2023
0 parents commit 6109952
Show file tree
Hide file tree
Showing 20 changed files with 1,021 additions and 0 deletions.
125 changes: 125 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
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\//}

# todo: waiting on https://github.com/dprint/js-formatter/issues/2
# 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
- 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/jupyter\/0.0.0/jupyter\/${{ steps.get_tag_version.outputs.TAG_VERSION }}/' deployment/schema.json
# rename the wasm file
(cd target/wasm32-unknown-unknown/release/ && mv dprint_plugin_jupyter.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 jupyter
```
Then add some additional formatting plugins to format the code blocks with. For example:
```shellsession
dprint config add typescript
dprint config add markdown
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/jupyter)
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"
36 changes: 36 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "dprint-plugin-jupyter"
version = "0.0.1"
authors = ["David Sherret <[email protected]>"]
edition = "2021"
homepage = "https://github.com/dprint/dprint-plugin-jupyter"
keywords = ["formatting", "formatter", "jupyter"]
license = "MIT"
repository = "https://github.com/dprint/dprint-plugin-jupyter"
description = "Formats code blocks in Jupyter notebooks."

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

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

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

[dependencies]
anyhow = "1.0.51"
dprint-core = { version = "0.63.3", features = ["formatting"] }
jsonc-parser = "0.23.0"
serde = { version = "1.0.108", features = ["derive"] }
serde_json = "1.0"

[dev-dependencies]
dprint-development = "0.9.5"
pretty_assertions = "1.4.0"
serde_json = { version = "1.0" }
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# dprint-plugin-jupyter

[![](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)

Formats code blocks in Jupyter notebook files (`.ipynb`) using dprint plugins.

## 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 jupyter
```

Then add some additional formatting plugins to format the code blocks with. For example:

```shellsession
dprint config add typescript
dprint config add markdown
dprint config add ruff
```

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).

## Configuration

Configuration is handled in other plugins.
7 changes: 7 additions & 0 deletions deployment/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://plugins.dprint.dev/dprint/dprint-plugin-jupyter/0.0.0/schema.json",
"type": "object",
"properties": {
}
}
21 changes: 21 additions & 0 deletions dprint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"exec": {
"commands": [{
"command": "rustfmt",
"exts": ["rs"]
}]
},
"excludes": [
"**/node_modules",
"**/*-lock.json",
"deployment/npm/buffer.generated.js",
"**/target"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.88.4.wasm",
"https://plugins.dprint.dev/json-0.19.0.wasm",
"https://plugins.dprint.dev/markdown-0.16.2.wasm",
"https://plugins.dprint.dev/toml-0.5.4.wasm",
"https://plugins.dprint.dev/exec-0.4.4.json@c207bf9b9a4ee1f0ecb75c594f774924baf62e8e53a2ce9d873816a408cecbf7"
]
}
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.74.0"
components = ["clippy", "rustfmt"]
6 changes: 6 additions & 0 deletions src/configuration/configuration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use serde::Deserialize;
use serde::Serialize;

#[derive(Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Configuration {}
6 changes: 6 additions & 0 deletions src/configuration/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[allow(clippy::module_inception)]
mod configuration;
mod resolve_config;

pub use configuration::*;
pub use resolve_config::*;
41 changes: 41 additions & 0 deletions src/configuration/resolve_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use super::Configuration;
use dprint_core::configuration::*;

/// Resolves configuration from a collection of key value strings.
///
/// # Example
///
/// ```
/// use dprint_core::configuration::ConfigKeyMap;
/// use dprint_core::configuration::resolve_global_config;
/// use dprint_plugin_jupyter::configuration::resolve_config;
///
/// let mut config_map = ConfigKeyMap::new(); // get a collection of key value pairs from somewhere
/// let global_config_result = resolve_global_config(&mut config_map);
///
/// // check global_config_result.diagnostics here...
///
/// let config_result = resolve_config(
/// config_map,
/// &global_config_result.config
/// );
///
/// // check config_result.diagnostics here and use config_result.config
/// ```
pub fn resolve_config(
config: ConfigKeyMap,
_global_config: &GlobalConfiguration,
) -> ResolveConfigurationResult<Configuration> {
let mut diagnostics = Vec::new();

let resolved_config = Configuration {
// todo...
};

diagnostics.extend(get_unknown_property_diagnostics(config));

ResolveConfigurationResult {
config: resolved_config,
diagnostics,
}
}
Loading

0 comments on commit 6109952

Please sign in to comment.