Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] finish switch to real McCode sources #46

Merged
merged 4 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions mccode_antlr/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import confuse

# Try and simplify handling configuration values need for, e.g., compiling different versions of the runtimes
# under different operating systems, while allowing a user to 'easily' override defaults if necessary.
#
Expand Down Expand Up @@ -30,5 +31,44 @@ def _platform_defaults():
return platform_configs[system]


def _common_defaults():
import yaml
from importlib.resources import files, as_file

common_file = files(__name__).joinpath('config_default.yaml')
if not common_file.is_file():
raise RuntimeError(f"Can not locate config_default.yaml in module files (looking for {common_file})")
with as_file(common_file) as file:
with open(file, 'r') as data:
common_configs = yaml.safe_load(data)

return common_configs


def registry_defaults(libc_registry, projects: list[str]):
"""Add values for @MCCODE_*@ expansion based on the in-use LIBC registry"""
from datetime import datetime

def version_macro():
from packaging.version import Version, InvalidVersion
try:
v = Version(libc_registry.version)
return (v.major * 100 + v.minor) * 1000 + v.micro
except InvalidVersion:
return 399999 # 3.99.999 to match McCode default (MCVERSION not set)

configs = {project: {} for project in projects}
for project in configs.values():
project['string'] = str(libc_registry).replace('\n', '')
project['version'] = libc_registry.version
project['version_macro'] = version_macro()
project['date'] = datetime.utcnow().strftime('%Y-%m-%d')

# Override any configurations in case this is called more than once with different information
config.set(configs)


# By using the 'add' method, we set these as the *lowest* priority. Any user/system files will override:
config.add(_platform_defaults())
#
config.add(_common_defaults())
16 changes: 16 additions & 0 deletions mccode_antlr/config/config_default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
mcstas:
name: mcstas
particle: neutron
particle_code: 2112
lib: nlib
libenv: MCSTAS
prefix: mc
project: 1
mcxtrace:
name: mcxtrace
particle: xray
particle_code: 22
lib: xlib
libenv: MCXTRACE
prefix: mx
project: 2
35 changes: 0 additions & 35 deletions mccode_antlr/libc-registry.txt

This file was deleted.

Loading
Loading