Source mapping and debugging

This commit is contained in:
Adsooi 2024-09-25 19:18:04 +02:00
parent 937cb07d0b
commit f9af0c34dd
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
12 changed files with 2313 additions and 20 deletions

View file

@ -43,7 +43,7 @@ if path.realpath(path.join(getcwd(), "..")) not in sys_path:
sys_path.append(path.realpath(path.join(getcwd(), "..")))
from LogarithmPlotter import __VERSION__
from LogarithmPlotter.util import config, native
from LogarithmPlotter.util import config, native, debug
from LogarithmPlotter.util.update import check_for_updates
from LogarithmPlotter.util.helper import Helper
from LogarithmPlotter.util.latex import Latex
@ -155,6 +155,7 @@ def run():
register_icon_directories()
app = create_qapp()
translator = install_translation(app)
debug.setup()
# Installing macOS file handler.
macos_file_open_handler = None

View file

@ -155,7 +155,7 @@ export class Domain {
return Domain.ZE
break;
default:
return new EmptySet()
return Domain.EmptySet
break;
}
}
@ -182,6 +182,8 @@ export class EmptySet extends Domain {
static import(frm) { return new EmptySet() }
}
Domain.EmptySet = new EmptySet() // To prevent use prior to declaration.
/**
* Domain classes for ranges (e.g ]0;3[, [1;2[ ...)
*/

View file

@ -34,7 +34,7 @@ const evalVariables = {
"false": false
}
export class ExprParserAPI extends Module {
class ExprParserAPI extends Module {
constructor() {
super("ExprParser")
this.currentVars = {}

View file

@ -178,4 +178,4 @@ class IOAPI extends Module {
/** @type {IOAPI} */
Modules.IO = Modules.IO || new IOAPI()
export default Modules.IO
export default Modules.IO

View file

@ -0,0 +1,80 @@
"""
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 Ad5001
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from PySide6.QtCore import QtMsgType, qInstallMessageHandler
from math import ceil, log10
from sourcemap import loads
from os import path
CURRENT_PATH = path.dirname(path.realpath(__file__))
SOURECMAP_PATH = path.realpath(f"{CURRENT_PATH}/../qml/eu/ad5001/LogarithmPlotter/js/index.mjs.map")
SOURCEMAP_INDEX = None
class LOG_COLORS:
GRAY = "\033[90m"
BLUE = "\033[94m"
ORANGE = "\033[38;5;166m"
RED = "\033[e[38;5;204m"
INVERT = "\033[7m"
RESET_INVERT = "\033[27m"
RESET = "\033[0m"
MODES = {
QtMsgType.QtInfoMsg: ['info', LOG_COLORS.BLUE],
QtMsgType.QtWarningMsg: ['warning', LOG_COLORS.ORANGE],
QtMsgType.QtCriticalMsg: ['critical', LOG_COLORS.RED],
QtMsgType.QtFatalMsg: ['critical', LOG_COLORS.RED]
}
DEFAULT_MODE = ['debug', LOG_COLORS.GRAY]
def log_qt_debug(mode, context, message):
"""
Parses and renders qt log messages.
"""
if mode in MODES:
mode = MODES[mode]
else:
mode = DEFAULT_MODE
line = context.line
source_file = context.file
# Remove source and line from emssage
if source_file is not None:
if message.startswith(source_file):
message = message[len(source_file) + 1:]
source_file = source_file.split("/qml")[-1] # We're only interested in that part.
if line is not None and message.startswith(str(line)):
line_length = ceil(log10((line+1) if line > 0 else 1))
message = message[line_length + 2:]
# Check MJS
if line is not None and source_file is not None and source_file.endswith("index.mjs"):
try:
token = SOURCEMAP_INDEX.lookup(line, 20)
source_file = source_file[:-len("index.mjs")] + token.src
line = token.src_line
except IndexError:
pass # Unable to find source, leave as is.
print(f"{LOG_COLORS.INVERT}{mode[1]}[{mode[0].upper()}]{LOG_COLORS.RESET_INVERT} {message}{LOG_COLORS.RESET} ({context.function} at {source_file}:{line})")
def setup():
global SOURCEMAP_INDEX
with open(SOURECMAP_PATH, "r") as f:
SOURCEMAP_INDEX = loads(f.read())
qInstallMessageHandler(log_qt_debug)

6
babel.config.json Normal file
View file

@ -0,0 +1,6 @@
{
"presets": ["@babel/preset-env"],
"targets": {
"esmodules": true
}
}

2199
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -13,9 +13,12 @@
"author": "Ad5001 <mail@ad5001.eu>",
"license": "GPL-3.0-or-later",
"dependencies": {
"@babel/preset-env": "^7.25.4",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^28.0.0",
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-terser": "^0.4.4",
"install": "^0.13.0",
"rollup": "^4.22.4"
}
}

13
poetry.lock generated
View file

@ -395,6 +395,17 @@ files = [
{file = "shiboken6-6.7.2-cp39-abi3-win_amd64.whl", hash = "sha256:9024e6afb2af1568ebfc8a5d07e4ff6c8829f40923eeb28901f535463e2b6b65"},
]
[[package]]
name = "sourcemap"
version = "0.2.1"
description = "Parse JavaScript source maps."
optional = false
python-versions = "*"
files = [
{file = "sourcemap-0.2.1-py2.py3-none-any.whl", hash = "sha256:c448a8c48f9482e522e4582106b0c641a83b5dbc7f13927b178848e3ea20967b"},
{file = "sourcemap-0.2.1.tar.gz", hash = "sha256:be00a90185e7a16b87bbe62a68ffd5e38bc438ef4700806d9b90e44d8027787c"},
]
[[package]]
name = "stdeb"
version = "0.10.0"
@ -438,4 +449,4 @@ type = ["pytest-mypy"]
[metadata]
lock-version = "2.0"
python-versions = ">=3.9,<3.13"
content-hash = "3db79d8b611fd2e37486fbd8e10c6d454b293cc7156d83b05c1a8459cb9b33e6"
content-hash = "30da53f0a05c06c5f93aa1260217d807ce2ab64debd26f313b47c664931e67c7"

View file

@ -20,3 +20,7 @@ stdeb = "^0.10.0"
pytest = "^8.3.3"
pytest-cov = "^5.0.0"
pytest-qt = "^4.4.0"
[tool.poetry.group.dev.dependencies]
sourcemap = "^0.2.1"

View file

@ -18,6 +18,7 @@
import { nodeResolve } from "@rollup/plugin-node-resolve"
import commonjs from "@rollup/plugin-commonjs"
import { babel } from "@rollup/plugin-babel"
import terser from "@rollup/plugin-terser"
const path = "LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js"
@ -26,16 +27,19 @@ export default {
input: `${path}/autoload.mjs`,
output: {
file: `${path}/index.mjs`,
compact: true,
compact: false,
sourcemap: true,
format: "es",
format: "es"
},
plugins: [
nodeResolve(),
nodeResolve({ browser: true }),
commonjs(),
terser({
ecma: 2015,
})
babel({
babelHelpers: "bundled"
}),
// terser({
// ecma: 2015
// })
]
}

1
run.py
View file

@ -21,6 +21,7 @@ def update_translations():
"""
from os import system, getcwd, chdir, path
pwd = getcwd()
system("npm run build")
chdir(path.join("LogarithmPlotter", "i18n"))
system("./release.sh")
chdir(pwd)