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

feat: support pyment #518

Merged
merged 1 commit into from
Oct 26, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [Unreleased](https://github.com/hougesen/mdsf/compare/v0.2.7...HEAD)

- feat: support pyment [`#518`](https://github.com/hougesen/mdsf/pull/518)
- feat: support sqruff [`#517`](https://github.com/hougesen/mdsf/pull/517)
- feat: support opa fmt [`#516`](https://github.com/hougesen/mdsf/pull/516)
- feat: support purty [`#515`](https://github.com/hougesen/mdsf/pull/515)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ mdsf init

<!-- START_SECTION:supported-tools -->

`mdsf` currently supports 208 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃
`mdsf` currently supports 209 commands. Feel free to open an issue/pull-request if your favorite tool is missing! 😃

| Name | Command |
| ------------------------ | -------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -330,6 +330,7 @@ mdsf init
| `purty` | `purty --write PATH` |
| `pycln` | `pycln --no-gitignore --quiet PATH` |
| `pyink` | `pyink --quiet PATH` |
| `pyment` | `pyment -w PATH` |
| `qmlfmt` | `qmlfmt -w PATH` |
| `raco:fmt` | `raco fmt -i PATH` |
| `refmt` | `refmt --in-place PATH` |
Expand Down
7 changes: 7 additions & 0 deletions mdsf/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub mod purs_tidy;
pub mod purty;
pub mod pycln;
pub mod pyink;
pub mod pyment;
pub mod qmlfmt;
pub mod raco_fmt;
pub mod refmt;
Expand Down Expand Up @@ -779,6 +780,10 @@ pub enum Tooling {
/// `pyink --quiet $PATH`
Pyink,

#[serde(rename = "pyment")]
/// `pyment -w $PATH`
Pyment,

#[serde(rename = "qmlfmt")]
/// `qmlfmt -w $PATH`
Qmlfmt,
Expand Down Expand Up @@ -1194,6 +1199,7 @@ impl Tooling {
Self::Purty => purty::run(snippet_path),
Self::Pycln => pycln::run(snippet_path),
Self::Pyink => pyink::run(snippet_path),
Self::Pyment => pyment::run(snippet_path),
Self::Qmlfmt => qmlfmt::run(snippet_path),
Self::RacoFmt => raco_fmt::run(snippet_path),
Self::Refmt => refmt::run(snippet_path),
Expand Down Expand Up @@ -1411,6 +1417,7 @@ impl AsRef<str> for Tooling {
Self::Purty => "purty",
Self::Pycln => "pycln",
Self::Pyink => "pyink",
Self::Pyment => "pyment",
Self::Qmlfmt => "qmlfmt",
Self::RacoFmt => "raco_fmt",
Self::Refmt => "refmt",
Expand Down
35 changes: 35 additions & 0 deletions mdsf/src/tools/pyment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::process::Command;

use crate::{error::MdsfError, execution::execute_command, runners::CommandType};

#[inline]
fn set_pyment_args(mut cmd: Command, file_path: &std::path::Path) -> Command {
cmd.arg("-w");
cmd.arg(file_path);
cmd
}

#[inline]
pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfError> {
let commands = [CommandType::Direct("pyment")];

for (index, cmd) in commands.iter().enumerate() {
let cmd = set_pyment_args(cmd.build(), file_path);
let execution_result = execute_command(cmd, file_path);

if index == commands.len() - 1 {
return execution_result;
}

if let Ok(r) = execution_result {
if !r.0 {
return Ok(r);
}
}
}

Ok((true, None))
}

#[cfg(test)]
mod test_pyment {}
5 changes: 5 additions & 0 deletions schemas/v0.2.7/mdsf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,11 @@
"type": "string",
"enum": ["pyink"]
},
{
"description": "`pyment -w $PATH`",
"type": "string",
"enum": ["pyment"]
},
{
"description": "`qmlfmt -w $PATH`",
"type": "string",
Expand Down
15 changes: 15 additions & 0 deletions tools/pyment/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../tool.schema.json",
"binary": "pyment",
"categories": ["formatter"],
"commands": {
"": ["-w", "$PATH"]
},
"description": "Format and convert Python docstrings and generates patches",
"homepage": "https://github.com/dadadel/pyment",
"languages": ["python"],
"name": null,
"npm": null,
"php": null,
"tests": []
}
Loading