gitronics 0.5.6__tar.gz → 0.5.8__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 (59) hide show
  1. gitronics-0.5.8/.vscode/settings.json +4 -0
  2. {gitronics-0.5.6 → gitronics-0.5.8}/Cargo.lock +27 -1
  3. {gitronics-0.5.6 → gitronics-0.5.8}/Cargo.toml +2 -1
  4. {gitronics-0.5.6 → gitronics-0.5.8}/PKG-INFO +1 -1
  5. {gitronics-0.5.6 → gitronics-0.5.8}/docs/usage/build.md +20 -0
  6. {gitronics-0.5.6 → gitronics-0.5.8}/python/gitronics/__init__.py +2 -1
  7. gitronics-0.5.8/python/gitronics/__main__.py +3 -0
  8. gitronics-0.5.8/python/gitronics/gitronics.pyi +45 -0
  9. gitronics-0.5.8/python/tests/test_build_model.py +30 -0
  10. {gitronics-0.5.6 → gitronics-0.5.8}/src/build_model.rs +19 -0
  11. {gitronics-0.5.6 → gitronics-0.5.8}/src/project_manager.rs +5 -0
  12. gitronics-0.5.8/src/python.rs +31 -0
  13. {gitronics-0.5.6 → gitronics-0.5.8}/tests/test_example_project.rs +41 -0
  14. gitronics-0.5.6/src/python.rs +0 -16
  15. {gitronics-0.5.6 → gitronics-0.5.8}/.github/workflows/ci.yml +0 -0
  16. {gitronics-0.5.6 → gitronics-0.5.8}/.github/workflows/docs.yml +0 -0
  17. {gitronics-0.5.6 → gitronics-0.5.8}/.github/workflows/release.yml +0 -0
  18. {gitronics-0.5.6 → gitronics-0.5.8}/.gitignore +0 -0
  19. {gitronics-0.5.6 → gitronics-0.5.8}/LICENSE +0 -0
  20. {gitronics-0.5.6 → gitronics-0.5.8}/README.md +0 -0
  21. {gitronics-0.5.6 → gitronics-0.5.8}/docs/assets/logo.png +0 -0
  22. {gitronics-0.5.6 → gitronics-0.5.8}/docs/best-practices.md +0 -0
  23. {gitronics-0.5.6 → gitronics-0.5.8}/docs/changelog.md +0 -0
  24. {gitronics-0.5.6 → gitronics-0.5.8}/docs/examples.md +0 -0
  25. {gitronics-0.5.6 → gitronics-0.5.8}/docs/getting-started.md +0 -0
  26. {gitronics-0.5.6 → gitronics-0.5.8}/docs/index.md +0 -0
  27. {gitronics-0.5.6 → gitronics-0.5.8}/docs/installation.md +0 -0
  28. {gitronics-0.5.6 → gitronics-0.5.8}/docs/requirements.txt +0 -0
  29. {gitronics-0.5.6 → gitronics-0.5.8}/docs/usage/configuration.md +0 -0
  30. {gitronics-0.5.6 → gitronics-0.5.8}/docs/usage/migrate.md +0 -0
  31. {gitronics-0.5.6 → gitronics-0.5.8}/example_project/assessment_specific/filler_model_3.mcnp +0 -0
  32. {gitronics-0.5.6 → gitronics-0.5.8}/example_project/assessment_specific/filler_model_3.metadata +0 -0
  33. {gitronics-0.5.6 → gitronics-0.5.8}/example_project/assessment_specific/small_override.yaml +0 -0
  34. {gitronics-0.5.6 → gitronics-0.5.8}/example_project/configurations/valid_configuration.yaml +0 -0
  35. {gitronics-0.5.6 → gitronics-0.5.8}/example_project/output/.gitignore +0 -0
  36. {gitronics-0.5.6 → gitronics-0.5.8}/example_project/reference_model/data_cards/fine_mesh.tally +0 -0
  37. {gitronics-0.5.6 → gitronics-0.5.8}/example_project/reference_model/data_cards/materials.mat +0 -0
  38. {gitronics-0.5.6 → gitronics-0.5.8}/example_project/reference_model/data_cards/my_transform.transform +0 -0
  39. {gitronics-0.5.6 → gitronics-0.5.8}/example_project/reference_model/data_cards/volumetric_source.source +0 -0
  40. {gitronics-0.5.6 → gitronics-0.5.8}/example_project/reference_model/envelope_structure.mcnp +0 -0
  41. {gitronics-0.5.6 → gitronics-0.5.8}/example_project/reference_model/envelope_structure.metadata +0 -0
  42. {gitronics-0.5.6 → gitronics-0.5.8}/example_project/reference_model/filler_models/filler_model_1.mcnp +0 -0
  43. {gitronics-0.5.6 → gitronics-0.5.8}/example_project/reference_model/filler_models/filler_model_1.metadata +0 -0
  44. {gitronics-0.5.6 → gitronics-0.5.8}/example_project/reference_model/filler_models/filler_model_2.mcnp +0 -0
  45. {gitronics-0.5.6 → gitronics-0.5.8}/example_project/reference_model/filler_models/filler_model_2.metadata +0 -0
  46. {gitronics-0.5.6 → gitronics-0.5.8}/mkdocs.yml +0 -0
  47. {gitronics-0.5.6 → gitronics-0.5.8}/pyproject.toml +0 -0
  48. {gitronics-0.5.6 → gitronics-0.5.8}/python/tests/test_cli_works.py +0 -0
  49. {gitronics-0.5.6 → gitronics-0.5.8}/resources/simple_model.mcnp +0 -0
  50. {gitronics-0.5.6 → gitronics-0.5.8}/src/cli.rs +0 -0
  51. {gitronics-0.5.6 → gitronics-0.5.8}/src/lib.rs +0 -0
  52. {gitronics-0.5.6 → gitronics-0.5.8}/src/main.rs +0 -0
  53. {gitronics-0.5.6 → gitronics-0.5.8}/src/migrate_model.rs +0 -0
  54. {gitronics-0.5.6 → gitronics-0.5.8}/src/model_config.rs +0 -0
  55. {gitronics-0.5.6 → gitronics-0.5.8}/src/project_manager/load_metadata.rs +0 -0
  56. {gitronics-0.5.6 → gitronics-0.5.8}/src/project_manager/load_model_config.rs +0 -0
  57. {gitronics-0.5.6 → gitronics-0.5.8}/src/project_manager/load_project_files.rs +0 -0
  58. {gitronics-0.5.6 → gitronics-0.5.8}/src/types.rs +0 -0
  59. {gitronics-0.5.6 → gitronics-0.5.8}/src/utils.rs +0 -0
@@ -0,0 +1,4 @@
1
+ {
2
+ "python-envs.defaultEnvManager": "ms-python.python:conda",
3
+ "python-envs.defaultPackageManager": "ms-python.python:conda"
4
+ }
@@ -390,7 +390,7 @@ dependencies = [
390
390
 
391
391
  [[package]]
392
392
  name = "gitronics"
393
- version = "0.5.6"
393
+ version = "0.5.8"
394
394
  dependencies = [
395
395
  "chrono",
396
396
  "clap",
@@ -399,6 +399,7 @@ dependencies = [
399
399
  "git2",
400
400
  "indexmap",
401
401
  "log",
402
+ "logtest",
402
403
  "migjorn",
403
404
  "pyo3",
404
405
  "rayon",
@@ -550,6 +551,12 @@ dependencies = [
550
551
  "wasm-bindgen",
551
552
  ]
552
553
 
554
+ [[package]]
555
+ name = "lazy_static"
556
+ version = "1.5.0"
557
+ source = "registry+https://github.com/rust-lang/crates.io-index"
558
+ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
559
+
553
560
  [[package]]
554
561
  name = "leb128fmt"
555
562
  version = "0.1.0"
@@ -597,6 +604,19 @@ name = "log"
597
604
  version = "0.4.29"
598
605
  source = "registry+https://github.com/rust-lang/crates.io-index"
599
606
  checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
607
+ dependencies = [
608
+ "value-bag",
609
+ ]
610
+
611
+ [[package]]
612
+ name = "logtest"
613
+ version = "2.0.0"
614
+ source = "registry+https://github.com/rust-lang/crates.io-index"
615
+ checksum = "eb3e43a8657c1d64516dcc9db8ca03826a4aceaf89d5ce1b37b59f6ff0e43026"
616
+ dependencies = [
617
+ "lazy_static",
618
+ "log",
619
+ ]
600
620
 
601
621
  [[package]]
602
622
  name = "memchr"
@@ -1031,6 +1051,12 @@ version = "0.2.2"
1031
1051
  source = "registry+https://github.com/rust-lang/crates.io-index"
1032
1052
  checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
1033
1053
 
1054
+ [[package]]
1055
+ name = "value-bag"
1056
+ version = "1.12.0"
1057
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1058
+ checksum = "7ba6f5989077681266825251a52748b8c1d8a4ad098cc37e440103d0ea717fc0"
1059
+
1034
1060
  [[package]]
1035
1061
  name = "vcpkg"
1036
1062
  version = "0.2.15"
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "gitronics"
3
- version = "0.5.6"
3
+ version = "0.5.8"
4
4
  edition = "2024"
5
5
  description = "Build MCNP neutronics models from modular components"
6
6
  license = "EUPL-1.2"
@@ -33,3 +33,4 @@ dunce = "1.0.5"
33
33
 
34
34
  [dev-dependencies]
35
35
  tempfile = "3.0"
36
+ logtest = "2.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitronics
3
- Version: 0.5.6
3
+ Version: 0.5.8
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -42,6 +42,26 @@ C ============================================================
42
42
 
43
43
  Gitronics searches all directories listed in `project_roots` (defined in the configuration) for files referenced by stem name. Any file whose stem (name without extension) matches a key in the configuration is a candidate. This means you can organise your project files into subdirectories however you like, as long as each stem name is unique across all `project_roots`.
44
44
 
45
+ ## Python API
46
+
47
+ `build_model` is also available as a Python function for use in scripts and notebooks:
48
+
49
+ ```python
50
+ import gitronics
51
+
52
+ gitronics.build_model(
53
+ "configurations/in_vessel_only.yaml",
54
+ "output/",
55
+ )
56
+ ```
57
+
58
+ | Parameter | Type | Description |
59
+ |---|---|---|
60
+ | `config_path` | `str` or `Path` | Path to the configuration YAML file. |
61
+ | `output_path` | `str` or `Path` | Directory to write `assembled.mcnp` into. |
62
+
63
+ Raises `RuntimeError` on failure with a descriptive message.
64
+
45
65
  ## Logging
46
66
 
47
67
  Set the `RUST_LOG` environment variable to control verbosity:
@@ -10,9 +10,10 @@ from __future__ import annotations
10
10
 
11
11
  import sys
12
12
 
13
+ from .gitronics import py_build_model as build_model # type: ignore[import]
13
14
  from .gitronics import run # type: ignore[import]
14
15
 
15
- __all__ = ["run"]
16
+ __all__ = ["build_model", "run"]
16
17
 
17
18
 
18
19
  def _cli_main() -> None:
@@ -0,0 +1,3 @@
1
+ from gitronics import _cli_main
2
+
3
+ _cli_main()
@@ -0,0 +1,45 @@
1
+ """Type stubs for the gitronics Rust extension module."""
2
+
3
+ from pathlib import Path
4
+
5
+ def run(args: list[str]) -> None:
6
+ """Run the gitronics CLI with the given argument list.
7
+
8
+ This is equivalent to running ``gitronics`` from the command line.
9
+ ``args[0]`` should be the program name (i.e. ``sys.argv``).
10
+
11
+ Args:
12
+ args: Argument list in ``sys.argv`` format, e.g.
13
+ ``["gitronics", "build", "config.yaml"]``.
14
+
15
+ Raises:
16
+ RuntimeError: If the command fails.
17
+ """
18
+ ...
19
+
20
+ def py_build_model(config_path: Path | str, output_path: Path | str) -> None:
21
+ """Assemble an MCNP model from a gitronics configuration file.
22
+
23
+ Reads the YAML configuration at *config_path*, resolves all referenced
24
+ filler models and data-card files, and writes ``assembled.mcnp`` (plus a
25
+ ``.gitignore``) into *output_path*.
26
+
27
+ Args:
28
+ config_path: Path to the YAML configuration file.
29
+ output_path: Directory where ``assembled.mcnp`` will be written.
30
+ The directory must already exist.
31
+
32
+ Raises:
33
+ RuntimeError: If any step of the build fails (e.g. missing file,
34
+ invalid MCNP syntax, validation error).
35
+
36
+ Example::
37
+
38
+ import gitronics
39
+
40
+ gitronics.build_model(
41
+ "configurations/baseline.yaml",
42
+ "output/",
43
+ )
44
+ """
45
+ ...
@@ -0,0 +1,30 @@
1
+ import tempfile
2
+ from pathlib import Path
3
+
4
+ import gitronics
5
+ import pytest
6
+
7
+ EXAMPLE_CONFIG = (
8
+ Path(__file__).parent.parent.parent
9
+ / "example_project"
10
+ / "configurations"
11
+ / "valid_configuration.yaml"
12
+ )
13
+
14
+
15
+ def test_build_model_success():
16
+ with tempfile.TemporaryDirectory() as output_dir:
17
+ gitronics.build_model(EXAMPLE_CONFIG, output_dir)
18
+ assert (Path(output_dir) / "assembled.mcnp").exists()
19
+
20
+
21
+ def test_build_model_accepts_str_paths():
22
+ with tempfile.TemporaryDirectory() as output_dir:
23
+ gitronics.build_model(str(EXAMPLE_CONFIG), output_dir)
24
+ assert (Path(output_dir) / "assembled.mcnp").exists()
25
+
26
+
27
+ def test_build_model_missing_config_raises():
28
+ with tempfile.TemporaryDirectory() as output_dir:
29
+ with pytest.raises(RuntimeError):
30
+ gitronics.build_model("does_not_exist.yaml", output_dir)
@@ -6,6 +6,7 @@ use git2::Repository;
6
6
  use log::{info, warn};
7
7
  use migjorn::{Card, CellCard, CellParam, DataCard, Model, ParamType};
8
8
  use regex::Regex;
9
+ use std::collections::HashSet;
9
10
  use std::{collections::HashMap, path::Path, sync::LazyLock};
10
11
  use std::{env, fs};
11
12
 
@@ -82,6 +83,9 @@ fn add_fill_cards_to_envelopes(
82
83
  universe_ids: &HashMap<FillerName, UniverseId>,
83
84
  envelope_structure: &mut Model,
84
85
  ) -> Result<(), GitronicsError> {
86
+ let mut missing_envelopes_in_file: HashSet<EnvelopeName> =
87
+ project_manager.envelopes_in_config().cloned().collect();
88
+
85
89
  for cell in envelope_structure.cells.iter_mut() {
86
90
  let original_text = cell.original_text();
87
91
  let Some(caps) = ENVELOPE_RE.captures(original_text) else {
@@ -105,6 +109,9 @@ fn add_fill_cards_to_envelopes(
105
109
  continue;
106
110
  };
107
111
 
112
+ // Remove the envelope from the set of missing envelopes, as we have found it in the file
113
+ missing_envelopes_in_file.remove(&envelope_name);
114
+
108
115
  // Envelope explicitly set to null in config, so we skip it
109
116
  let Some(filler_name) = env_config.as_ref() else {
110
117
  continue;
@@ -129,6 +136,18 @@ fn add_fill_cards_to_envelopes(
129
136
  .map_err(|e| GitronicsError::InvalidFillCard(fill_card_text, e.to_string()))?,
130
137
  );
131
138
  }
139
+
140
+ if !missing_envelopes_in_file.is_empty() {
141
+ warn!(
142
+ "The following envelopes were defined in the configuration file but not found in the envelope structure file: {}. \
143
+ Please check that the `$ @env:envelope_name` pattern is satisfied.",
144
+ missing_envelopes_in_file
145
+ .into_iter()
146
+ .map(|e| e.to_string())
147
+ .collect::<Vec<_>>()
148
+ .join(", ")
149
+ );
150
+ }
132
151
  Ok(())
133
152
  }
134
153
 
@@ -85,6 +85,11 @@ impl ProjectManager {
85
85
  .get(envelope_name)
86
86
  .and_then(|opt| opt.as_deref()))
87
87
  }
88
+
89
+ /// Returns an iterator over the envelope names defined in the configuration.
90
+ pub fn envelopes_in_config(&self) -> impl Iterator<Item = &EnvelopeName> {
91
+ self.model_config.envelopes().keys()
92
+ }
88
93
  }
89
94
 
90
95
  /// Indexes project files using roots resolved from a loaded configuration.
@@ -0,0 +1,31 @@
1
+ use std::path::PathBuf;
2
+
3
+ use pyo3::prelude::*;
4
+
5
+ use crate::build_model::build_model;
6
+ use crate::run_cli;
7
+
8
+ #[pyfunction]
9
+ fn run(args: Vec<String>) -> PyResult<()> {
10
+ use pyo3::exceptions::PyRuntimeError;
11
+ // Clap exits the process on --help / bad args; that's acceptable.
12
+ run_cli(args).map_err(|e| PyRuntimeError::new_err(e.to_string()))
13
+ }
14
+
15
+ /// Build an MCNP model from a gitronics configuration file.
16
+ ///
17
+ /// Args:
18
+ /// config_path: Path to the YAML configuration file.
19
+ /// output_path: Directory where the assembled model will be written.
20
+ #[pyfunction]
21
+ fn py_build_model(config_path: PathBuf, output_path: PathBuf) -> PyResult<()> {
22
+ use pyo3::exceptions::PyRuntimeError;
23
+ build_model(&config_path, &output_path).map_err(|e| PyRuntimeError::new_err(e.to_string()))
24
+ }
25
+
26
+ /// Python extension module.
27
+ #[pymodule]
28
+ fn gitronics(m: &Bound<'_, PyModule>) -> PyResult<()> {
29
+ m.add_function(wrap_pyfunction!(run, m)?)?;
30
+ m.add_function(wrap_pyfunction!(py_build_model, m)?)
31
+ }
@@ -1,4 +1,6 @@
1
1
  use gitronics::build_model;
2
+ use log::Level;
3
+ use logtest::Logger;
2
4
  use std::fs;
3
5
  use std::path::{Path, PathBuf};
4
6
  use tempfile::tempdir;
@@ -246,3 +248,42 @@ fn test_filler_first_cell_without_universe_id() {
246
248
  let msg = result.unwrap_err().to_string();
247
249
  assert!(msg.contains("No universe ID found in first cell of filler model"));
248
250
  }
251
+
252
+ #[test]
253
+ fn test_envelopes_in_config_that_dont_exist() {
254
+ let mut logger = Logger::start();
255
+ let dir = tempdir().unwrap();
256
+ let example_project_path = PathBuf::from("example_project/");
257
+ copy_dir(&example_project_path, dir.path()).unwrap();
258
+
259
+ fs::write(
260
+ dir.path().join("configurations/valid_configuration.yaml"),
261
+ "project_roots: [..]
262
+ overrides: null
263
+
264
+ envelope_structure: envelope_structure
265
+ source: volumetric_source
266
+ materials: [materials]
267
+ transformations: [my_transform]
268
+ tallies: [fine_mesh]
269
+ envelopes:
270
+ my_envelope_name_1: filler_model_1
271
+ wrong_envelope_name: filler_model_2
272
+ ",
273
+ )
274
+ .unwrap();
275
+
276
+ build_model(
277
+ &dir.path().join("configurations/valid_configuration.yaml"),
278
+ dir.path().join("out").as_path(),
279
+ )
280
+ .unwrap();
281
+
282
+ let warn_message = "The following envelopes were defined in the configuration file but not found in the envelope structure file";
283
+
284
+ assert!(
285
+ logger.any(|record| {
286
+ record.level() == Level::Warn && record.args().contains(warn_message)
287
+ })
288
+ );
289
+ }
@@ -1,16 +0,0 @@
1
- use pyo3::prelude::*;
2
-
3
- use crate::run_cli;
4
-
5
- #[pyfunction]
6
- fn run(args: Vec<String>) -> PyResult<()> {
7
- use pyo3::exceptions::PyRuntimeError;
8
- // Clap exits the process on --help / bad args; that's acceptable.
9
- run_cli(args).map_err(|e| PyRuntimeError::new_err(e.to_string()))
10
- }
11
-
12
- /// Python extension module.
13
- #[pymodule]
14
- fn gitronics(m: &Bound<'_, PyModule>) -> PyResult<()> {
15
- m.add_function(wrap_pyfunction!(run, m)?)
16
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes