diff --git a/scm/yaml_parser.scm b/scm/yaml_parser.scm index 577549e..f7bcf54 100644 --- a/scm/yaml_parser.scm +++ b/scm/yaml_parser.scm @@ -1,12 +1,22 @@ -(use-modules (ice-9 popen) (ice-9 textual-ports) (json parser)) +(if (not windows?) (use-modules (ice-9 popen))) +(use-modules (ice-9 textual-ports) (json parser)) (define (yml-file->scm filename) - (let* ((python_cmd (string-append "import sys, yaml, json; print(json.dumps(yaml.safe_load(open('" filename "'))))")) - ; WTF? On Windows there is "py" and we need to specify the encoding, on linux there is "python3" or "python" - ; but "python3" seems to work better. Be sure you have PyYAML installed. - (pipe (open-pipe (string-append "PYTHONHOME='' " (if windows? "py" "python3") " -X utf8 -c \"" python_cmd "\"") OPEN_READ)) - (json (get-string-all pipe))) - (close-pipe pipe) - (json-string->scm json))) + (if windows? + (let* ((tmpdir (or (getenv "TMPDIR") (getenv "TEMP") "/tmp")) + (port (mkstemp (string-append tmpdir file-name-separator-string (basename filename) "-XXXXXX") "r")) + (tmpfilepath (port-filename port)) + (python_code (string-append "import sys, yaml, json; f = open('" tmpfilepath "', 'w'); f.write(json.dumps(yaml.safe_load(open('" filename "')))); f.close()")) + (status (system (string-append "py -X utf8 -c \"" python_code "\""))) + (json (get-string-all port))) + (delete-file tmpfilepath) + (json-string->scm (if (status:exit-val status) json "{}"))) + (let* ((python_code (string-append "import sys, yaml, json; print(json.dumps(yaml.safe_load(open('" filename "'))))")) + ; WTF? On Windows there is "py" and we need to specify the encoding, on linux there is "python3" or "python" + ; but "python3" seems to work better. Be sure you have PyYAML installed. + (pipe (open-pipe (string-append "PYTHONHOME='' " (if windows? "py" "python3") " -X utf8 -c \"" python_code "\"") OPEN_READ)) + (json (get-string-all pipe))) + (close-pipe pipe) + (json-string->scm json)))) (define (parse-yml-file filename) (resolve-inherits (yml-file->scm filename)))