gitronics 0.3.2__py3-none-any.whl
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.
- gitronics/__init__.py +4 -0
- gitronics/compose_model.py +42 -0
- gitronics/file_discovery.py +29 -0
- gitronics/file_readers.py +133 -0
- gitronics/generate_model.py +130 -0
- gitronics/helpers.py +37 -0
- gitronics/project_checker.py +288 -0
- gitronics/project_manager.py +143 -0
- gitronics-0.3.2.dist-info/METADATA +19 -0
- gitronics-0.3.2.dist-info/RECORD +12 -0
- gitronics-0.3.2.dist-info/WHEEL +4 -0
- gitronics-0.3.2.dist-info/licenses/LICENSE +157 -0
gitronics/__init__.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""
|
|
2
|
+
These functions are used to compose the MCNP model from the blocks of cards that were
|
|
3
|
+
read and parsed previously.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import logging
|
|
7
|
+
from io import StringIO
|
|
8
|
+
from typing import TextIO
|
|
9
|
+
|
|
10
|
+
from gitronics.file_readers import ParsedBlocks
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def compose_model(parsed_data: ParsedBlocks) -> str:
|
|
14
|
+
"""
|
|
15
|
+
Takes the parsed blocks obtained from the file_readers and composes the MCNP model
|
|
16
|
+
as a string.
|
|
17
|
+
"""
|
|
18
|
+
logging.info("Composing model")
|
|
19
|
+
model = StringIO()
|
|
20
|
+
|
|
21
|
+
_write_cards_on_model(parsed_data.cells, model)
|
|
22
|
+
model.write("\n")
|
|
23
|
+
|
|
24
|
+
_write_cards_on_model(parsed_data.surfaces, model)
|
|
25
|
+
model.write("\n")
|
|
26
|
+
|
|
27
|
+
for card_dictionary in [
|
|
28
|
+
parsed_data.materials,
|
|
29
|
+
parsed_data.tallies,
|
|
30
|
+
parsed_data.transforms,
|
|
31
|
+
]:
|
|
32
|
+
_write_cards_on_model(card_dictionary, model)
|
|
33
|
+
|
|
34
|
+
model.write(parsed_data.source)
|
|
35
|
+
|
|
36
|
+
return model.getvalue()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _write_cards_on_model(card_dictionary: dict[int, str], model: TextIO) -> None:
|
|
40
|
+
card_ids = sorted(card_dictionary.keys())
|
|
41
|
+
for card_id in card_ids:
|
|
42
|
+
model.write(card_dictionary[card_id])
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from gitronics.helpers import ALLOWED_SUFFIXES
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def get_valid_file_paths(project_root: Path) -> dict[str, Path]:
|
|
7
|
+
"""Gets all the file paths with allowed suffixes in the project as a dictionary
|
|
8
|
+
`name: path`."""
|
|
9
|
+
all_paths = get_all_file_paths(project_root)
|
|
10
|
+
|
|
11
|
+
valid_suffix_paths = {}
|
|
12
|
+
for path in all_paths:
|
|
13
|
+
if path.suffix in ALLOWED_SUFFIXES:
|
|
14
|
+
file_name = path.stem
|
|
15
|
+
valid_suffix_paths[file_name] = path
|
|
16
|
+
|
|
17
|
+
return valid_suffix_paths
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get_all_file_paths(project_root: Path) -> list[Path]:
|
|
21
|
+
"""
|
|
22
|
+
Gets all the file paths in the project, including non-allowed suffixes.
|
|
23
|
+
"""
|
|
24
|
+
paths_list = []
|
|
25
|
+
for file in project_root.rglob("*"):
|
|
26
|
+
if file.is_file():
|
|
27
|
+
paths_list.append(file.resolve())
|
|
28
|
+
|
|
29
|
+
return paths_list
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""
|
|
2
|
+
These functions read and parse the individual files that will make up the composed MCNP
|
|
3
|
+
model. The result is an instance of ParsedBlocks which holds all the sections of the
|
|
4
|
+
final file.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
import re
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class ParsedBlocks:
|
|
15
|
+
"""Contains all the sections of the MCNP input model."""
|
|
16
|
+
|
|
17
|
+
cells: dict[int, str]
|
|
18
|
+
surfaces: dict[int, str]
|
|
19
|
+
tallies: dict[int, str]
|
|
20
|
+
materials: dict[int, str]
|
|
21
|
+
transforms: dict[int, str]
|
|
22
|
+
source: str
|
|
23
|
+
|
|
24
|
+
@classmethod
|
|
25
|
+
def empty_instance(cls) -> "ParsedBlocks":
|
|
26
|
+
"""Returns an empty instance of ParsedBlocks."""
|
|
27
|
+
return ParsedBlocks(
|
|
28
|
+
cells={}, surfaces={}, tallies={}, materials={}, transforms={}, source=""
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
def add_file(self, file: Path) -> None:
|
|
32
|
+
"""Adds the file if the suffix is recognized."""
|
|
33
|
+
suffix = file.suffix[1:] # remove the dot like in ".mcnp"
|
|
34
|
+
|
|
35
|
+
match suffix:
|
|
36
|
+
case "mcnp":
|
|
37
|
+
self._add_mcnp_file(file)
|
|
38
|
+
|
|
39
|
+
case "tally":
|
|
40
|
+
self._add_tally_file(file)
|
|
41
|
+
|
|
42
|
+
case "mat":
|
|
43
|
+
self._add_material_file(file)
|
|
44
|
+
|
|
45
|
+
case "transform":
|
|
46
|
+
self._add_transform_file(file)
|
|
47
|
+
|
|
48
|
+
case "source":
|
|
49
|
+
self._add_source_file(file)
|
|
50
|
+
|
|
51
|
+
case _:
|
|
52
|
+
raise ValueError(f"Unknown file suffix for: {file}")
|
|
53
|
+
|
|
54
|
+
def _add_mcnp_file(self, file: Path) -> None:
|
|
55
|
+
cells_block, surfaces_block = _read_mcnp(file)
|
|
56
|
+
self.cells[cells_block.first_id] = cells_block.text
|
|
57
|
+
self.surfaces[surfaces_block.first_id] = surfaces_block.text
|
|
58
|
+
|
|
59
|
+
def _add_tally_file(self, file: Path) -> None:
|
|
60
|
+
block = _read_first_block(file)
|
|
61
|
+
self.tallies[block.first_id] = block.text
|
|
62
|
+
|
|
63
|
+
def _add_material_file(self, file: Path) -> None:
|
|
64
|
+
block = _read_first_block(file)
|
|
65
|
+
self.materials[block.first_id] = block.text
|
|
66
|
+
|
|
67
|
+
def _add_transform_file(self, file: Path) -> None:
|
|
68
|
+
block = _read_first_block(file)
|
|
69
|
+
self.transforms[block.first_id] = block.text
|
|
70
|
+
|
|
71
|
+
def _add_source_file(self, file: Path) -> None:
|
|
72
|
+
self.source = _read_first_block(file).text
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def read_files(files: list[Path]) -> ParsedBlocks:
|
|
76
|
+
"""Reads the files and returns the parsed blocks."""
|
|
77
|
+
parsed_blocks = ParsedBlocks.empty_instance()
|
|
78
|
+
|
|
79
|
+
for file in files:
|
|
80
|
+
logging.info("Reading file: %s", file)
|
|
81
|
+
parsed_blocks.add_file(file)
|
|
82
|
+
|
|
83
|
+
return parsed_blocks
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@dataclass
|
|
87
|
+
class _FirstIdAndText:
|
|
88
|
+
first_id: int
|
|
89
|
+
text: str
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
BLANK_LINE = re.compile(r"^\s*\n", flags=re.MULTILINE)
|
|
93
|
+
MCNP_FILE_NEEDED_BLOCKS = 2
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _read_mcnp(file: Path) -> tuple[_FirstIdAndText, _FirstIdAndText]:
|
|
97
|
+
with open(file, encoding="utf-8") as infile:
|
|
98
|
+
blocks = BLANK_LINE.split(infile.read())
|
|
99
|
+
|
|
100
|
+
if len(blocks) < MCNP_FILE_NEEDED_BLOCKS:
|
|
101
|
+
raise ValueError(
|
|
102
|
+
f"File {file} does not contain the two blocks: cells and surfaces."
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
cells, surfaces = blocks[:2]
|
|
106
|
+
|
|
107
|
+
match_first_cell_id = re.search(r"^\d+", cells, flags=re.MULTILINE)
|
|
108
|
+
if not match_first_cell_id:
|
|
109
|
+
raise ValueError(f"Could not parse the first cell ID value in {file}.")
|
|
110
|
+
first_cell_id = int(match_first_cell_id.group())
|
|
111
|
+
|
|
112
|
+
match_first_surface_id = re.search(r"^\*?\d+", surfaces, flags=re.MULTILINE)
|
|
113
|
+
if not match_first_surface_id:
|
|
114
|
+
raise ValueError(f"Could not parse the first surface ID value in {file}.")
|
|
115
|
+
first_surface_id = int(match_first_surface_id.group())
|
|
116
|
+
|
|
117
|
+
return _FirstIdAndText(first_cell_id, cells), _FirstIdAndText(
|
|
118
|
+
first_surface_id, surfaces
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _read_first_block(file: Path) -> _FirstIdAndText:
|
|
123
|
+
with open(file, encoding="utf-8") as infile:
|
|
124
|
+
text = BLANK_LINE.split(infile.read())[0]
|
|
125
|
+
if text[-1] != "\n":
|
|
126
|
+
text += "\n"
|
|
127
|
+
|
|
128
|
+
match_first_id = re.search(r"^\*?[a-zA-Z]*(\d+)", text, flags=re.MULTILINE)
|
|
129
|
+
if not match_first_id:
|
|
130
|
+
raise ValueError(f"Could not parse the first ID value in file {file}.")
|
|
131
|
+
first_id = int(match_first_id.group(1))
|
|
132
|
+
|
|
133
|
+
return _FirstIdAndText(first_id, text)
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This file contains the generate_model function, the only function a user needs to call
|
|
3
|
+
to generate the MCNP model.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import logging
|
|
7
|
+
import re
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
from importlib.metadata import version
|
|
10
|
+
|
|
11
|
+
import yaml
|
|
12
|
+
|
|
13
|
+
from gitronics.compose_model import compose_model
|
|
14
|
+
from gitronics.file_readers import ParsedBlocks, read_files
|
|
15
|
+
from gitronics.helpers import Config, GitronicsError, ProjectParameters
|
|
16
|
+
from gitronics.project_checker import ProjectChecker
|
|
17
|
+
from gitronics.project_manager import ProjectManager
|
|
18
|
+
|
|
19
|
+
PLACEHOLDER_PAT = re.compile(r"\$\s+FILL\s*=\s*(\w+)\s*")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def generate_model(
|
|
23
|
+
configuration_name: str, project_parameters: ProjectParameters
|
|
24
|
+
) -> None:
|
|
25
|
+
# Set up logging
|
|
26
|
+
logging.basicConfig(
|
|
27
|
+
level=logging.INFO,
|
|
28
|
+
format="%(asctime)s - %(levelname)s - %(message)s",
|
|
29
|
+
datefmt="%Y-%m-%d %H:%M:%S",
|
|
30
|
+
filename=project_parameters.write_path / "model_generation.log",
|
|
31
|
+
filemode="w",
|
|
32
|
+
)
|
|
33
|
+
# Check the whole project
|
|
34
|
+
project_manager = ProjectManager(project_parameters)
|
|
35
|
+
ProjectChecker(project_manager).check_project()
|
|
36
|
+
# Read the configuration and assemble the model as a text string
|
|
37
|
+
config = project_manager.read_configuration(configuration_name)
|
|
38
|
+
text = _assemble_model(project_manager, config)
|
|
39
|
+
# Write the model to a file
|
|
40
|
+
with open(
|
|
41
|
+
project_parameters.write_path / f"assembled_{config.name}.mcnp",
|
|
42
|
+
"w",
|
|
43
|
+
encoding="utf-8-sig",
|
|
44
|
+
) as infile:
|
|
45
|
+
infile.write(text)
|
|
46
|
+
_dump_metadata(project_parameters, config)
|
|
47
|
+
logging.info("Model generation completed.")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _assemble_model(project_manager: ProjectManager, config: Config) -> str:
|
|
51
|
+
logging.info("Generating model for configuration: %s", config.name)
|
|
52
|
+
file_paths_to_include = project_manager.get_included_paths(config)
|
|
53
|
+
parsed_blocks = read_files(file_paths_to_include)
|
|
54
|
+
_fill_envelope_cards(parsed_blocks, project_manager, config)
|
|
55
|
+
text = compose_model(parsed_blocks)
|
|
56
|
+
return text
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _fill_envelope_cards(
|
|
60
|
+
parsed_blocks: ParsedBlocks, project_manager: ProjectManager, config: Config
|
|
61
|
+
) -> None:
|
|
62
|
+
logging.info("Preparing FILL cards in the envelope structure.")
|
|
63
|
+
envelope_structure_id = _get_envelope_structure_first_cell_id(
|
|
64
|
+
project_manager, config
|
|
65
|
+
)
|
|
66
|
+
text = parsed_blocks.cells[envelope_structure_id]
|
|
67
|
+
|
|
68
|
+
if not config.envelopes:
|
|
69
|
+
logging.info("No envelopes to fill, skipping FILL cards.")
|
|
70
|
+
return
|
|
71
|
+
|
|
72
|
+
fill_cards = {}
|
|
73
|
+
for envelope_name, filler_name in config.envelopes.items():
|
|
74
|
+
# If the envelope is left empty in the configuration do not fill
|
|
75
|
+
if not filler_name:
|
|
76
|
+
continue
|
|
77
|
+
|
|
78
|
+
# Create the fill card
|
|
79
|
+
universe_id = project_manager.get_universe_id(filler_name)
|
|
80
|
+
transform = project_manager.get_transformation(filler_name, envelope_name)
|
|
81
|
+
if transform:
|
|
82
|
+
transform = transform.strip()
|
|
83
|
+
if transform.startswith("*"):
|
|
84
|
+
fill_card = f" *FILL = {universe_id} {transform[1:]} "
|
|
85
|
+
else:
|
|
86
|
+
fill_card = f" FILL = {universe_id} {transform} "
|
|
87
|
+
else:
|
|
88
|
+
fill_card = f" FILL = {universe_id} "
|
|
89
|
+
fill_card += f"\n $ {envelope_name} \n"
|
|
90
|
+
fill_cards[envelope_name] = fill_card
|
|
91
|
+
|
|
92
|
+
# Modify the text
|
|
93
|
+
lines = text.splitlines(keepends=True)
|
|
94
|
+
for i, line in enumerate(lines):
|
|
95
|
+
match_placeholder = PLACEHOLDER_PAT.search(line)
|
|
96
|
+
if match_placeholder:
|
|
97
|
+
envelope_name = match_placeholder.group(1)
|
|
98
|
+
if envelope_name in fill_cards:
|
|
99
|
+
lines[i] = re.sub(PLACEHOLDER_PAT, fill_cards[envelope_name], lines[i])
|
|
100
|
+
text = "".join(lines)
|
|
101
|
+
|
|
102
|
+
# Update the ParsedBlocks with the new text for the envelope structure
|
|
103
|
+
parsed_blocks.cells[envelope_structure_id] = text
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _get_envelope_structure_first_cell_id(
|
|
107
|
+
project_manager: ProjectManager, config: Config
|
|
108
|
+
) -> int:
|
|
109
|
+
assert config.envelope_structure in project_manager.file_paths
|
|
110
|
+
path = project_manager.file_paths[config.envelope_structure]
|
|
111
|
+
with open(path, encoding="utf-8") as infile:
|
|
112
|
+
for line in infile:
|
|
113
|
+
match_first_cell_id = re.match(r"^(\d+)", line)
|
|
114
|
+
if match_first_cell_id:
|
|
115
|
+
return int(match_first_cell_id.group(1))
|
|
116
|
+
raise GitronicsError(f"Could not find the first cell ID in {path}.")
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _dump_metadata(project_parameters: ProjectParameters, config: Config) -> None:
|
|
120
|
+
with open(
|
|
121
|
+
project_parameters.write_path / f"assembled_{config.name}.metadata",
|
|
122
|
+
"w",
|
|
123
|
+
encoding="utf-8",
|
|
124
|
+
) as infile:
|
|
125
|
+
metadata = {
|
|
126
|
+
"configuration_name": config.name,
|
|
127
|
+
"gitronics_version": version("gitronics"),
|
|
128
|
+
"build_date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
|
129
|
+
}
|
|
130
|
+
yaml.dump(metadata, infile, default_flow_style=False, sort_keys=False)
|
gitronics/helpers.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
ALLOWED_SUFFIXES = {".mcnp", ".transform", ".mat", ".source", ".tally", ".yaml", ".yml"}
|
|
5
|
+
|
|
6
|
+
TYPE_BY_SUFFIX = {
|
|
7
|
+
".mcnp": "Geometry",
|
|
8
|
+
".transform": "Transform",
|
|
9
|
+
".mat": "Material",
|
|
10
|
+
".source": "Source",
|
|
11
|
+
".tally": "Tally",
|
|
12
|
+
".yaml": "Configuration",
|
|
13
|
+
".yml": "Configuration",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class ProjectParameters:
|
|
19
|
+
root_folder_path: Path
|
|
20
|
+
write_path: Path
|
|
21
|
+
extra_metadata_fields: list[str] | None = None
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class Config:
|
|
26
|
+
name: str
|
|
27
|
+
overrides: str | None
|
|
28
|
+
envelope_structure: str
|
|
29
|
+
envelopes: dict[str, str]
|
|
30
|
+
source: str | None
|
|
31
|
+
tallies: list[str] | None
|
|
32
|
+
materials: list[str] | None
|
|
33
|
+
transforms: list[str] | None
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class GitronicsError(Exception):
|
|
37
|
+
"""Base class for all Gitronics exceptions."""
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import re
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import polars as pl
|
|
7
|
+
from xlsxwriter import Workbook # type: ignore
|
|
8
|
+
|
|
9
|
+
from gitronics.file_discovery import get_all_file_paths
|
|
10
|
+
from gitronics.helpers import (
|
|
11
|
+
ALLOWED_SUFFIXES,
|
|
12
|
+
TYPE_BY_SUFFIX,
|
|
13
|
+
Config,
|
|
14
|
+
GitronicsError,
|
|
15
|
+
)
|
|
16
|
+
from gitronics.project_manager import ProjectManager
|
|
17
|
+
|
|
18
|
+
PLACEHOLDER_PAT = re.compile(r"\$\s+FILL\s*=\s*(\w+)\s*")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class ConfigSummaryTables:
|
|
23
|
+
configuration_and_structure: pl.DataFrame
|
|
24
|
+
envelopes: pl.DataFrame
|
|
25
|
+
data_files: pl.DataFrame
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class SummaryData:
|
|
30
|
+
all_files_info: pl.DataFrame | None = None
|
|
31
|
+
config_summaries: dict[str, ConfigSummaryTables] = field(default_factory=dict)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ProjectChecker:
|
|
35
|
+
def __init__(self, project_manager: ProjectManager):
|
|
36
|
+
self.project_manager = project_manager
|
|
37
|
+
self.summary_data = SummaryData()
|
|
38
|
+
|
|
39
|
+
def check_project(self) -> None:
|
|
40
|
+
"""Checks the whole project for potential issues and creates a summary with
|
|
41
|
+
all the files. It also checks the validity of all the configurations."""
|
|
42
|
+
logging.info("Checking the validity of the whole project")
|
|
43
|
+
file_paths = self._get_file_paths()
|
|
44
|
+
self._check_no_duplicate_names(file_paths)
|
|
45
|
+
self._check_metadata_files_exist_for_mcnp_models(file_paths)
|
|
46
|
+
self._update_summary_data_with_all_files_info(
|
|
47
|
+
file_paths, self.project_manager.parameters.extra_metadata_fields
|
|
48
|
+
)
|
|
49
|
+
self._check_all_configurations(file_paths)
|
|
50
|
+
self._write_excel_summary(self.project_manager.parameters.write_path)
|
|
51
|
+
|
|
52
|
+
def _check_all_configurations(self, paths: list[Path]) -> None:
|
|
53
|
+
"""Check all the configurations found in the project (files with .yaml or .yml
|
|
54
|
+
suffix)."""
|
|
55
|
+
configuration_files = [
|
|
56
|
+
path for path in paths if path.suffix in {".yaml", ".yml"}
|
|
57
|
+
]
|
|
58
|
+
for config_path in configuration_files:
|
|
59
|
+
configuration_name = config_path.stem
|
|
60
|
+
config = self.project_manager.read_configuration(configuration_name)
|
|
61
|
+
self.check_configuration(config)
|
|
62
|
+
|
|
63
|
+
def check_configuration(self, config: Config) -> None:
|
|
64
|
+
logging.info("Checking configuration: %s", config.name)
|
|
65
|
+
self._check_envelope_structure(config)
|
|
66
|
+
self._check_envelopes(config)
|
|
67
|
+
self._check_fillers(config)
|
|
68
|
+
self._check_source(config)
|
|
69
|
+
self._check_tallies(config)
|
|
70
|
+
self._check_materials(config)
|
|
71
|
+
self._check_transforms(config)
|
|
72
|
+
self._trigger_warnings(config)
|
|
73
|
+
self._update_summary_data_with_config(config)
|
|
74
|
+
|
|
75
|
+
def _get_file_paths(self) -> list[Path]:
|
|
76
|
+
all_file_paths = get_all_file_paths(self.project_manager.project_root)
|
|
77
|
+
return [path for path in all_file_paths if path.suffix in ALLOWED_SUFFIXES]
|
|
78
|
+
|
|
79
|
+
def _check_no_duplicate_names(self, paths: list[Path]) -> None:
|
|
80
|
+
names = set()
|
|
81
|
+
for path in paths:
|
|
82
|
+
name = path.stem
|
|
83
|
+
if name in names:
|
|
84
|
+
raise GitronicsError(f"Duplicate file name found: {name}")
|
|
85
|
+
names.add(name)
|
|
86
|
+
|
|
87
|
+
def _check_metadata_files_exist_for_mcnp_models(self, paths: list[Path]) -> None:
|
|
88
|
+
for path in paths:
|
|
89
|
+
if path.suffix == ".mcnp" and not path.with_suffix(".metadata").exists():
|
|
90
|
+
raise GitronicsError(f"Metadata file not found for: {path}")
|
|
91
|
+
|
|
92
|
+
def _update_summary_data_with_all_files_info(
|
|
93
|
+
self, paths: list[Path], extra_metadata_fields: list[str] | None = None
|
|
94
|
+
) -> None:
|
|
95
|
+
data = []
|
|
96
|
+
for path in paths:
|
|
97
|
+
relative_path = str(
|
|
98
|
+
path.relative_to(self.project_manager.project_root.absolute()).parent
|
|
99
|
+
)
|
|
100
|
+
entry = {
|
|
101
|
+
"Type": TYPE_BY_SUFFIX[path.suffix],
|
|
102
|
+
"Name": path.stem,
|
|
103
|
+
"Path": relative_path,
|
|
104
|
+
}
|
|
105
|
+
data.append(entry)
|
|
106
|
+
if extra_metadata_fields:
|
|
107
|
+
try:
|
|
108
|
+
metadata = self.project_manager.get_metadata(path.stem)
|
|
109
|
+
except GitronicsError:
|
|
110
|
+
metadata = {}
|
|
111
|
+
for metadata_field in extra_metadata_fields:
|
|
112
|
+
entry[metadata_field] = metadata.get(metadata_field, "")
|
|
113
|
+
|
|
114
|
+
dataframe = pl.DataFrame(data).sort(["Type", "Path", "Name"])
|
|
115
|
+
self.summary_data.all_files_info = dataframe
|
|
116
|
+
|
|
117
|
+
def _check_envelope_structure(self, config: Config) -> None:
|
|
118
|
+
"""Checks that the envelope structure is defined in the configuration and that
|
|
119
|
+
it exists."""
|
|
120
|
+
if not config.envelope_structure:
|
|
121
|
+
raise GitronicsError(
|
|
122
|
+
"Envelope structure is not defined in the configuration."
|
|
123
|
+
)
|
|
124
|
+
if config.envelope_structure not in self.project_manager.file_paths:
|
|
125
|
+
raise GitronicsError(
|
|
126
|
+
f"Envelope structure file {config.envelope_structure} not found "
|
|
127
|
+
"in the project."
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
def _check_envelopes(self, config: Config) -> None:
|
|
131
|
+
"""Checks that, if there is an envelopes field, all the envelopes appear in the
|
|
132
|
+
envelope structure. Prints a warning if there are envelopes that do not appear
|
|
133
|
+
in the configuration."""
|
|
134
|
+
if not config.envelopes:
|
|
135
|
+
return
|
|
136
|
+
|
|
137
|
+
envelope_structure_path = self.project_manager.file_paths[
|
|
138
|
+
config.envelope_structure
|
|
139
|
+
]
|
|
140
|
+
with open(envelope_structure_path, encoding="utf-8") as infile:
|
|
141
|
+
text = infile.read()
|
|
142
|
+
envelope_names_in_structure = set()
|
|
143
|
+
for line in text.splitlines():
|
|
144
|
+
placeholder_match = PLACEHOLDER_PAT.search(line)
|
|
145
|
+
if placeholder_match:
|
|
146
|
+
envelope_name = placeholder_match.group(1)
|
|
147
|
+
envelope_names_in_structure.add(envelope_name)
|
|
148
|
+
|
|
149
|
+
for envelope_name in config.envelopes.keys():
|
|
150
|
+
if envelope_name not in envelope_names_in_structure:
|
|
151
|
+
raise GitronicsError(
|
|
152
|
+
f"Envelope {envelope_name} not found in the envelope structure."
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
empty_envelopes = envelope_names_in_structure.difference(
|
|
156
|
+
config.envelopes.keys()
|
|
157
|
+
)
|
|
158
|
+
if empty_envelopes:
|
|
159
|
+
logging.warning(
|
|
160
|
+
"There are empty envelopes in the structure not accounted for in the "
|
|
161
|
+
"configuration: %s",
|
|
162
|
+
empty_envelopes,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
def _check_fillers(self, config: Config) -> None:
|
|
166
|
+
"""Check that all the fillers exist and that their metadata includes the
|
|
167
|
+
necessary transformation."""
|
|
168
|
+
for envelope_name, filler_name in config.envelopes.items():
|
|
169
|
+
if not filler_name:
|
|
170
|
+
continue
|
|
171
|
+
if filler_name not in self.project_manager.file_paths:
|
|
172
|
+
raise GitronicsError(
|
|
173
|
+
f"Filler file {filler_name} not found in the project."
|
|
174
|
+
)
|
|
175
|
+
metadata = self.project_manager.get_metadata(filler_name)
|
|
176
|
+
try:
|
|
177
|
+
metadata["transformations"][envelope_name]
|
|
178
|
+
except (KeyError, TypeError):
|
|
179
|
+
raise GitronicsError(
|
|
180
|
+
f"Transformation for envelope {envelope_name} not found in filler"
|
|
181
|
+
f" model {filler_name} metadata."
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
def _check_source(self, config: Config) -> None:
|
|
185
|
+
"""Check that the source file exists (if defined)."""
|
|
186
|
+
if config.source:
|
|
187
|
+
self._check_file_exists(config.source, "Source")
|
|
188
|
+
|
|
189
|
+
def _check_tallies(self, config: Config) -> None:
|
|
190
|
+
"""Check that the tally files exist (if defined)."""
|
|
191
|
+
if config.tallies:
|
|
192
|
+
for tally in config.tallies:
|
|
193
|
+
self._check_file_exists(tally, "Tally")
|
|
194
|
+
|
|
195
|
+
def _check_materials(self, config: Config) -> None:
|
|
196
|
+
"""Check that the material files exist (if defined)."""
|
|
197
|
+
if config.materials:
|
|
198
|
+
for material in config.materials:
|
|
199
|
+
self._check_file_exists(material, "Material")
|
|
200
|
+
|
|
201
|
+
def _check_transforms(self, config: Config) -> None:
|
|
202
|
+
"""Check that the transform files exist (if defined)."""
|
|
203
|
+
if config.transforms:
|
|
204
|
+
for transform in config.transforms:
|
|
205
|
+
self._check_file_exists(transform, "Transform")
|
|
206
|
+
|
|
207
|
+
def _check_file_exists(self, file_name: str, file_type: str) -> None:
|
|
208
|
+
"""Generic helper to check if a file exists in the project."""
|
|
209
|
+
if file_name not in self.project_manager.file_paths:
|
|
210
|
+
raise GitronicsError(
|
|
211
|
+
f"{file_type} file {file_name} not found in the project."
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
def _trigger_warnings(self, config: Config) -> None:
|
|
215
|
+
if not config.source:
|
|
216
|
+
logging.warning("No source included in the configuration!")
|
|
217
|
+
if not config.materials or len(config.materials) == 0:
|
|
218
|
+
logging.warning("No materials included in the configuration!")
|
|
219
|
+
|
|
220
|
+
def _update_summary_data_with_config(self, config: Config) -> None:
|
|
221
|
+
"""Adds to the summary_data attribute the information from the given
|
|
222
|
+
configuration. This data will be used to create the Excel summary."""
|
|
223
|
+
table_configuration_and_structure = [
|
|
224
|
+
{"Type": "Configuration", "Name": config.name},
|
|
225
|
+
{"Type": "Envelope Structure", "Name": config.envelope_structure},
|
|
226
|
+
]
|
|
227
|
+
|
|
228
|
+
table_envelopes = []
|
|
229
|
+
if config.envelopes:
|
|
230
|
+
for envelope_name, filler_name in config.envelopes.items():
|
|
231
|
+
table_envelopes.append(
|
|
232
|
+
{"Envelope": envelope_name, "Filler": filler_name}
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
table_data_files = []
|
|
236
|
+
if config.source:
|
|
237
|
+
table_data_files.append({"Type": "Source", "Name": config.source})
|
|
238
|
+
if config.tallies:
|
|
239
|
+
for tally in config.tallies:
|
|
240
|
+
table_data_files.append({"Type": "Tally", "Name": tally})
|
|
241
|
+
if config.materials:
|
|
242
|
+
for material in config.materials:
|
|
243
|
+
table_data_files.append({"Type": "Material", "Name": material})
|
|
244
|
+
if config.transforms:
|
|
245
|
+
for transform in config.transforms:
|
|
246
|
+
table_data_files.append({"Type": "Transform", "Name": transform})
|
|
247
|
+
self.summary_data.config_summaries[config.name] = ConfigSummaryTables(
|
|
248
|
+
pl.DataFrame(table_configuration_and_structure),
|
|
249
|
+
pl.DataFrame(table_envelopes),
|
|
250
|
+
pl.DataFrame(table_data_files),
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
def _write_excel_summary(self, write_path: Path) -> None:
|
|
254
|
+
with Workbook(write_path / "summary.xlsx") as workbook:
|
|
255
|
+
if self.summary_data.all_files_info is not None:
|
|
256
|
+
self.summary_data.all_files_info.write_excel(
|
|
257
|
+
workbook,
|
|
258
|
+
worksheet="All files",
|
|
259
|
+
position=(0, 0),
|
|
260
|
+
autofit=True,
|
|
261
|
+
header_format={"bold": True},
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
for conf_name, tables in self.summary_data.config_summaries.items():
|
|
265
|
+
tables.configuration_and_structure.write_excel(
|
|
266
|
+
workbook,
|
|
267
|
+
worksheet=conf_name,
|
|
268
|
+
position=(0, 0),
|
|
269
|
+
autofit=True,
|
|
270
|
+
header_format={"bold": True},
|
|
271
|
+
)
|
|
272
|
+
tables.envelopes.write_excel(
|
|
273
|
+
workbook,
|
|
274
|
+
worksheet=conf_name,
|
|
275
|
+
position=(4, 0),
|
|
276
|
+
autofit=True,
|
|
277
|
+
header_format={"bold": True},
|
|
278
|
+
)
|
|
279
|
+
tables.data_files.write_excel(
|
|
280
|
+
workbook,
|
|
281
|
+
worksheet=conf_name,
|
|
282
|
+
position=(
|
|
283
|
+
4,
|
|
284
|
+
tables.envelopes.width + 1,
|
|
285
|
+
),
|
|
286
|
+
autofit=True,
|
|
287
|
+
header_format={"bold": True},
|
|
288
|
+
)
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from functools import lru_cache
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import yaml
|
|
7
|
+
|
|
8
|
+
from gitronics.file_discovery import get_valid_file_paths
|
|
9
|
+
from gitronics.helpers import Config, GitronicsError, ProjectParameters
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ProjectManager:
|
|
13
|
+
"""Handles the file paths, metadata and configurations of the project."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, project_parameters: ProjectParameters) -> None:
|
|
16
|
+
self.parameters = project_parameters
|
|
17
|
+
self.project_root = project_parameters.root_folder_path
|
|
18
|
+
if not self.project_root.exists() or not self.project_root.is_dir():
|
|
19
|
+
raise GitronicsError(f"The directory {self.project_root} does not exist.")
|
|
20
|
+
|
|
21
|
+
self.file_paths = get_valid_file_paths(self.project_root)
|
|
22
|
+
|
|
23
|
+
def get_included_paths(self, config: Config) -> list[Path]:
|
|
24
|
+
paths: list[Path] = []
|
|
25
|
+
self._include_envelope_structure(paths, config)
|
|
26
|
+
self._include_fillers(paths, config)
|
|
27
|
+
self._include_source(paths, config)
|
|
28
|
+
self._include_tallies(paths, config)
|
|
29
|
+
self._include_materials(paths, config)
|
|
30
|
+
self._include_transforms(paths, config)
|
|
31
|
+
return paths
|
|
32
|
+
|
|
33
|
+
@lru_cache(maxsize=1000)
|
|
34
|
+
def get_metadata(self, name: str) -> dict[str, Any]:
|
|
35
|
+
if name not in self.file_paths:
|
|
36
|
+
raise GitronicsError(f"File {name} not found in the project.")
|
|
37
|
+
|
|
38
|
+
file_path = self.file_paths[name].with_suffix(".metadata")
|
|
39
|
+
if not file_path.exists():
|
|
40
|
+
raise GitronicsError(f"Metadata file not found for {name}.")
|
|
41
|
+
|
|
42
|
+
with open(file_path, encoding="utf-8") as infile:
|
|
43
|
+
metadata = yaml.safe_load(infile) or {}
|
|
44
|
+
return metadata
|
|
45
|
+
|
|
46
|
+
def get_transformation(self, filler_name: str, envelope_name: str) -> str | None:
|
|
47
|
+
metadata = self.get_metadata(filler_name)
|
|
48
|
+
transformation = metadata["transformations"][envelope_name]
|
|
49
|
+
assert isinstance(transformation, str) or transformation is None
|
|
50
|
+
return transformation
|
|
51
|
+
|
|
52
|
+
@lru_cache(maxsize=1000)
|
|
53
|
+
def get_universe_id(self, filler_name: str) -> int:
|
|
54
|
+
"""Returns the universe ID of the filler model."""
|
|
55
|
+
filler_path = self.file_paths[filler_name]
|
|
56
|
+
with open(filler_path, encoding="utf-8") as infile:
|
|
57
|
+
for line in infile:
|
|
58
|
+
universe_match = re.match(r"^[^cC\$]*\s*[uU]\s*=\s*(\d+)", line)
|
|
59
|
+
if universe_match:
|
|
60
|
+
return int(universe_match.group(1))
|
|
61
|
+
raise GitronicsError(f"Universe ID not found in filler model {filler_path}")
|
|
62
|
+
|
|
63
|
+
def read_configuration(self, configuration_name: str) -> Config:
|
|
64
|
+
if configuration_name not in self.file_paths:
|
|
65
|
+
raise GitronicsError(f"Configuration file {configuration_name} not found.")
|
|
66
|
+
conf_path = self.file_paths[configuration_name]
|
|
67
|
+
|
|
68
|
+
with open(conf_path, encoding="utf-8") as infile:
|
|
69
|
+
conf_dict = yaml.safe_load(infile)
|
|
70
|
+
|
|
71
|
+
configuration = Config(
|
|
72
|
+
name=configuration_name,
|
|
73
|
+
overrides=conf_dict.get("overrides"),
|
|
74
|
+
envelope_structure=conf_dict.get("envelope_structure"),
|
|
75
|
+
envelopes=conf_dict.get("envelopes", {}),
|
|
76
|
+
source=conf_dict.get("source"),
|
|
77
|
+
tallies=conf_dict.get("tallies"),
|
|
78
|
+
materials=conf_dict.get("materials"),
|
|
79
|
+
transforms=conf_dict.get("transformations"),
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
configuration = self._override_configuration(configuration)
|
|
83
|
+
|
|
84
|
+
return configuration
|
|
85
|
+
|
|
86
|
+
def _override_configuration(self, new_conf: Config) -> Config:
|
|
87
|
+
if not new_conf.overrides:
|
|
88
|
+
return new_conf
|
|
89
|
+
|
|
90
|
+
base = self.read_configuration(new_conf.overrides)
|
|
91
|
+
|
|
92
|
+
base.name = new_conf.name
|
|
93
|
+
if new_conf.envelope_structure:
|
|
94
|
+
base.envelope_structure = new_conf.envelope_structure
|
|
95
|
+
if new_conf.envelopes:
|
|
96
|
+
base.envelopes.update(new_conf.envelopes)
|
|
97
|
+
if new_conf.source:
|
|
98
|
+
base.source = new_conf.source
|
|
99
|
+
if isinstance(new_conf.tallies, list):
|
|
100
|
+
base.tallies = new_conf.tallies
|
|
101
|
+
if isinstance(new_conf.materials, list):
|
|
102
|
+
base.materials = new_conf.materials
|
|
103
|
+
if isinstance(new_conf.transforms, list):
|
|
104
|
+
base.transforms = new_conf.transforms
|
|
105
|
+
|
|
106
|
+
return base
|
|
107
|
+
|
|
108
|
+
def _include_envelope_structure(self, paths: list[Path], config: Config) -> None:
|
|
109
|
+
if config.envelope_structure in self.file_paths:
|
|
110
|
+
paths.append(self.file_paths[config.envelope_structure])
|
|
111
|
+
|
|
112
|
+
def _include_fillers(self, paths: list[Path], config: Config) -> None:
|
|
113
|
+
if not config.envelopes:
|
|
114
|
+
return
|
|
115
|
+
for filler in config.envelopes.values():
|
|
116
|
+
if not filler:
|
|
117
|
+
continue
|
|
118
|
+
path = self.file_paths[filler]
|
|
119
|
+
if path not in paths:
|
|
120
|
+
paths.append(path)
|
|
121
|
+
|
|
122
|
+
def _include_source(self, paths: list[Path], config: Config) -> None:
|
|
123
|
+
if not config.source:
|
|
124
|
+
return
|
|
125
|
+
paths.append(self.file_paths[config.source])
|
|
126
|
+
|
|
127
|
+
def _include_tallies(self, paths: list[Path], config: Config) -> None:
|
|
128
|
+
if not config.tallies:
|
|
129
|
+
return
|
|
130
|
+
for tally in config.tallies:
|
|
131
|
+
paths.append(self.file_paths[tally])
|
|
132
|
+
|
|
133
|
+
def _include_materials(self, paths: list[Path], config: Config) -> None:
|
|
134
|
+
if not config.materials:
|
|
135
|
+
return
|
|
136
|
+
for material in config.materials:
|
|
137
|
+
paths.append(self.file_paths[material])
|
|
138
|
+
|
|
139
|
+
def _include_transforms(self, paths: list[Path], config: Config) -> None:
|
|
140
|
+
if not config.transforms:
|
|
141
|
+
return
|
|
142
|
+
for transform in config.transforms:
|
|
143
|
+
paths.append(self.file_paths[transform])
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gitronics
|
|
3
|
+
Version: 0.3.2
|
|
4
|
+
Summary: Automatically build an MCNP from a set of files.
|
|
5
|
+
Author-email: Alvaro Cubi <cubiric@hotmail.com>
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.13
|
|
8
|
+
Requires-Dist: pip>=25.2
|
|
9
|
+
Requires-Dist: polars>=1.33.1
|
|
10
|
+
Requires-Dist: pyyaml>=6.0.2
|
|
11
|
+
Requires-Dist: xlsxwriter>=3.2.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
# Gitronics
|
|
17
|
+
A tool to manage and automatically build an MCNP model from a set of files.
|
|
18
|
+
|
|
19
|
+
Please check the online documentation for installation and how to use: https://gitronics.readthedocs.io/en/latest/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
gitronics/__init__.py,sha256=RJbJRMlfRce0st03MJErYubd_bOHHpSwQk8SSZfCBUg,151
|
|
2
|
+
gitronics/compose_model.py,sha256=cKAnmFOhbH0Jww_kSTCPQLQgLV0iTAe1ICL7GZ5KhOU,1079
|
|
3
|
+
gitronics/file_discovery.py,sha256=eXygfKz84KPPAvuhSMF96gLFDIm4LJrXiIgvwzifjy0,817
|
|
4
|
+
gitronics/file_readers.py,sha256=Iw0ymQQLWlYT-pm1XSy6zpaIoYS5KOaS7czLGHIKk0A,4103
|
|
5
|
+
gitronics/generate_model.py,sha256=LlNY-rYiETuW4pdRRbIJ7PIQKyvH3eJwzoLeB3jrSSM,4847
|
|
6
|
+
gitronics/helpers.py,sha256=DDdGInYL7s8UkJE63pk-6ubLsgbEAHxaNE-Z4G_nAks,824
|
|
7
|
+
gitronics/project_checker.py,sha256=V5KaBGrfX5lMzdA_X1QpvJTCHvOGDvHGFZPn0wdjxXs,11805
|
|
8
|
+
gitronics/project_manager.py,sha256=-urvL_4OpNgABda_NJy1ExXOofUNjx-DTkjhwVtkk8o,5630
|
|
9
|
+
gitronics-0.3.2.dist-info/METADATA,sha256=U5p4ciQW84FMWX0MAQr05KfJkwZ7rc6P9mFFvQbMptI,617
|
|
10
|
+
gitronics-0.3.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
11
|
+
gitronics-0.3.2.dist-info/licenses/LICENSE,sha256=QhdjJIRvSVT27zTXcyBHxi2IOsHHJrIKouDEnzG_KL0,13969
|
|
12
|
+
gitronics-0.3.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
EUROPEAN UNION PUBLIC LICENCE v. 1.2
|
|
2
|
+
EUPL © the European Union 2007, 2016
|
|
3
|
+
|
|
4
|
+
This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined below) which is provided under the terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such use is covered by a right of the copyright holder of the Work).
|
|
5
|
+
|
|
6
|
+
The Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following notice immediately following the copyright notice for the Work:
|
|
7
|
+
|
|
8
|
+
Licensed under the EUPL
|
|
9
|
+
|
|
10
|
+
or has expressed by any other means his willingness to license under the EUPL.
|
|
11
|
+
|
|
12
|
+
1. Definitions
|
|
13
|
+
In this Licence, the following terms have the following meaning:
|
|
14
|
+
|
|
15
|
+
— ‘The Licence’: this Licence.
|
|
16
|
+
|
|
17
|
+
— ‘The Original Work’: the work or software distributed or communicated by the Licensor under this Licence, available as Source Code and also as Executable Code as the case may be.
|
|
18
|
+
|
|
19
|
+
— ‘Derivative Works’: the works or software that could be created by the Licensee, based upon the Original Work or modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in the country mentioned in Article 15.
|
|
20
|
+
|
|
21
|
+
— ‘The Work’: the Original Work or its Derivative Works.
|
|
22
|
+
|
|
23
|
+
— ‘The Source Code’: the human-readable form of the Work which is the most convenient for people to study and modify.
|
|
24
|
+
|
|
25
|
+
— ‘The Executable Code’: any code which has generally been compiled and which is meant to be interpreted by a computer as a program.
|
|
26
|
+
|
|
27
|
+
— ‘The Licensor’: the natural or legal person that distributes or communicates the Work under the Licence.
|
|
28
|
+
|
|
29
|
+
— ‘Contributor(s)’: any natural or legal person who modifies the Work under the Licence, or otherwise contributes to the creation of a Derivative Work.
|
|
30
|
+
|
|
31
|
+
— ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of the Work under the terms of the Licence.
|
|
32
|
+
|
|
33
|
+
— ‘Distribution’ or ‘Communication’: any act of selling, giving, lending, renting, distributing, communicating, transmitting, or otherwise making available, online or offline, copies of the Work or providing access to its essential functionalities at the disposal of any other natural or legal person.
|
|
34
|
+
|
|
35
|
+
2. Scope of the rights granted by the Licence
|
|
36
|
+
The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, sublicensable licence to do the following, for the duration of copyright vested in the Original Work:
|
|
37
|
+
|
|
38
|
+
— use the Work in any circumstance and for all usage,
|
|
39
|
+
|
|
40
|
+
— reproduce the Work,
|
|
41
|
+
|
|
42
|
+
— modify the Work, and make Derivative Works based upon the Work,
|
|
43
|
+
|
|
44
|
+
— communicate to the public, including the right to make available or display the Work or copies thereof to the public and perform publicly, as the case may be, the Work,
|
|
45
|
+
|
|
46
|
+
— distribute the Work or copies thereof,
|
|
47
|
+
|
|
48
|
+
— lend and rent the Work or copies thereof,
|
|
49
|
+
|
|
50
|
+
— sublicense rights in the Work or copies thereof.
|
|
51
|
+
|
|
52
|
+
Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the applicable law permits so.
|
|
53
|
+
|
|
54
|
+
In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed by law in order to make effective the licence of the economic rights here above listed.
|
|
55
|
+
|
|
56
|
+
The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to any patents held by the Licensor, to the extent necessary to make use of the rights granted on the Work under this Licence.
|
|
57
|
+
|
|
58
|
+
3. Communication of the Source Code
|
|
59
|
+
The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to distribute or communicate the Work.
|
|
60
|
+
|
|
61
|
+
4. Limitations on copyright
|
|
62
|
+
Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the exclusive rights of the rights owners in the Work, of the exhaustion of those rights or of other applicable limitations thereto.
|
|
63
|
+
|
|
64
|
+
5. Obligations of the Licensee
|
|
65
|
+
The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those obligations are the following:
|
|
66
|
+
|
|
67
|
+
Attribution right: The Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the Licence with every copy of the Work he/she distributes or communicates. The Licensee must cause any Derivative Work to carry prominent notices stating that the Work has been modified and the date of modification.
|
|
68
|
+
Copyleft clause: If the Licensee distributes or communicates copies of the Original Works or Derivative Works, this Distribution or Communication will be done under the terms of this Licence or of a later version of this Licence unless the Original Work is expressly distributed only under this version of the Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the Work or Derivative Work that alter or restrict the terms of the Licence.
|
|
69
|
+
Compatibility clause: If the Licensee Distributes or Communicates Derivative Works or copies thereof based upon both the Work and another work licensed under a Compatible Licence, this Distribution or Communication can be done under the terms of this Compatible Licence. For the sake of this clause, ‘Compatible Licence’ refers to the licences listed in the appendix attached to this Licence. Should the Licensee's obligations under the Compatible Licence conflict with his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail.
|
|
70
|
+
Provision of Source Code: When distributing or communicating copies of the Work, the Licensee will provide a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available for as long as the Licensee continues to distribute or communicate the Work.
|
|
71
|
+
Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the copyright notice.
|
|
72
|
+
6. Chain of Authorship
|
|
73
|
+
The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or licensed to him/her and that he/she has the power and authority to grant the Licence.
|
|
74
|
+
|
|
75
|
+
Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or licensed to him/her and that he/she has the power and authority to grant the Licence.
|
|
76
|
+
|
|
77
|
+
Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contri butions to the Work, under the terms of this Licence.
|
|
78
|
+
|
|
79
|
+
7. Disclaimer of Warranty
|
|
80
|
+
The Work is a work in progress, which is continuously improved by numerous Contributors. It is not a finished work and may therefore contain defects or ‘bugs’ inherent to this type of development.
|
|
81
|
+
|
|
82
|
+
For the above reason, the Work is provided under the Licence on an ‘as is’ basis and without warranties of any kind concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this Licence.
|
|
83
|
+
|
|
84
|
+
This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work.
|
|
85
|
+
|
|
86
|
+
8. Disclaimer of Liability
|
|
87
|
+
Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However, the Licensor will be liable under statutory product liability laws as far such laws apply to the Work.
|
|
88
|
+
|
|
89
|
+
9. Additional agreements
|
|
90
|
+
While distributing the Work, You may choose to conclude an additional agreement, defining obligations or services consistent with this Licence. However, if accepting obligations, You may act only on your own behalf and on your sole responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by the fact You have accepted any warranty or additional liability.
|
|
91
|
+
|
|
92
|
+
10. Acceptance of the Licence
|
|
93
|
+
The provisions of this Licence can be accepted by clicking on an icon ‘I agree’ placed under the bottom of a window displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms and conditions.
|
|
94
|
+
|
|
95
|
+
Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution or Communication by You of the Work or copies thereof.
|
|
96
|
+
|
|
97
|
+
11. Information to the public
|
|
98
|
+
In case of any Distribution or Communication of the Work by means of electronic communication by You (for example, by offering to download the Work from a remote location) the distribution channel or media (for example, a website) must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence and the way it may be accessible, concluded, stored and reproduced by the Licensee.
|
|
99
|
+
|
|
100
|
+
12. Termination of the Licence
|
|
101
|
+
The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms of the Licence.
|
|
102
|
+
|
|
103
|
+
Such a termination will not terminate the licences of any person who has received the Work from the Licensee under the Licence, provided such persons remain in full compliance with the Licence.
|
|
104
|
+
|
|
105
|
+
13. Miscellaneous
|
|
106
|
+
Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the Work.
|
|
107
|
+
|
|
108
|
+
If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or enforceability of the Licence as a whole. Such provision will be construed or reformed so as necessary to make it valid and enforceable.
|
|
109
|
+
|
|
110
|
+
The European Commission may publish other linguistic versions or new versions of this Licence or updated versions of the Appendix, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence. New versions of the Licence will be published with a unique version number.
|
|
111
|
+
|
|
112
|
+
All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take advantage of the linguistic version of their choice.
|
|
113
|
+
|
|
114
|
+
14. Jurisdiction
|
|
115
|
+
Without prejudice to specific agreement between parties,
|
|
116
|
+
|
|
117
|
+
— any litigation resulting from the interpretation of this License, arising between the European Union institutions, bodies, offices or agencies, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice of the European Union, as laid down in article 272 of the Treaty on the Functioning of the European Union,
|
|
118
|
+
|
|
119
|
+
— any litigation arising between other parties and resulting from the interpretation of this License, will be subject to the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business.
|
|
120
|
+
|
|
121
|
+
15. Applicable Law
|
|
122
|
+
Without prejudice to specific agreement between parties,
|
|
123
|
+
|
|
124
|
+
— this Licence shall be governed by the law of the European Union Member State where the Licensor has his seat, resides or has his registered office,
|
|
125
|
+
|
|
126
|
+
— this licence shall be governed by Belgian law if the Licensor has no seat, residence or registered office inside a European Union Member State.
|
|
127
|
+
|
|
128
|
+
Appendix
|
|
129
|
+
‘Compatible Licences’ according to Article 5 EUPL are:
|
|
130
|
+
|
|
131
|
+
— GNU General Public License (GPL) v. 2, v. 3
|
|
132
|
+
|
|
133
|
+
— GNU Affero General Public License (AGPL) v. 3
|
|
134
|
+
|
|
135
|
+
— Open Software License (OSL) v. 2.1, v. 3.0
|
|
136
|
+
|
|
137
|
+
— Eclipse Public License (EPL) v. 1.0
|
|
138
|
+
|
|
139
|
+
— CeCILL v. 2.0, v. 2.1
|
|
140
|
+
|
|
141
|
+
— Mozilla Public Licence (MPL) v. 2
|
|
142
|
+
|
|
143
|
+
— GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
|
|
144
|
+
|
|
145
|
+
— Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for works other than software
|
|
146
|
+
|
|
147
|
+
— European Union Public Licence (EUPL) v. 1.1, v. 1.2
|
|
148
|
+
|
|
149
|
+
— Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong Reciprocity (LiLiQ-R+)
|
|
150
|
+
|
|
151
|
+
The European Commission may update this Appendix to later versions of the above licences without producing a new version of the EUPL, as long as they provide the rights granted in Article 2 of this Licence and protect the covered Source Code from exclusive appropriation.
|
|
152
|
+
|
|
153
|
+
All other changes or additions to this Appendix require the production of a new EUPL version.
|
|
154
|
+
|
|
155
|
+
This website is not sponsored or endorsed by the European Commission or any other institution, body or agency of the European Union.
|
|
156
|
+
|
|
157
|
+
Created by Javier Casares (legal) under license EUPL 1.2.
|