asterust 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. asterust-0.1.0/.github/workflows/ci.yml +57 -0
  2. asterust-0.1.0/.github/workflows/publish-pypi.yml +65 -0
  3. asterust-0.1.0/.github/workflows/publish.yml +26 -0
  4. asterust-0.1.0/.gitignore +55 -0
  5. asterust-0.1.0/AGENTS.md +114 -0
  6. asterust-0.1.0/Cargo.lock +192 -0
  7. asterust-0.1.0/Cargo.toml +16 -0
  8. asterust-0.1.0/LICENSE-APACHE +201 -0
  9. asterust-0.1.0/LICENSE-MIT +21 -0
  10. asterust-0.1.0/Makefile +41 -0
  11. asterust-0.1.0/PKG-INFO +45 -0
  12. asterust-0.1.0/README.md +57 -0
  13. asterust-0.1.0/crates/asterust-iosxr/Cargo.toml +14 -0
  14. asterust-0.1.0/crates/asterust-iosxr/LICENSE-APACHE +201 -0
  15. asterust-0.1.0/crates/asterust-iosxr/LICENSE-MIT +21 -0
  16. asterust-0.1.0/crates/asterust-iosxr/README.md +26 -0
  17. asterust-0.1.0/crates/asterust-iosxr/src/bgp.rs +118 -0
  18. asterust-0.1.0/crates/asterust-iosxr/src/device.rs +78 -0
  19. asterust-0.1.0/crates/asterust-iosxr/src/interface.rs +102 -0
  20. asterust-0.1.0/crates/asterust-iosxr/src/isis.rs +72 -0
  21. asterust-0.1.0/crates/asterust-iosxr/src/lib.rs +38 -0
  22. asterust-0.1.0/crates/asterust-iosxr/src/ospf.rs +101 -0
  23. asterust-0.1.0/crates/asterust-iosxr/tests/full_config.rs +51 -0
  24. asterust-0.1.0/crates/asterust-py/Cargo.toml +20 -0
  25. asterust-0.1.0/crates/asterust-py/README.md +34 -0
  26. asterust-0.1.0/crates/asterust-py/src/config.rs +169 -0
  27. asterust-0.1.0/crates/asterust-py/src/iosxr.rs +194 -0
  28. asterust-0.1.0/crates/asterust-py/src/lib.rs +22 -0
  29. asterust-0.1.0/crates/asterust-py/tests/test_config.py +34 -0
  30. asterust-0.1.0/crates/asterust-py/tests/test_iosxr.py +88 -0
  31. asterust-0.1.0/pyproject.toml +23 -0
  32. asterust-0.1.0/python/asterust/__init__.py +5 -0
  33. asterust-0.1.0/python/asterust/iosxr.py +21 -0
  34. asterust-0.1.0/rustfmt.toml +1 -0
  35. asterust-0.1.0/src/config/cisco.rs +153 -0
  36. asterust-0.1.0/src/config/juniper.rs +162 -0
  37. asterust-0.1.0/src/config/mod.rs +302 -0
  38. asterust-0.1.0/src/lib.rs +6 -0
  39. asterust-0.1.0/tests/config_cisco.rs +102 -0
  40. asterust-0.1.0/tests/config_juniper.rs +89 -0
@@ -0,0 +1,57 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ env:
9
+ CARGO_TERM_COLOR: always
10
+
11
+ jobs:
12
+ test:
13
+ name: Test
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - name: Install Rust
19
+ uses: dtolnay/rust-toolchain@stable
20
+ with:
21
+ components: clippy, rustfmt
22
+
23
+ - name: Cache cargo
24
+ uses: Swatinem/rust-cache@v2
25
+
26
+ - name: Check formatting
27
+ run: cargo fmt --all -- --check
28
+
29
+ - name: Clippy
30
+ run: cargo clippy --workspace --all-targets -- -D warnings
31
+
32
+ - name: Test
33
+ run: cargo test --workspace --all-targets
34
+
35
+ python:
36
+ name: Python bindings
37
+ runs-on: ubuntu-latest
38
+ steps:
39
+ - uses: actions/checkout@v4
40
+
41
+ - name: Install Rust
42
+ uses: dtolnay/rust-toolchain@stable
43
+
44
+ - name: Cache cargo
45
+ uses: Swatinem/rust-cache@v2
46
+
47
+ - name: Install uv
48
+ uses: astral-sh/setup-uv@v6
49
+
50
+ - name: Build extension and run pytest
51
+ working-directory: crates/asterust-py
52
+ run: |
53
+ uv venv
54
+ source .venv/bin/activate
55
+ uv pip install maturin pytest
56
+ maturin develop
57
+ python -m pytest
@@ -0,0 +1,65 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags: ['py-v*']
6
+
7
+ jobs:
8
+ wheels:
9
+ name: Wheels (${{ matrix.os }}, ${{ matrix.target }})
10
+ runs-on: ${{ matrix.os }}
11
+ strategy:
12
+ matrix:
13
+ include:
14
+ - { os: ubuntu-latest, target: x86_64 }
15
+ - { os: ubuntu-latest, target: aarch64 }
16
+ - { os: macos-latest, target: x86_64 }
17
+ - { os: macos-latest, target: aarch64 }
18
+ - { os: windows-latest, target: x64 }
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+
22
+ - name: Build wheel
23
+ uses: PyO3/maturin-action@v1
24
+ with:
25
+ target: ${{ matrix.target }}
26
+ command: build
27
+ args: --release --out dist -m crates/asterust-py/Cargo.toml
28
+ manylinux: auto
29
+
30
+ - uses: actions/upload-artifact@v4
31
+ with:
32
+ name: wheels-${{ matrix.os }}-${{ matrix.target }}
33
+ path: dist
34
+
35
+ sdist:
36
+ name: Source distribution
37
+ runs-on: ubuntu-latest
38
+ steps:
39
+ - uses: actions/checkout@v4
40
+
41
+ - name: Build sdist
42
+ uses: PyO3/maturin-action@v1
43
+ with:
44
+ command: sdist
45
+ args: --out dist -m crates/asterust-py/Cargo.toml
46
+
47
+ - uses: actions/upload-artifact@v4
48
+ with:
49
+ name: sdist
50
+ path: dist
51
+
52
+ publish:
53
+ needs: [wheels, sdist]
54
+ runs-on: ubuntu-latest
55
+ environment: pypi
56
+ permissions:
57
+ id-token: write # required for PyPI Trusted Publishing
58
+ steps:
59
+ - uses: actions/download-artifact@v4
60
+ with:
61
+ path: dist
62
+ merge-multiple: true
63
+
64
+ - name: Publish
65
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,26 @@
1
+ name: Publish to crates.io
2
+
3
+ on:
4
+ push:
5
+ tags: ['v*']
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ environment: release
11
+ permissions:
12
+ id-token: write # required for OIDC token exchange with crates.io
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Install Rust
17
+ uses: dtolnay/rust-toolchain@stable
18
+
19
+ - name: Authenticate with crates.io (Trusted Publishing)
20
+ uses: rust-lang/crates-io-auth-action@v1
21
+ id: auth
22
+
23
+ - name: Publish
24
+ run: cargo publish -p asterust
25
+ env:
26
+ CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
@@ -0,0 +1,55 @@
1
+ /target
2
+ Cargo.lock
3
+
4
+ # ==============================================================================
5
+ # OS-Specific System Files
6
+ # ==============================================================================
7
+ # macOS
8
+ .DS_Store
9
+ .AppleDouble
10
+ .LSOverride
11
+
12
+ # Windows
13
+ Thumbs.db
14
+ ehthumbs.db
15
+ Desktop.ini
16
+
17
+ # Linux
18
+ *~
19
+ .directory
20
+
21
+ # ==============================================================================
22
+ # Common Development Junk (Optional but recommended)
23
+ # ==============================================================================
24
+ # IDEs and Text Editors
25
+ .vscode/
26
+ .idea/
27
+ *.swp
28
+ *.swo
29
+
30
+ # Log files and temporary files
31
+ *.log
32
+ *.tmp
33
+ *.bak
34
+
35
+ # Generated by Cargo
36
+ # Contains compiled files, build artifacts, and executables
37
+ /target/
38
+
39
+ # Backup files generated by rustfmt
40
+ **/*.rs.bk
41
+
42
+ # MSVC Windows builds of rustc generate these, which store debugging information
43
+ *.pdb
44
+
45
+ # rustc will dump stack traces here when hitting an internal compiler error
46
+ rustc-ice-*.txt
47
+
48
+ # Cargo mutants testing data (if you use cargo-mutants)
49
+ **/mutants.out/
50
+
51
+ # Python bindings
52
+ .venv/
53
+ __pycache__/
54
+ *.so
55
+ .pytest_cache/
@@ -0,0 +1,114 @@
1
+ # Agent Guidelines for asterust
2
+
3
+ `asterust` is a small, pure-Rust library: vendor-namespaced hierarchical
4
+ configuration parsing (`config::cisco`, `config::juniper`). It has no
5
+ PyO3/binding dependency of its own — consumers (e.g. a PyO3 extension
6
+ module) add their own bindings on top. The repo is a Cargo workspace:
7
+ platform crates live under `crates/` and depend on this core. These
8
+ guidelines apply to the core crate and, unless noted, the crates under
9
+ `crates/`; prune/extend them if the scope changes.
10
+
11
+ ## Core Principle
12
+
13
+ Write clear, correct, idiomatic Rust. Prioritize clarity and
14
+ maintainability over cleverness — this is a library other code will
15
+ depend on, so predictable, well-tested behavior matters more than
16
+ micro-optimization.
17
+
18
+ ## Code Style and Formatting
19
+
20
+ - Use `rustfmt` (config in `rustfmt.toml`, `max_width = 120` to match
21
+ the `ruff line-length = 120` convention used in sibling projects).
22
+ - Use meaningful, descriptive names. `snake_case` for
23
+ functions/variables/modules, `PascalCase` for types/traits,
24
+ `SCREAMING_SNAKE_CASE` for constants.
25
+ - Follow idiomatic Rust / the Rust API Guidelines.
26
+ - No emoji or unicode that emulates emoji, except when a test is
27
+ specifically exercising multibyte/unicode handling.
28
+ - Avoid redundant comments that just restate what the next line does.
29
+ A comment should explain *why*, not *what*, when the *what* is
30
+ already obvious from the code.
31
+
32
+ ## Documentation
33
+
34
+ - Public functions, structs, enums, and methods should have doc
35
+ comments explaining purpose, non-obvious parameters, and return
36
+ value. Match the existing style in this crate (see `src/config/mod.rs`,
37
+ `src/config/cisco.rs`) rather than a generic template — most functions
38
+ here need only 1-3 lines, not full `# Arguments`/`# Returns` sections.
39
+ - Keep doc comments up to date with the code; stale docs are worse
40
+ than no docs.
41
+
42
+ ## Error Handling
43
+
44
+ - Prefer `Option<T>` for "not found" / "didn't match" cases — this is
45
+ the common case in a parser (e.g. `find_child_with`, `find_line_with`,
46
+ `match_str_group` all return `Option`, not an error).
47
+ - Reserve `Result<T, E>` for operations that can genuinely fail with
48
+ information the caller needs to act on. None of the current public
49
+ API needs this; don't introduce `thiserror`/`anyhow` speculatively —
50
+ add them only when a real fallible operation needs them.
51
+ - `.unwrap()` is acceptable only on a compile-time-constant invariant
52
+ (e.g. `Regex::new("...a hardcoded, known-valid pattern...").unwrap()`).
53
+ Prefer `.expect("why this can't fail")` over bare `.unwrap()` in new
54
+ code so a panic (if the invariant is ever violated by a future edit)
55
+ is self-explanatory.
56
+ - Never `.unwrap()` on anything derived from external/caller-supplied
57
+ input.
58
+
59
+ ## Function and Type Design
60
+
61
+ - Keep functions focused on a single responsibility.
62
+ - Prefer borrowing (`&T`, `&str`) over taking ownership when the
63
+ function doesn't need it.
64
+ - Return early to reduce nesting.
65
+ - Prefer iterator adapters over manual loops where it's at least as
66
+ clear (don't force it when a plain loop reads better).
67
+ - Derive `Debug`, `Clone`, `PartialEq`/`Eq` where appropriate (see
68
+ `ConfigLine`).
69
+ - Public fields are fine where the type is a plain data holder with no
70
+ invariants to protect (e.g. `ConfigLine.text`, `ConfigBlock.root_line`,
71
+ `Config.blocks`) — don't add accessor boilerplate for its own sake.
72
+
73
+ ## Testing
74
+
75
+ - Unit tests (`#[cfg(test)] mod tests` inline in the same file) for
76
+ anything that needs access to private helpers — most tests in this
77
+ crate are this kind.
78
+ - Black-box integration tests (`tests/*.rs`, a separate crate, `pub`
79
+ API only) for end-to-end scenarios a real consumer would hit — see
80
+ `tests/config_cisco.rs`, `tests/config_juniper.rs`.
81
+ - New parsing behavior needs a test with realistic input (a real-ish
82
+ config/capture snippet), not just a trivial one-liner.
83
+ - Don't commit commented-out tests.
84
+
85
+ ## Imports and Dependencies
86
+
87
+ - No wildcard imports except `use super::*;` in test modules.
88
+ - Keep dependencies minimal — this crate exists partly *because*
89
+ pulling in a huge dependency tree for simple text parsing is
90
+ wasteful. Justify any new dependency in the PR description.
91
+ - New dependencies need a version constraint in `Cargo.toml`.
92
+
93
+ ## Version Control
94
+
95
+ - Clear, descriptive commit messages (explain *why* a change was made,
96
+ not just *what* changed — the diff already shows the *what*).
97
+ - Never commit commented-out code, debug `println!`/`dbg!` calls, or
98
+ credentials.
99
+ - Bump `Cargo.toml`'s `version` whenever a branch adds a new feature
100
+ (new module, new public API, new vendor/syntax support) — minor bump
101
+ for features, patch for pure bugfixes. Don't bump for docs/tooling/
102
+ test-only changes.
103
+
104
+ ## Before Committing
105
+
106
+ - [ ] `cargo test` passes
107
+ - [ ] `cargo clippy --all-targets -- -D warnings` passes
108
+ - [ ] `cargo fmt --all -- --check` passes
109
+ - [ ] New public items have doc comments
110
+ - [ ] No commented-out code, debug prints, or credentials
111
+ - [ ] `Cargo.toml` version bumped if this change is a new feature
112
+
113
+ These are exactly the checks `.github/workflows/ci.yml` runs — if all
114
+ four pass locally, CI will pass.
@@ -0,0 +1,192 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "1.1.5"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "asterust"
16
+ version = "0.2.0"
17
+ dependencies = [
18
+ "regex",
19
+ ]
20
+
21
+ [[package]]
22
+ name = "asterust-iosxr"
23
+ version = "0.1.0"
24
+ dependencies = [
25
+ "asterust",
26
+ ]
27
+
28
+ [[package]]
29
+ name = "asterust-py"
30
+ version = "0.1.0"
31
+ dependencies = [
32
+ "asterust",
33
+ "asterust-iosxr",
34
+ "pyo3",
35
+ ]
36
+
37
+ [[package]]
38
+ name = "heck"
39
+ version = "0.5.0"
40
+ source = "registry+https://github.com/rust-lang/crates.io-index"
41
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
42
+
43
+ [[package]]
44
+ name = "libc"
45
+ version = "0.2.191"
46
+ source = "registry+https://github.com/rust-lang/crates.io-index"
47
+ checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
48
+
49
+ [[package]]
50
+ name = "memchr"
51
+ version = "2.8.3"
52
+ source = "registry+https://github.com/rust-lang/crates.io-index"
53
+ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
54
+
55
+ [[package]]
56
+ name = "once_cell"
57
+ version = "1.21.4"
58
+ source = "registry+https://github.com/rust-lang/crates.io-index"
59
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
60
+
61
+ [[package]]
62
+ name = "portable-atomic"
63
+ version = "1.15.0"
64
+ source = "registry+https://github.com/rust-lang/crates.io-index"
65
+ checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
66
+
67
+ [[package]]
68
+ name = "proc-macro2"
69
+ version = "1.0.107"
70
+ source = "registry+https://github.com/rust-lang/crates.io-index"
71
+ checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
72
+ dependencies = [
73
+ "unicode-ident",
74
+ ]
75
+
76
+ [[package]]
77
+ name = "pyo3"
78
+ version = "0.30.1"
79
+ source = "registry+https://github.com/rust-lang/crates.io-index"
80
+ checksum = "229ca13b8a15bb0d1487b81ab975bfcd97513416499a8312011b6036e42e0de4"
81
+ dependencies = [
82
+ "libc",
83
+ "once_cell",
84
+ "portable-atomic",
85
+ "pyo3-build-config",
86
+ "pyo3-ffi",
87
+ "pyo3-macros",
88
+ ]
89
+
90
+ [[package]]
91
+ name = "pyo3-build-config"
92
+ version = "0.30.1"
93
+ source = "registry+https://github.com/rust-lang/crates.io-index"
94
+ checksum = "70130e2b6dd1ee589a8788026a429561ca5c40fa7a2fa7914c2282eddae24700"
95
+ dependencies = [
96
+ "target-lexicon",
97
+ ]
98
+
99
+ [[package]]
100
+ name = "pyo3-ffi"
101
+ version = "0.30.1"
102
+ source = "registry+https://github.com/rust-lang/crates.io-index"
103
+ checksum = "5e7ff73c555c286d212d4ce7e5fbda845a973c4f61bd5f160f5f2c3c2a04d1c4"
104
+ dependencies = [
105
+ "libc",
106
+ "pyo3-build-config",
107
+ ]
108
+
109
+ [[package]]
110
+ name = "pyo3-macros"
111
+ version = "0.30.1"
112
+ source = "registry+https://github.com/rust-lang/crates.io-index"
113
+ checksum = "c46d2e5862c7bb8207e3b639f713dda3c499933444784154c11d013c5a691b60"
114
+ dependencies = [
115
+ "proc-macro2",
116
+ "pyo3-macros-backend",
117
+ "quote",
118
+ "syn",
119
+ ]
120
+
121
+ [[package]]
122
+ name = "pyo3-macros-backend"
123
+ version = "0.30.1"
124
+ source = "registry+https://github.com/rust-lang/crates.io-index"
125
+ checksum = "38b89f066f2ae72a2aef52d1537ca2fcd104440ebfadee06e97aa90738a25b9b"
126
+ dependencies = [
127
+ "heck",
128
+ "proc-macro2",
129
+ "quote",
130
+ "syn",
131
+ ]
132
+
133
+ [[package]]
134
+ name = "quote"
135
+ version = "1.0.47"
136
+ source = "registry+https://github.com/rust-lang/crates.io-index"
137
+ checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
138
+ dependencies = [
139
+ "proc-macro2",
140
+ ]
141
+
142
+ [[package]]
143
+ name = "regex"
144
+ version = "1.13.2"
145
+ source = "registry+https://github.com/rust-lang/crates.io-index"
146
+ checksum = "9807af0e638c12e753aa1b4e601791bf2a8f71274023c8bbeec12fc149950857"
147
+ dependencies = [
148
+ "aho-corasick",
149
+ "memchr",
150
+ "regex-automata",
151
+ "regex-syntax",
152
+ ]
153
+
154
+ [[package]]
155
+ name = "regex-automata"
156
+ version = "0.4.19"
157
+ source = "registry+https://github.com/rust-lang/crates.io-index"
158
+ checksum = "41d60ef07df457506a0a1a2073112eb4aae5733dbd2813c3da77d1b0fd441158"
159
+ dependencies = [
160
+ "aho-corasick",
161
+ "memchr",
162
+ "regex-syntax",
163
+ ]
164
+
165
+ [[package]]
166
+ name = "regex-syntax"
167
+ version = "0.8.12"
168
+ source = "registry+https://github.com/rust-lang/crates.io-index"
169
+ checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6"
170
+
171
+ [[package]]
172
+ name = "syn"
173
+ version = "3.0.10"
174
+ source = "registry+https://github.com/rust-lang/crates.io-index"
175
+ checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
176
+ dependencies = [
177
+ "proc-macro2",
178
+ "quote",
179
+ "unicode-ident",
180
+ ]
181
+
182
+ [[package]]
183
+ name = "target-lexicon"
184
+ version = "0.13.6"
185
+ source = "registry+https://github.com/rust-lang/crates.io-index"
186
+ checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da"
187
+
188
+ [[package]]
189
+ name = "unicode-ident"
190
+ version = "1.0.27"
191
+ source = "registry+https://github.com/rust-lang/crates.io-index"
192
+ checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
@@ -0,0 +1,16 @@
1
+ [package]
2
+ name = "asterust"
3
+ version = "0.2.0"
4
+ edition = "2021"
5
+ description = "Vendor-aware hierarchical configuration parsing for network device CLI output (Cisco-style indentation, Juniper-style braces)."
6
+ license = "MIT OR Apache-2.0"
7
+ repository = "https://github.com/asterust/asterust"
8
+
9
+ [lib]
10
+ name = "asterust"
11
+
12
+ [dependencies]
13
+ regex = "1"
14
+
15
+ [workspace]
16
+ members = [".", "crates/asterust-iosxr", "crates/asterust-py"]