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

Use upstream ruamel.yaml instead of ruamel_yaml #435

Merged
merged 2 commits into from
Nov 2, 2023
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
9 changes: 4 additions & 5 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ if (HAS_JSONSCHEMA EQUAL 1)
message("python: missing `jsonschema` package is highly recommended")
endif()

execute_process(COMMAND ${Python_EXECUTABLE} -c "import ruamel_yaml as yaml" RESULT_VARIABLE HAS_YAML1 ERROR_QUIET)
execute_process(COMMAND ${Python_EXECUTABLE} -c "import ruamel.yaml as yaml" RESULT_VARIABLE HAS_YAML2 ERROR_QUIET)
execute_process(COMMAND ${Python_EXECUTABLE} -c "import yaml" RESULT_VARIABLE HAS_YAML3 ERROR_QUIET)
if ((HAS_YAML1 EQUAL 1) AND (HAS_YAML2 EQUAL 1) AND (HAS_YAML3 EQUAL 1))
message("python: missing `ruamel_yaml` (preferred) or `yaml` packages are highly recommended")
execute_process(COMMAND ${Python_EXECUTABLE} -c "import ruamel.yaml as yaml" RESULT_VARIABLE HAS_YAML1 ERROR_QUIET)
execute_process(COMMAND ${Python_EXECUTABLE} -c "import yaml" RESULT_VARIABLE HAS_YAML2 ERROR_QUIET)
if ((HAS_YAML1 EQUAL 1) AND (HAS_YAML2 EQUAL 1))
message("python: missing `ruamel.yaml` (preferred) or `yaml` packages are highly recommended")
endif()

find_program(PANDOC pandoc)
Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ but compile on most unix operating systems, including the Windows Subsystem for
- CMake 3.24+
- C++20 compiler (clang, g++, intel ixpc, ...)
- Python 3.7+ with the following packages:
- `jinja2`, `ruamel_yaml` or `yaml`
- `jinja2`, `ruamel.yaml` or `yaml`

The following are optional:

Expand Down
13 changes: 6 additions & 7 deletions examples/temper/temper.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
"from math import log, fabs, pi, cos, sin\n",
"from scipy.stats import ks_2samp\n",
"try:\n",
" try:\n",
" import ruamel.yaml as yaml\n",
" except ImportError:\n",
" # anaconda packs it as a standalone module (underscore instead of dot)\n",
" import ruamel_yaml as yaml\n",
" import ruamel.yaml\n",
"except ImportError:\n",
" import yaml"
" from yaml import safe_load as yaml_safe_load\n",
"else:\n",
" def yaml_safe_load(stream):\n",
" return ruamel.yaml.YAML(typ=\"safe\").load(stream)\n"
]
},
{
Expand All @@ -49,7 +48,7 @@
" template = jinja2.Template(template_file.read())\n",
" for replica, scale in enumerate(scale_array):\n",
" contents = template.render(scale=scale, micro=20000)\n",
" yml = yaml.safe_load(contents) # parse contents as YAML\n",
" yml = yaml_safe_load(contents) # parse contents as YAML\n",
" if not temper: \n",
" del yml[\"moves\"][1]\n",
" file = open(\"mpi{}.input.json\".format(replica), 'w')\n",
Expand Down
4 changes: 2 additions & 2 deletions scripts/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
- pandoc=2
- pypandoc=1
- beautifulsoup4=4.7
- ruamel_yaml=0.15
- ruamel.yaml=0.15
- scipy=1.2
- pygments=2.4
- jinja2=2.10
Expand All @@ -25,5 +25,5 @@ dependencies:
- jupyter_contrib_nbextensions=0.5
- sdl2=2
- jsonschema=3
- ruamel_yaml
- ruamel.yaml

10 changes: 8 additions & 2 deletions scripts/extractsids.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
sys.exit(1)

import os, json, urllib.request
import ruamel_yaml as yaml
try:
import ruamel.yaml
except ImportError:
from yaml import safe_load as yaml_safe_load
else:
def yaml_safe_load(stream):
return ruamel.yaml.YAML(typ="safe").load(stream)

if len(sys.argv)!=2:
print("usage: {} music.yml".format(sys.argv[0]))
Expand All @@ -19,7 +25,7 @@
filename = sys.argv[1]

with open(filename) as f:
sidlist = yaml.safe_load(f)
sidlist = yaml_safe_load(f)
server = sidlist['server'] + '/'
dstdir = 'sids/'
if not os.path.exists(dstdir):
Expand Down
12 changes: 6 additions & 6 deletions scripts/inject_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

from jinja2 import Template
try:
try:
import ruamel.yaml as yaml
except ImportError:
import ruamel_yaml as yaml
import ruamel.yaml
except ImportError:
import yaml
from yaml import safe_load as yaml_safe_load
else:
def yaml_safe_load(stream):
return ruamel.yaml.YAML(typ="safe").load(stream)

def extract_as_lists(schema):
'''
Expand Down Expand Up @@ -59,7 +59,7 @@ def print_table(schema, label='Keyword'):

template = Template(sys.stdin.read()) # load template from stdin
with open('schema.yml') as schema_file:
d = yaml.safe_load(schema_file)["properties"] # read schema file
d = yaml_safe_load(schema_file)["properties"] # read schema file
atomlist = d["atomlist"]["items"]["additionalProperties"]
out = template.render(topology_atomlist = print_table(atomlist, '`atomlist`'))
print(out)
4 changes: 2 additions & 2 deletions scripts/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ requirements:
- pandoc 2.*
- pypandoc 1.*
- beautifulsoup4
- ruamel_yaml
- ruamel.yaml
- cmake >=3.11.4
- numpy 1.*
- matplotlib
Expand All @@ -37,7 +37,7 @@ requirements:
- llvm-openmp # [osx]
- openmpi 1.6.* # [osx]
- openmpi 3.1.* # [linux64]
- ruamel_yaml
- ruamel.yaml
- pygments
- numpy 1.*
- python
Expand Down
22 changes: 14 additions & 8 deletions scripts/yason.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@
# API compatibility between pyyaml and ruamel.yaml might break in the future
# https://yaml.readthedocs.io/en/latest/api.html
try:
try:
import ruamel.yaml as yaml
except ImportError:
# anaconda packs it as a standalone module (underscore instead of dot)
import ruamel_yaml as yaml
import ruamel.yaml as yaml
except ImportError:
import yaml
from yaml import (
safe_load as yaml_safe_load,
safe_dump as yaml_safe_dump,
)
else:
def yaml_safe_load(stream):
return yaml.YAML(typ="safe").load(stream)

def yaml_safe_dump(data, stream=None, **kwargs):
return yaml.YAML(typ="safe").dump(data, stream=stream, **kwargs)

try:
pygments = True
Expand Down Expand Up @@ -108,7 +114,7 @@ def validate_input(instance):
schemafile = os.path.abspath(pathname+subdir) + '/schema.yml'
if os.path.exists(schemafile):
with open(schemafile, "r") as f:
_schema = yaml.safe_load(f)
_schema = yaml_safe_load(f)
error = best_match(Draft201909Validator(_schema).iter_errors(instance))
if error!=None:
eprint( "{}{}\n".format(human_readable_path(error.path), error.message) )
Expand All @@ -134,13 +140,13 @@ def validate_input(instance):
i = highlight(out, JsonLexer(), formatter())
print(i)
else:
out = yaml.safe_dump(d, indent=args.indent, allow_unicode=True)
out = yaml_safe_dump(d, indent=args.indent, allow_unicode=True)
if pygments:
out = highlight(out, YamlLexer(), formatter())
print(out)
except json.decoder.JSONDecodeError:
try: # ... to read yaml
d = yaml.safe_load(i) # plain load was deprecated in PyYAML
d = yaml_safe_load(i) # plain load was deprecated in PyYAML
if "mcloop" in d or "version" in d:
validate_input(d)
out = json.dumps(d, indent=args.indent)
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ if (ENABLE_PYTHON)
execute_process(COMMAND ${Python_EXECUTABLE} scripts/yason.py -h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ERROR_QUIET OUTPUT_QUIET RESULT_VARIABLE yasontest)
if (${yasontest} EQUAL 1)
message("missing required python modules 'yaml' or 'ruamel_yaml'")
message("missing required python modules 'yaml' or 'ruamel.yaml'")
endif()

pybind11_add_module(pyfaunus pyfaunus.cpp ${objs})
Expand Down