Skip to content

Commit b038bc2

Browse files
committed
Remove Python and include any shell scripts
Python has been removed due to lack of possibility to embed. You can anyway use Python scripts as shell scripts with shebangs.
1 parent 6c0f1b6 commit b038bc2

File tree

17 files changed

+380
-288
lines changed

17 files changed

+380
-288
lines changed

.depl/config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pipelines:
4848
supported_langs:
4949
- rust
5050
commands:
51-
- bash_c: cargo clippy --no-default-features --features=tests,python,lua,rhai
51+
- bash_c: cargo clippy --no-default-features --features=lua,rhai
5252
show_success_output: true
5353
- title: Format
5454
info: cargo-format@0.1.0
@@ -70,7 +70,7 @@ pipelines:
7070
supported_langs:
7171
- rust
7272
commands:
73-
- bash_c: cargo build --release --no-default-features --features=tests,python,lua,rhai
73+
- bash_c: cargo build --release --no-default-features --features=lua,rhai
7474
- title: Test
7575
info: cargo-test@0.1.0
7676
tags:
@@ -83,7 +83,7 @@ pipelines:
8383
- rust
8484
commands:
8585
- bash_c: cp tests/*.py .
86-
- bash_c: cargo test --lib --no-default-features --features=tests,python,lua,rhai
86+
- bash_c: cargo test --lib --no-default-features --features=lua,rhai
8787
- title: Compress
8888
info: upx-compress@0.1.0
8989
tags:

Cargo.toml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "smart-patcher"
33
description = "Patcher based on rules"
4-
version = "0.3.0-1"
4+
version = "0.4.0"
55
edition = "2024"
66
license = "MIT"
77
authors = ["Klimenty Titov <aclo.create@gmail.com>"]
@@ -10,20 +10,18 @@ repository = "https://github.com/impulse-sw/smart-patcher"
1010
[dependencies]
1111
anyhow = "1"
1212
clap = { version = "4", features = ["derive"] }
13-
difference-rs = { optional = true, version = "3.2.0" }
13+
difference-rs = "3.2.0"
1414
mimalloc = "0.1"
1515
mlua = { optional = true, version = "0.11", features = ["anyhow", "lua54", "vendored"] }
16-
pyo3 = { optional = true, version = "0.25", features = ["auto-initialize"] }
1716
regex = "1"
1817
rhai = { optional = true, version = "1" }
1918
serde = { version = "1", features = ["derive"] }
2019
serde_json = "1"
20+
uuid = { version = "1.18.0", features = ["v4"] }
2121
walkdir = "2.5"
2222

2323
[features]
24-
default = ["tests", "generate-patches"]
25-
tests = ["dep:difference-rs"]
26-
generate-patches = ["python", "lua", "rhai"]
27-
python = ["dep:pyo3"]
24+
default = []
25+
generate-patches = ["lua", "rhai"]
2826
lua = ["dep:mlua"]
2927
rhai = ["dep:rhai"]

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Patcher based on rules. Written for [Deployer](https://github.com/impulse-sw/dep
44

55
Features:
66

7-
- script support (Python, Lua, Rhai) - to find, replace, or decode/encode
7+
- embedded script support (Lua, Rhai) - to find, replace, or decode/encode
8+
- any shell command support - to find, replace, or decode/encode
89
- regexes
910

1011
## Build
@@ -38,7 +39,7 @@ Also you can use `smart-patcher` as library and even specify needed features:
3839

3940
```toml
4041
[dependencies]
41-
smart-patcher = { version = "0.3.0", default-features = false, features = ["python", "lua", "rhai"] }
42+
smart-patcher = { version = "0.4", features = ["lua", "rhai"] }
4243
```
4344

4445
## Patches
@@ -92,7 +93,7 @@ There are several rule types to cut text sections step by step:
9293
2. `not_contains` - nearly the same
9394
3. `before` and `after` - cuts the patchable area before and after specified regular expression matches
9495
4. `cursor_at_begin` and `cursor_at_end` - moves the `inplace` cursor at begin or at end of the text area
95-
5. `find_by_{lua,python,rhai}` - cuts the section by Lua/Python/Rhai script
96+
5. `find_by_{lua,sh,rhai}` - cuts the section by Lua/Rhai or shell script
9697

9798
This is how a step by step set looks like:
9899

@@ -109,7 +110,7 @@ This is how a step by step set looks like:
109110
"after": "...but after this."
110111
},
111112
{
112-
"find_by_python": "some_script_afterall.py"
113+
"find_by_sh": "some_script_afterall.py"
113114
}
114115
]
115116
}
@@ -152,12 +153,20 @@ See the `tests/test_v5.py` example (and `tests/test_v5.docx` file). This is simp
152153
```json
153154
{
154155
"decoder": {
155-
"python": "tests/test_v5.py"
156+
"sh": "tests/test_v5.py"
156157
},
157158
"encoder": {
158-
"python": "tests/test_v5.py"
159+
"sh": "tests/test_v5.py"
159160
},
160161
}
161162
```
162163

163-
You can also specify `lua` and `rhai` values instead of `python`.
164+
You can also specify `lua` and `rhai` values instead of `sh`.
165+
166+
### 5. Shell vs Rhai/Lua (`0.3` -> `0.4` migration)
167+
168+
If `lua` or `rhai` feature is enabled, `smart-patcher` can patch files without any external runtime dependencies. Unfortunately, Python can't be embedded within `smart-patcher` due to `pyo3` library, therefore now you can choose to shebang your Python scripts and use them again.
169+
170+
Nevertheless, API was slightly changed. Requests are written in JSON files and responses are read from JSON files too. See Python scripts implementations in `tests` folder to see how them are adapted to new `smart-patcher`.
171+
172+
For novices, in `smart-patcher v0.4` you can propose any scripts to handle next patch tasks: find, replace, and decode from/encode to any binary data. For Rhai/Lua scripts, you should write functions with proposed names (`find`, `replace`, `decode` and `encode`), and for shell scripts you should use file system I/O and JSON utilities to read requests and write responses in paths provided by command arguments.

examples/patch4.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"after": "new "
1111
},
1212
{
13-
"find_by_python": "../tests/test_v4.py"
13+
"find_by_sh": "../tests/test_v4.py"
1414
}
1515
],
1616
"insert": " v2"

examples/patch5.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
}
88
],
99
"decoder": {
10-
"python": "../tests/test_v5.py"
10+
"sh": "../tests/test_v5.py"
1111
},
1212
"encoder": {
13-
"python": "../tests/test_v5.py"
13+
"sh": "../tests/test_v5.py"
1414
},
1515
"patch_area": [],
1616
"insert": {

examples/patch8.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"files": [],
55
"patch_area": [],
66
"replace": {
7-
"by_python": "../tests/test_v8.py"
7+
"by_sh": "../tests/test_v8.py"
88
}
99
}
1010
]

examples/patch9.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"files": [],
55
"patch_area": [],
66
"replace": {
7-
"by_python": "../tests/test_v9.py"
7+
"by_sh": "../tests/test_v9.py"
88
}
99
}
1010
]

src/cmd.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub(crate) enum SmartPatcherExecType {
1414
/// Apply patches
1515
Apply(PatchParams),
1616

17-
#[cfg(feature = "tests")]
1817
/// Test run
1918
Test(PatchParams),
2019

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@
88
//! - regex support
99
//! - Python, Lua and Rhai scripts support (featured by `python`, `lua` and `rhai`)
1010
//!
11-
//! See [PatchFile] for further details.
11+
//! See [`PatchFile`] for further details.
1212
13-
#![feature(let_chains)]
13+
#![feature(let_chains, exit_status_error)]
1414
#![deny(missing_docs)]
1515

1616
pub(crate) mod patch;
1717
pub(crate) mod regex;
1818

1919
#[cfg(feature = "lua")]
2020
pub(crate) mod lua_exec;
21-
#[cfg(feature = "python")]
22-
pub(crate) mod python_exec;
2321
#[cfg(feature = "rhai")]
2422
pub(crate) mod rhai_exec;
23+
pub(crate) mod sh_exec;
2524

2625
pub use crate::patch::{AreaRule, DecodeBy, EncodeBy, FilePath, Patch, PatchFile, Replacer};
2726
pub use crate::regex::RegexIR;

src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(let_chains)]
1+
#![feature(let_chains, exit_status_error)]
22
#![deny(warnings, clippy::todo, clippy::unimplemented)]
33

44
pub(crate) mod cmd;
@@ -7,10 +7,9 @@ pub(crate) mod regex;
77

88
#[cfg(feature = "lua")]
99
pub(crate) mod lua_exec;
10-
#[cfg(feature = "python")]
11-
pub(crate) mod python_exec;
1210
#[cfg(feature = "rhai")]
1311
pub(crate) mod rhai_exec;
12+
pub(crate) mod sh_exec;
1413

1514
use mimalloc::MiMalloc;
1615

@@ -36,7 +35,6 @@ fn main() -> anyhow::Result<()> {
3635

3736
patches.patch(&params.work_at, &patch_dir)?;
3837
}
39-
#[cfg(feature = "tests")]
4038
SmartPatcherExecType::Test(params) => {
4139
let mut patch_dir = params.patch.clone();
4240
patch_dir.pop();

0 commit comments

Comments
 (0)