From cc016b193e091fb3a376f4284a3f060c4abeec7f Mon Sep 17 00:00:00 2001 From: karnigen Date: Sun, 17 Dec 2023 23:03:39 +0100 Subject: initial changes --- lib/debug_utils.py | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 lib/debug_utils.py (limited to 'lib/debug_utils.py') diff --git a/lib/debug_utils.py b/lib/debug_utils.py new file mode 100644 index 00000000..6555b083 --- /dev/null +++ b/lib/debug_utils.py @@ -0,0 +1,84 @@ +# Authors: see git history +# +# Copyright (c) 2010 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +import os +import sys + +# DEBUG file format: +# - first non-comment line is debugger type +# - valid values are: +# "vscode" or "vscode-script" - for debugging with vscode +# "pycharm" or "pycharm-script" - for debugging with pycharm +# "pydev" or "pydev-script" - for debugging with pydev +# "none" or empty file - for no debugging +# - for offline debugging without inkscape, set debugger name to +# as "vscode-script" or "pycharm-script" or "pydev-script" +# - in that case running from inkscape will not start debugger +# but prepare script for offline debugging from console +# - backward compatibilty is broken due to confusion +# debug_type = 'pydev' # default debugger backwards compatibility +# if 'PYCHARM_REMOTE_DEBUG' in os.environ: # backwards compatibility +# debug_type = 'pycharm' + +# PROFILE file format: +# - first non-comment line is profiler type +# - valid values are: +# "cprofile" - for cProfile +# "pyinstrument" - for pyinstrument +# "profile" - for profile +# "none" - for no profiling + + +def parse_file(filename): + # parse DEBUG or PROFILE file for type + # - return first noncomment and nonempty line from file + value_type = 'none' + with open(filename, 'r') as f: + for line in f: + line = line.strip().lower() + if line.startswith("#") or line == "": # skip comments and empty lines + continue + value_type = line # first non-comment line is type + break + return value_type + +def write_offline_debug_script(SCRIPTDIR): + # prepare script for offline debugging from console + # - only tested on linux + import shutil + ink_file = os.path.join(SCRIPTDIR, ".ink.sh") + with open(ink_file, 'w') as f: + f.write(f"#!/usr/bin/env bash\n\n") + f.write(f"# version: {sys.version}\n") # python version + + myargs = " ".join(sys.argv[1:]) + f.write(f'# script: {sys.argv[0]} arguments: {myargs}\n') # script name and arguments + + # python module path + f.write(f"# python sys.path:\n") + for p in sys.path: + f.write(f"# {p}\n") + + # print PYTHONPATH one per line + f.write(f"# PYTHONPATH:\n") + for p in os.environ.get('PYTHONPATH', '').split(os.pathsep): + f.write(f"# {p}\n") + + # take argument that not start with '-' as file name + svg_file = " ".join([arg for arg in sys.argv[1:] if not arg.startswith('-')]) + f.write(f"# copy {svg_file} to .ink.svg\n") + # check if filer are not the same + if svg_file != '.ink.svg': + shutil.copy(svg_file, f'{SCRIPTDIR}/.ink.svg') # copy file to .ink.svg + myargs = myargs.replace(svg_file, '.ink.svg') # replace file name with .ink.svg + + # export INK*|PYTHON* environment variables + for k, v in sorted(os.environ.items()): + if k.startswith('INK') or k.startswith('PYTHON'): + f.write(f'export {k}="{v}"\n') + + # f.write(f"# python3 -m debugpy --listen 5678 --wait-for-client inkstitch.py {myargs}\n") + f.write(f"python3 inkstitch.py {myargs}\n") + os.chmod(ink_file, 0o0755) # make file executable -- cgit v1.2.3 From fe323375e42253f00fd378fbaff1a3373385fccc Mon Sep 17 00:00:00 2001 From: karnigen Date: Mon, 25 Dec 2023 19:54:52 +0100 Subject: env update from inkscape, bash names for script --- lib/debug_utils.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'lib/debug_utils.py') diff --git a/lib/debug_utils.py b/lib/debug_utils.py index 6555b083..b5d7aa6a 100644 --- a/lib/debug_utils.py +++ b/lib/debug_utils.py @@ -17,6 +17,7 @@ import sys # as "vscode-script" or "pycharm-script" or "pydev-script" # - in that case running from inkscape will not start debugger # but prepare script for offline debugging from console +# - valid for "none-script" too # - backward compatibilty is broken due to confusion # debug_type = 'pydev' # default debugger backwards compatibility # if 'PYCHARM_REMOTE_DEBUG' in os.environ: # backwards compatibility @@ -44,14 +45,14 @@ def parse_file(filename): break return value_type -def write_offline_debug_script(SCRIPTDIR): +def write_offline_debug_script(SCRIPTDIR, bash_name, bash_svg): # prepare script for offline debugging from console # - only tested on linux import shutil - ink_file = os.path.join(SCRIPTDIR, ".ink.sh") + ink_file = os.path.join(SCRIPTDIR, bash_name) with open(ink_file, 'w') as f: f.write(f"#!/usr/bin/env bash\n\n") - f.write(f"# version: {sys.version}\n") # python version + f.write(f"# python version: {sys.version}\n") # python version myargs = " ".join(sys.argv[1:]) f.write(f'# script: {sys.argv[0]} arguments: {myargs}\n') # script name and arguments @@ -61,24 +62,29 @@ def write_offline_debug_script(SCRIPTDIR): for p in sys.path: f.write(f"# {p}\n") - # print PYTHONPATH one per line + # see static void set_extensions_env() in inkscape/src/inkscape-main.cpp f.write(f"# PYTHONPATH:\n") - for p in os.environ.get('PYTHONPATH', '').split(os.pathsep): + for p in os.environ.get('PYTHONPATH', '').split(os.pathsep): # PYTHONPATH to list f.write(f"# {p}\n") # take argument that not start with '-' as file name svg_file = " ".join([arg for arg in sys.argv[1:] if not arg.startswith('-')]) - f.write(f"# copy {svg_file} to .ink.svg\n") - # check if filer are not the same - if svg_file != '.ink.svg': - shutil.copy(svg_file, f'{SCRIPTDIR}/.ink.svg') # copy file to .ink.svg - myargs = myargs.replace(svg_file, '.ink.svg') # replace file name with .ink.svg + f.write(f"# copy {svg_file} to {bash_svg}\n") + # check if files are not the same + if svg_file != bash_svg: + shutil.copy(svg_file, SCRIPTDIR / bash_svg) # copy file to bash_svg + myargs = myargs.replace(svg_file, bash_svg) # replace file name with bash_svg - # export INK*|PYTHON* environment variables - for k, v in sorted(os.environ.items()): - if k.startswith('INK') or k.startswith('PYTHON'): - f.write(f'export {k}="{v}"\n') + # see void Extension::set_environment() in inkscape/src/extension/extension.cpp + notexported = ["SELF_CALL"] # if an extension calls inkscape itself + exported = ["INKEX_GETTEXT_DOMAIN", "INKEX_GETTEXT_DIRECTORY", + "INKSCAPE_PROFILE_DIR", "DOCUMENT_PATH", "PYTHONPATH"] + for k in notexported: + if k in os.environ: + f.write(f'# export {k}="{os.environ[k]}"\n') + for k in exported: + if k in os.environ: + f.write(f'export {k}="{os.environ[k]}"\n') - # f.write(f"# python3 -m debugpy --listen 5678 --wait-for-client inkstitch.py {myargs}\n") f.write(f"python3 inkstitch.py {myargs}\n") os.chmod(ink_file, 0o0755) # make file executable -- cgit v1.2.3 From f1f9d275a1ffaeb538a72e3643fb98231323337a Mon Sep 17 00:00:00 2001 From: karnigen Date: Fri, 29 Dec 2023 16:25:17 +0100 Subject: replace DEBUG,PROFILE by DEVEL.ini --- lib/debug_utils.py | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'lib/debug_utils.py') diff --git a/lib/debug_utils.py b/lib/debug_utils.py index b5d7aa6a..183a44f8 100644 --- a/lib/debug_utils.py +++ b/lib/debug_utils.py @@ -5,6 +5,12 @@ import os import sys +from pathlib import Path + +# this file is without: import inkex +# - so we can modify sys.path before importing inkex + +# DEBUG and PROFILE are in DEVEL.ini file # DEBUG file format: # - first non-comment line is debugger type @@ -45,12 +51,24 @@ def parse_file(filename): break return value_type -def write_offline_debug_script(SCRIPTDIR, bash_name, bash_svg): +def write_offline_debug_script(SCRIPTDIR : Path, bash_name : Path, bash_svg : Path): # prepare script for offline debugging from console - # - only tested on linux + + # check if input svg file exists in arguments, take argument that not start with '-' as file name + svgs = [arg for arg in sys.argv[1:] if not arg.startswith('-')] + if len(svgs) != 1: + print(f"WARN: {len(svgs)} svg files found, expected 1, [{svgs}]. No script created in write debug script.", file=sys.stderr) + return + + svg_file = Path(svgs[0]) + if svg_file.exists() and bash_svg.exists() and bash_svg.samefile(svg_file): + print(f"WARN: input svg file is same as output svg file. No script created in write debug script.", file=sys.stderr) + return + import shutil - ink_file = os.path.join(SCRIPTDIR, bash_name) - with open(ink_file, 'w') as f: + bash_file = SCRIPTDIR / bash_name + + with open(bash_file, 'w') as f: # "w" text mode, automatic conversion of \n to os.linesep f.write(f"#!/usr/bin/env bash\n\n") f.write(f"# python version: {sys.version}\n") # python version @@ -67,13 +85,11 @@ def write_offline_debug_script(SCRIPTDIR, bash_name, bash_svg): for p in os.environ.get('PYTHONPATH', '').split(os.pathsep): # PYTHONPATH to list f.write(f"# {p}\n") - # take argument that not start with '-' as file name - svg_file = " ".join([arg for arg in sys.argv[1:] if not arg.startswith('-')]) f.write(f"# copy {svg_file} to {bash_svg}\n") # check if files are not the same if svg_file != bash_svg: shutil.copy(svg_file, SCRIPTDIR / bash_svg) # copy file to bash_svg - myargs = myargs.replace(svg_file, bash_svg) # replace file name with bash_svg + myargs = myargs.replace(str(svg_file), str(bash_svg)) # replace file name with bash_svg # see void Extension::set_environment() in inkscape/src/extension/extension.cpp notexported = ["SELF_CALL"] # if an extension calls inkscape itself @@ -86,5 +102,9 @@ def write_offline_debug_script(SCRIPTDIR, bash_name, bash_svg): if k in os.environ: f.write(f'export {k}="{os.environ[k]}"\n') + f.write('# signal inkstitch.py that we are running from offline script\n') + f.write(f'export INKSTITCH_OFFLINE_SCRIPT="True"\n') + + f.write('# call inkstitch\n') f.write(f"python3 inkstitch.py {myargs}\n") - os.chmod(ink_file, 0o0755) # make file executable + bash_file.chmod(0o0755) # make file executable -- cgit v1.2.3 From b4f50b1ed9fa6ac50bcce7bc7b78dd9c7ef6138e Mon Sep 17 00:00:00 2001 From: karnigen Date: Fri, 5 Jan 2024 17:05:22 +0100 Subject: simplification, cleanup, docs, startup dialog, DEBUG.ini --- lib/debug_utils.py | 177 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 125 insertions(+), 52 deletions(-) (limited to 'lib/debug_utils.py') diff --git a/lib/debug_utils.py b/lib/debug_utils.py index 183a44f8..298a7b80 100644 --- a/lib/debug_utils.py +++ b/lib/debug_utils.py @@ -5,54 +5,27 @@ import os import sys -from pathlib import Path +from pathlib import Path # to work with paths as objects +import configparser # to read DEBUG.ini # this file is without: import inkex -# - so we can modify sys.path before importing inkex - -# DEBUG and PROFILE are in DEVEL.ini file - -# DEBUG file format: -# - first non-comment line is debugger type -# - valid values are: -# "vscode" or "vscode-script" - for debugging with vscode -# "pycharm" or "pycharm-script" - for debugging with pycharm -# "pydev" or "pydev-script" - for debugging with pydev -# "none" or empty file - for no debugging -# - for offline debugging without inkscape, set debugger name to -# as "vscode-script" or "pycharm-script" or "pydev-script" -# - in that case running from inkscape will not start debugger -# but prepare script for offline debugging from console -# - valid for "none-script" too -# - backward compatibilty is broken due to confusion -# debug_type = 'pydev' # default debugger backwards compatibility -# if 'PYCHARM_REMOTE_DEBUG' in os.environ: # backwards compatibility -# debug_type = 'pycharm' - -# PROFILE file format: -# - first non-comment line is profiler type -# - valid values are: -# "cprofile" - for cProfile -# "pyinstrument" - for pyinstrument -# "profile" - for profile -# "none" - for no profiling - - -def parse_file(filename): - # parse DEBUG or PROFILE file for type - # - return first noncomment and nonempty line from file - value_type = 'none' - with open(filename, 'r') as f: - for line in f: - line = line.strip().lower() - if line.startswith("#") or line == "": # skip comments and empty lines - continue - value_type = line # first non-comment line is type - break - return value_type - -def write_offline_debug_script(SCRIPTDIR : Path, bash_name : Path, bash_svg : Path): - # prepare script for offline debugging from console +# - we need dump argv and sys.path as is on startup from inkscape +# - later sys.path may be modified that influences importing inkex (see prefere_pip_inkex) + + + +def write_offline_debug_script(debug_script_dir : Path, ini : configparser.ConfigParser): + ''' + prepare Bash script for offline debugging from console + arguments: + - debug_script_dir - Path object, absolute path to directory of inkstitch.py + - ini - see DEBUG.ini + ''' + + # define names of files used by offline Bash script + bash_file_base = ini.get("DEBUG","bash_file_base", fallback="debug_inkstitch") + bash_name = Path(bash_file_base).with_suffix(".sh") # Path object + bash_svg = Path(bash_file_base).with_suffix(".svg") # Path object # check if input svg file exists in arguments, take argument that not start with '-' as file name svgs = [arg for arg in sys.argv[1:] if not arg.startswith('-')] @@ -65,8 +38,8 @@ def write_offline_debug_script(SCRIPTDIR : Path, bash_name : Path, bash_svg : Pa print(f"WARN: input svg file is same as output svg file. No script created in write debug script.", file=sys.stderr) return - import shutil - bash_file = SCRIPTDIR / bash_name + import shutil # to copy svg file + bash_file = debug_script_dir / bash_name with open(bash_file, 'w') as f: # "w" text mode, automatic conversion of \n to os.linesep f.write(f"#!/usr/bin/env bash\n\n") @@ -86,9 +59,7 @@ def write_offline_debug_script(SCRIPTDIR : Path, bash_name : Path, bash_svg : Pa f.write(f"# {p}\n") f.write(f"# copy {svg_file} to {bash_svg}\n") - # check if files are not the same - if svg_file != bash_svg: - shutil.copy(svg_file, SCRIPTDIR / bash_svg) # copy file to bash_svg + shutil.copy(svg_file, debug_script_dir / bash_svg) # copy file to bash_svg myargs = myargs.replace(str(svg_file), str(bash_svg)) # replace file name with bash_svg # see void Extension::set_environment() in inkscape/src/extension/extension.cpp @@ -107,4 +78,106 @@ def write_offline_debug_script(SCRIPTDIR : Path, bash_name : Path, bash_svg : Pa f.write('# call inkstitch\n') f.write(f"python3 inkstitch.py {myargs}\n") - bash_file.chmod(0o0755) # make file executable + bash_file.chmod(0o0755) # make file executable, hopefully ignored on Windows + + +def reorder_sys_path(): + ''' + change sys.path to prefer pip installed inkex over inkscape bundled inkex + ''' + + # see static void set_extensions_env() in inkscape/src/inkscape-main.cpp + # what we do: + # - move inkscape extensions path to the end of sys.path + # - we compare PYTHONPATH with sys.path and move PYTHONPATH to the end of sys.path + # - also user inkscape extensions path is moved to the end of sys.path - may cause problems? + # - path for deprecated-simple are removed from sys.path, will be added later by importing inkex + + # PYTHONPATH to list + pythonpath = os.environ.get('PYTHONPATH', '').split(os.pathsep) + # remove pythonpath from sys.path + sys.path = [p for p in sys.path if p not in pythonpath] + # remove deprecated-simple, it will be added later by importing inkex + pythonpath = [p for p in pythonpath if not p.endswith('deprecated-simple')] + # remove nonexisting paths + pythonpath = [p for p in pythonpath if os.path.exists(p)] + # add pythonpath to the end of sys.path + sys.path.extend(pythonpath) + +# ----------------------------------------------------------------------------- +# Profilers: +# currently supported profilers: +# - cProfile - standard python profiler +# - profile - standard python profiler +# - pyinstrument - profiler with nice html output + + +def profile(profile_type, profile_dir : Path, ini : configparser.ConfigParser, extension, remaining_args): + ''' + profile with cProfile, profile or pyinstrument + ''' + profile_file_base = ini.get("PROFILE","profile_file_base", fallback="debug_profile") + profile_file_path = profile_dir / profile_file_base # Path object + + if profile_type == 'cprofile': + with_cprofile(extension, remaining_args, profile_file_path) + elif profile_type == 'profile': + with_profile(extension, remaining_args, profile_file_path) + elif profile_type == 'pyinstrument': + with_pyinstrument(extension, remaining_args, profile_file_path) + else: + raise ValueError(f"unknown profiler type: '{profile_type}'") + +def with_cprofile(extension, remaining_args, profile_file_path): + ''' + profile with cProfile + ''' + import cProfile + import pstats + profiler = cProfile.Profile() + + profiler.enable() + extension.run(args=remaining_args) + profiler.disable() + + profiler.dump_stats(profile_file_path.with_suffix(".prof")) # can be read by 'snakeviz -s' or 'pyprof2calltree' + with open(profile_file_path, 'w') as stats_file: + stats = pstats.Stats(profiler, stream=stats_file) + stats.sort_stats(pstats.SortKey.CUMULATIVE) + stats.print_stats() + print(f"Profiler: cprofile, stats written to '{profile_file_path.name}' and '{profile_file_path.name}.prof'. Use snakeviz to see it.", + file=sys.stderr) + +def with_profile(extension, remaining_args, profile_file_path): + ''' + profile with profile + ''' + import profile + import pstats + profiler = profile.Profile() + + profiler.run('extension.run(args=remaining_args)') + + profiler.dump_stats(profile_file_path.with_suffix(".prof")) # can be read by 'snakeviz' or 'pyprof2calltree' - seems broken + with open(profile_file_path, 'w') as stats_file: + stats = pstats.Stats(profiler, stream=stats_file) + stats.sort_stats(pstats.SortKey.CUMULATIVE) + stats.print_stats() + print(f"'Profiler: profile, stats written to '{profile_file_path.name}' and '{profile_file_path.name}.prof'. Use of snakeviz is broken.", + file=sys.stderr) + +def with_pyinstrument(extension, remaining_args, profile_file_path): + ''' + profile with pyinstrument + ''' + import pyinstrument + profiler = pyinstrument.Profiler() + + profiler.start() + extension.run(args=remaining_args) + profiler.stop() + + profile_file_path = profile_file_path.with_suffix(".html") + with open(profile_file_path, 'w') as stats_file: + stats_file.write(profiler.output_html()) + print(f"Profiler: pyinstrument, stats written to '{profile_file_path.name}'. Use browser to see it.", file=sys.stderr) -- cgit v1.2.3 From 0f404bb737fd5879ce8171cafb73f10ac1ec15ed Mon Sep 17 00:00:00 2001 From: karnigen Date: Thu, 11 Jan 2024 14:19:16 +0100 Subject: extending bash with cmd line args: -d -p --- lib/debug_utils.py | 71 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 12 deletions(-) (limited to 'lib/debug_utils.py') diff --git a/lib/debug_utils.py b/lib/debug_utils.py index 298a7b80..ab2a6ca9 100644 --- a/lib/debug_utils.py +++ b/lib/debug_utils.py @@ -13,7 +13,6 @@ import configparser # to read DEBUG.ini # - later sys.path may be modified that influences importing inkex (see prefere_pip_inkex) - def write_offline_debug_script(debug_script_dir : Path, ini : configparser.ConfigParser): ''' prepare Bash script for offline debugging from console @@ -42,30 +41,40 @@ def write_offline_debug_script(debug_script_dir : Path, ini : configparser.Confi bash_file = debug_script_dir / bash_name with open(bash_file, 'w') as f: # "w" text mode, automatic conversion of \n to os.linesep - f.write(f"#!/usr/bin/env bash\n\n") - f.write(f"# python version: {sys.version}\n") # python version + f.write(f'#!/usr/bin/env bash\n') + + # cmd line arguments for debugging and profiling + f.write(bash_parser()) # parse cmd line arguments: -d -p + + f.write(f'# python version: {sys.version}\n') # python version myargs = " ".join(sys.argv[1:]) f.write(f'# script: {sys.argv[0]} arguments: {myargs}\n') # script name and arguments + # environment PATH + f.write(f'# PATH:\n') + f.write(f'# {os.environ["PATH"]}\n') + # for p in os.environ.get("PATH", '').split(os.pathsep): # PATH to list + # f.write(f'# {p}\n') + # python module path - f.write(f"# python sys.path:\n") + f.write(f'# python sys.path:\n') for p in sys.path: - f.write(f"# {p}\n") + f.write(f'# {p}\n') # see static void set_extensions_env() in inkscape/src/inkscape-main.cpp - f.write(f"# PYTHONPATH:\n") + f.write(f'# PYTHONPATH:\n') for p in os.environ.get('PYTHONPATH', '').split(os.pathsep): # PYTHONPATH to list - f.write(f"# {p}\n") + f.write(f'# {p}\n') - f.write(f"# copy {svg_file} to {bash_svg}\n") + f.write(f'# copy {svg_file} to {bash_svg}\n') shutil.copy(svg_file, debug_script_dir / bash_svg) # copy file to bash_svg myargs = myargs.replace(str(svg_file), str(bash_svg)) # replace file name with bash_svg # see void Extension::set_environment() in inkscape/src/extension/extension.cpp - notexported = ["SELF_CALL"] # if an extension calls inkscape itself - exported = ["INKEX_GETTEXT_DOMAIN", "INKEX_GETTEXT_DIRECTORY", - "INKSCAPE_PROFILE_DIR", "DOCUMENT_PATH", "PYTHONPATH"] + notexported = ['SELF_CALL'] # if an extension calls inkscape itself + exported = ['INKEX_GETTEXT_DOMAIN', 'INKEX_GETTEXT_DIRECTORY', + 'INKSCAPE_PROFILE_DIR', 'DOCUMENT_PATH', 'PYTHONPATH'] for k in notexported: if k in os.environ: f.write(f'# export {k}="{os.environ[k]}"\n') @@ -77,10 +86,48 @@ def write_offline_debug_script(debug_script_dir : Path, ini : configparser.Confi f.write(f'export INKSTITCH_OFFLINE_SCRIPT="True"\n') f.write('# call inkstitch\n') - f.write(f"python3 inkstitch.py {myargs}\n") + f.write(f'python3 inkstitch.py {myargs}\n') bash_file.chmod(0o0755) # make file executable, hopefully ignored on Windows +def bash_parser(): + return ''' +set -e # exit on error + +# parse cmd line arguments: +# -d enable debugging +# -p enable profiling +# ":..." - silent error reporting +while getopts ":dp" opt; do + case $opt in + d) + arg_d="true" + ;; + p) + arg_p="true" + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + +# -v: check if variable is set +if [[ -v arg_d ]]; then + export INKSTITCH_DEBUG_ENABLE="True" +fi +if [[ -v arg_p ]]; then + export INKSTITCH_PROFILE_ENABLE="True" +fi + +''' + + def reorder_sys_path(): ''' change sys.path to prefer pip installed inkex over inkscape bundled inkex -- cgit v1.2.3 From 0e08a263116c4c5cda0fd81da122ae384a13b52a Mon Sep 17 00:00:00 2001 From: karnigen Date: Thu, 11 Jan 2024 17:48:11 +0100 Subject: updated decription --- lib/debug_utils.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'lib/debug_utils.py') diff --git a/lib/debug_utils.py b/lib/debug_utils.py index ab2a6ca9..169fa4c5 100644 --- a/lib/debug_utils.py +++ b/lib/debug_utils.py @@ -53,7 +53,7 @@ def write_offline_debug_script(debug_script_dir : Path, ini : configparser.Confi # environment PATH f.write(f'# PATH:\n') - f.write(f'# {os.environ["PATH"]}\n') + f.write(f'# {os.environ.get("PATH","")}\n') # for p in os.environ.get("PATH", '').split(os.pathsep): # PATH to list # f.write(f'# {p}\n') @@ -67,17 +67,18 @@ def write_offline_debug_script(debug_script_dir : Path, ini : configparser.Confi for p in os.environ.get('PYTHONPATH', '').split(os.pathsep): # PYTHONPATH to list f.write(f'# {p}\n') - f.write(f'# copy {svg_file} to {bash_svg}\n') + f.write(f'# copy {svg_file} to {bash_svg}\n#\n') shutil.copy(svg_file, debug_script_dir / bash_svg) # copy file to bash_svg myargs = myargs.replace(str(svg_file), str(bash_svg)) # replace file name with bash_svg # see void Extension::set_environment() in inkscape/src/extension/extension.cpp + f.write('# Export inkscape environment variables:\n') notexported = ['SELF_CALL'] # if an extension calls inkscape itself exported = ['INKEX_GETTEXT_DOMAIN', 'INKEX_GETTEXT_DIRECTORY', 'INKSCAPE_PROFILE_DIR', 'DOCUMENT_PATH', 'PYTHONPATH'] for k in notexported: if k in os.environ: - f.write(f'# export {k}="{os.environ[k]}"\n') + f.write(f'# export {k}="{os.environ[k]}"\n') for k in exported: if k in os.environ: f.write(f'export {k}="{os.environ[k]}"\n') @@ -159,21 +160,21 @@ def reorder_sys_path(): # - pyinstrument - profiler with nice html output -def profile(profile_type, profile_dir : Path, ini : configparser.ConfigParser, extension, remaining_args): +def profile(profiler_type, profile_dir : Path, ini : configparser.ConfigParser, extension, remaining_args): ''' profile with cProfile, profile or pyinstrument ''' profile_file_base = ini.get("PROFILE","profile_file_base", fallback="debug_profile") profile_file_path = profile_dir / profile_file_base # Path object - if profile_type == 'cprofile': + if profiler_type == 'cprofile': with_cprofile(extension, remaining_args, profile_file_path) - elif profile_type == 'profile': + elif profiler_type == 'profile': with_profile(extension, remaining_args, profile_file_path) - elif profile_type == 'pyinstrument': + elif profiler_type == 'pyinstrument': with_pyinstrument(extension, remaining_args, profile_file_path) else: - raise ValueError(f"unknown profiler type: '{profile_type}'") + raise ValueError(f"unknown profiler type: '{profiler_type}'") def with_cprofile(extension, remaining_args, profile_file_path): ''' -- cgit v1.2.3