From b5aa568bfe59e8a263f4af85378326b50f915bc5 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 7 Jun 2021 20:06:53 +0000 Subject: pythontex (7jun21) git-svn-id: svn://tug.org/texlive/trunk@59514 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/scripts/pythontex/depythontex2.py | 4 +-- .../texmf-dist/scripts/pythontex/depythontex3.py | 4 +-- Master/texmf-dist/scripts/pythontex/pythontex2.py | 33 ++++++++++++++++------ Master/texmf-dist/scripts/pythontex/pythontex3.py | 33 ++++++++++++++++------ .../scripts/pythontex/pythontex_engines.py | 8 +++--- 5 files changed, 58 insertions(+), 24 deletions(-) (limited to 'Master/texmf-dist/scripts/pythontex') diff --git a/Master/texmf-dist/scripts/pythontex/depythontex2.py b/Master/texmf-dist/scripts/pythontex/depythontex2.py index f49fd229778..997a30d6eac 100755 --- a/Master/texmf-dist/scripts/pythontex/depythontex2.py +++ b/Master/texmf-dist/scripts/pythontex/depythontex2.py @@ -47,7 +47,7 @@ example, typeset code may have a different appearance or layout when it is typeset with a different package. -Copyright (c) 2013-2017, Geoffrey M. Poore +Copyright (c) 2013-2021, Geoffrey M. Poore All rights reserved. Licensed under the BSD 3-Clause License: http://www.opensource.org/licenses/BSD-3-Clause @@ -86,7 +86,7 @@ import codecs # Script parameters # Version -__version__ = '0.17' +__version__ = '0.18' # Functions and parameters for customizing the script output diff --git a/Master/texmf-dist/scripts/pythontex/depythontex3.py b/Master/texmf-dist/scripts/pythontex/depythontex3.py index 2d86edb5914..e27abea1188 100755 --- a/Master/texmf-dist/scripts/pythontex/depythontex3.py +++ b/Master/texmf-dist/scripts/pythontex/depythontex3.py @@ -47,7 +47,7 @@ example, typeset code may have a different appearance or layout when it is typeset with a different package. -Copyright (c) 2013-2017, Geoffrey M. Poore +Copyright (c) 2013-2021, Geoffrey M. Poore All rights reserved. Licensed under the BSD 3-Clause License: http://www.opensource.org/licenses/BSD-3-Clause @@ -86,7 +86,7 @@ import codecs # Script parameters # Version -__version__ = '0.17' +__version__ = '0.18' # Functions and parameters for customizing the script output diff --git a/Master/texmf-dist/scripts/pythontex/pythontex2.py b/Master/texmf-dist/scripts/pythontex/pythontex2.py index 34e151f4177..661ef37f2f4 100755 --- a/Master/texmf-dist/scripts/pythontex/pythontex2.py +++ b/Master/texmf-dist/scripts/pythontex/pythontex2.py @@ -13,7 +13,7 @@ should be in the same directory. Licensed under the BSD 3-Clause License: -Copyright (c) 2012-2019, Geoffrey M. Poore +Copyright (c) 2012-2021, Geoffrey M. Poore All rights reserved. @@ -78,7 +78,7 @@ else: # Script parameters # Version -__version__ = '0.17' +__version__ = '0.18' @@ -437,7 +437,7 @@ def load_code_get_settings(data, temp_data): elif v in ('false', 'False'): v = False else: - k = option + k = options v = True opt_dict[k] = v if family != ':GLOBAL': @@ -869,12 +869,15 @@ def hash_all(data, temp_data, old_data, engine_dict): if family in pygments_settings: if (not pygments_settings_changed[family] and key in old_typeset_hash_dict and - typeset_hash_dict[key] == old_typeset_hash_dict[key]): + typeset_hash_dict[key] == old_typeset_hash_dict[key] and + not modified_dependencies(key, data, old_data, temp_data)): pygments_update[key] = False if key in old_pygments_macros: pygments_macros[key] = old_pygments_macros[key] if key in old_pygments_files: pygments_files[key] = old_pygments_files[key] + if key in old_dependencies: + dependencies[key] = old_dependencies[key] else: pygments_update[key] = True else: @@ -1229,7 +1232,7 @@ def do_multiprocessing(data, temp_data, old_data, engine_dict): exec_cmd = shlex.split(command.format(file=script.replace('\\', '\\\\'), File=script_full.replace('\\', '\\\\'))) try: proc = subprocess.Popen(exec_cmd) - except (WindowsError, FileNotFoundError) as e: + except (OSError, FileNotFoundError) as e: if platform.system() == 'Windows' and e.errno == 2: # Batch files won't be found when called without extension. They # would be found if `shell=True`, but then getting the right @@ -1359,11 +1362,15 @@ def do_multiprocessing(data, temp_data, old_data, engine_dict): # Add a Pygments process if pygments_list: + # Uncomment the following for debugging + # do_pygments(encoding, outputdir, fvextfile, pygments_list, + # pygments_settings, typeset_cache, hashdependencies) tasks.append(pool.apply_async(do_pygments, [encoding, outputdir, fvextfile, pygments_list, pygments_settings, - typeset_cache])) + typeset_cache, + hashdependencies])) if verbose: print(' - Pygments process') @@ -1412,6 +1419,8 @@ def do_multiprocessing(data, temp_data, old_data, engine_dict): if result['pygments_files'][k]: new_files = True break + for k, v in result['dependencies'].items(): + dependencies[k] = v pygments_macros.update(result['pygments_macros']) errors += result['errors'] warnings += result['warnings'] @@ -1560,7 +1569,7 @@ def run_code(encoding, outputdir, workingdir, proc = subprocess.Popen(exec_cmd, stdout=out_file, stderr=err_file) else: proc = subprocess.Popen(exec_cmd, stdout=out_file, stderr=subprocess.STDOUT) - except WindowsError as e: + except OSError as e: if e.errno == 2: # Batch files won't be found when called without extension. They # would be found if `shell=True`, but then getting the right @@ -2362,7 +2371,7 @@ def run_code(encoding, outputdir, workingdir, def do_pygments(encoding, outputdir, fvextfile, pygments_list, - pygments_settings, typeset_cache): + pygments_settings, typeset_cache, hashdependencies): ''' Create Pygments content. @@ -2380,6 +2389,7 @@ def do_pygments(encoding, outputdir, fvextfile, pygments_list, warnings = 0 messages = [] messages.append('\n---- Messages for Pygments ----') + dependencies = {} # Create dicts of formatters and lexers. formatter = dict() @@ -2402,6 +2412,12 @@ def do_pygments(encoding, outputdir, fvextfile, pygments_list, f = open(c.extfile, encoding=encoding) content = f.read() f.close() + if hashdependencies: + hasher = sha1() + hasher.update(content.encode(encoding)) + dependencies[c.key_typeset] = {c.extfile: (os.path.getmtime(c.extfile), hasher.hexdigest())} + else: + dependencies[c.key_typeset] = {c.extfile: (os.path.getmtime(c.extfile), '')} else: content = None messages.append('* PythonTeX error') @@ -2440,6 +2456,7 @@ def do_pygments(encoding, outputdir, fvextfile, pygments_list, return {'process': 'pygments', 'pygments_files': pygments_files, 'pygments_macros': pygments_macros, + 'dependencies': dependencies, 'errors': errors, 'warnings': warnings, 'messages': messages} diff --git a/Master/texmf-dist/scripts/pythontex/pythontex3.py b/Master/texmf-dist/scripts/pythontex/pythontex3.py index bc61f912ca6..488c234c254 100755 --- a/Master/texmf-dist/scripts/pythontex/pythontex3.py +++ b/Master/texmf-dist/scripts/pythontex/pythontex3.py @@ -13,7 +13,7 @@ should be in the same directory. Licensed under the BSD 3-Clause License: -Copyright (c) 2012-2019, Geoffrey M. Poore +Copyright (c) 2012-2021, Geoffrey M. Poore All rights reserved. @@ -78,7 +78,7 @@ else: # Script parameters # Version -__version__ = '0.17' +__version__ = '0.18' @@ -437,7 +437,7 @@ def load_code_get_settings(data, temp_data): elif v in ('false', 'False'): v = False else: - k = option + k = options v = True opt_dict[k] = v if family != ':GLOBAL': @@ -869,12 +869,15 @@ def hash_all(data, temp_data, old_data, engine_dict): if family in pygments_settings: if (not pygments_settings_changed[family] and key in old_typeset_hash_dict and - typeset_hash_dict[key] == old_typeset_hash_dict[key]): + typeset_hash_dict[key] == old_typeset_hash_dict[key] and + not modified_dependencies(key, data, old_data, temp_data)): pygments_update[key] = False if key in old_pygments_macros: pygments_macros[key] = old_pygments_macros[key] if key in old_pygments_files: pygments_files[key] = old_pygments_files[key] + if key in old_dependencies: + dependencies[key] = old_dependencies[key] else: pygments_update[key] = True else: @@ -1229,7 +1232,7 @@ def do_multiprocessing(data, temp_data, old_data, engine_dict): exec_cmd = shlex.split(command.format(file=script.replace('\\', '\\\\'), File=script_full.replace('\\', '\\\\'))) try: proc = subprocess.Popen(exec_cmd) - except (WindowsError, FileNotFoundError) as e: + except (OSError, FileNotFoundError) as e: if platform.system() == 'Windows' and e.errno == 2: # Batch files won't be found when called without extension. They # would be found if `shell=True`, but then getting the right @@ -1359,11 +1362,15 @@ def do_multiprocessing(data, temp_data, old_data, engine_dict): # Add a Pygments process if pygments_list: + # Uncomment the following for debugging + # do_pygments(encoding, outputdir, fvextfile, pygments_list, + # pygments_settings, typeset_cache, hashdependencies) tasks.append(pool.apply_async(do_pygments, [encoding, outputdir, fvextfile, pygments_list, pygments_settings, - typeset_cache])) + typeset_cache, + hashdependencies])) if verbose: print(' - Pygments process') @@ -1412,6 +1419,8 @@ def do_multiprocessing(data, temp_data, old_data, engine_dict): if result['pygments_files'][k]: new_files = True break + for k, v in result['dependencies'].items(): + dependencies[k] = v pygments_macros.update(result['pygments_macros']) errors += result['errors'] warnings += result['warnings'] @@ -1560,7 +1569,7 @@ def run_code(encoding, outputdir, workingdir, proc = subprocess.Popen(exec_cmd, stdout=out_file, stderr=err_file) else: proc = subprocess.Popen(exec_cmd, stdout=out_file, stderr=subprocess.STDOUT) - except WindowsError as e: + except OSError as e: if e.errno == 2: # Batch files won't be found when called without extension. They # would be found if `shell=True`, but then getting the right @@ -2362,7 +2371,7 @@ def run_code(encoding, outputdir, workingdir, def do_pygments(encoding, outputdir, fvextfile, pygments_list, - pygments_settings, typeset_cache): + pygments_settings, typeset_cache, hashdependencies): ''' Create Pygments content. @@ -2380,6 +2389,7 @@ def do_pygments(encoding, outputdir, fvextfile, pygments_list, warnings = 0 messages = [] messages.append('\n---- Messages for Pygments ----') + dependencies = {} # Create dicts of formatters and lexers. formatter = dict() @@ -2402,6 +2412,12 @@ def do_pygments(encoding, outputdir, fvextfile, pygments_list, f = open(c.extfile, encoding=encoding) content = f.read() f.close() + if hashdependencies: + hasher = sha1() + hasher.update(content.encode(encoding)) + dependencies[c.key_typeset] = {c.extfile: (os.path.getmtime(c.extfile), hasher.hexdigest())} + else: + dependencies[c.key_typeset] = {c.extfile: (os.path.getmtime(c.extfile), '')} else: content = None messages.append('* PythonTeX error') @@ -2440,6 +2456,7 @@ def do_pygments(encoding, outputdir, fvextfile, pygments_list, return {'process': 'pygments', 'pygments_files': pygments_files, 'pygments_macros': pygments_macros, + 'dependencies': dependencies, 'errors': errors, 'warnings': warnings, 'messages': messages} diff --git a/Master/texmf-dist/scripts/pythontex/pythontex_engines.py b/Master/texmf-dist/scripts/pythontex/pythontex_engines.py index 4928826bf1c..6b00dbbf6f5 100755 --- a/Master/texmf-dist/scripts/pythontex/pythontex_engines.py +++ b/Master/texmf-dist/scripts/pythontex/pythontex_engines.py @@ -17,7 +17,7 @@ document (script for execution). -Copyright (c) 2012-2018, Geoffrey M. Poore +Copyright (c) 2012-2021, Geoffrey M. Poore All rights reserved. Licensed under the BSD 3-Clause License: http://www.opensource.org/licenses/BSD-3-Clause @@ -1107,14 +1107,14 @@ julia_wrapper = ''' julia_sub = '''println("{field_delim}")\nprintln({field})\n''' -CodeEngine('julia', 'julia', '.jl', '{julia} "{file}.jl"', julia_template, +CodeEngine('julia', 'julia', '.jl', '{julia} --project=@. "{file}.jl"', julia_template, julia_wrapper, 'println(jltex.formatter({code}))', julia_sub, 'ERROR:', 'WARNING:', ':{number}', True) SubCodeEngine('julia', 'jl') -CodeEngine('juliacon', 'julia', '.jl', '{julia} -e "using Weave; weave(\\"{File}.jl\\", \\"tex\\")"', '{body}\n', +CodeEngine('juliacon', 'julia', '.jl', '{julia} --project=@. -e "using Weave; weave(\\"{File}.jl\\", \\"tex\\")"', '{body}\n', '#+ term=true\n{code}\n', '', '', 'ERROR:', 'WARNING:', ':{number}', True, created='{File}.tex') @@ -1537,7 +1537,7 @@ rust_sub = ''' CodeEngine('rust', 'rust', '.rs', # The full script name has to be used in order to make Windows and Unix behave nicely # together when naming executables. Despite appearances, using `.exe` works on Unix too. - ['{rustc} --crate-type bin -o {File}.exe -L {workingdir} {file}.rs', '{File}.exe'], + ['{rustc} --crate-type bin -o "{File}.exe" -L "{workingdir}" {file}.rs', '"{File}.exe"'], rust_template, rust_wrapper, '{{ let val = {{ {code} }}; println!("{{}}", rstex.formatter(val)); }}', rust_sub, errors='error:', warnings='warning:', linenumbers='.rs:{number}', created='{File}.exe') -- cgit v1.2.3