-
Notifications
You must be signed in to change notification settings - Fork 129
[IMP] Add suppor for Pydevd/Pycharm #542
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
base: main
Are you sure you want to change the base?
Conversation
Nice to see preparations for official support for this. Which version of PyCharm would you be targeting? Our current code to generate the mappings which requires to first save the run config as project file and it requires first creating a /=/ fake mapping in the run config to create the xml that we can patch. (works less well in current versions of PyCharm as they are only saving those files to the file system on pycharm close) if [[ -e .idea/runConfigurations/ || -e .run ]] ; then
function get_mappings() {
# mapping paths adds support for clicking the stacktrace, as well as mapping the source in debugger
while read -r line; do
directory=$(dirname "$line")
addon_name=$(basename "$directory")
echo "$addon_name => $directory" 1>&2
echo "$INDENT<mapping local-root=\"\$PROJECT_DIR\$/$directory\" remote-root=\"/opt/odoo/auto/addons/$addon_name\" />"
done < <(find odoo/custom/src -name '__manifest__.py' | grep -v '/odoo/')
if [[ -e odoo/custom/src/odoo/odoo-bin ]] ; then
# since PyCharm 2022.2 it is necessary to specify a locally existing script, so we need to map the odoo-bin to /usr/local/bin/odoo
# to be able to run odoo correctly
echo "$INDENT<mapping local-root=\"\$PROJECT_DIR\$/odoo/custom/src/odoo/odoo-bin\" remote-root=\"/usr/local/bin/odoo\" />"
fi
echo "$INDENT<mapping local-root=\"\$PROJECT_DIR\$/odoo/custom/src/odoo/addons\" remote-root=\"/opt/odoo/auto/addons\" />"
echo "$INDENT<mapping local-root=\"\$PROJECT_DIR\$/odoo/custom/src\" remote-root=\"/opt/odoo/custom/src\" />"
# mapping for restore_encrypted.yaml
echo "$INDENT<mapping local-root=\"\$PROJECT_DIR\$/restore.d\" remote-root=\"/opt/odoo/restore\" />"
}
TMP_NEW_MAPPING_FILE=""
while read -r FILE; do
if [[ -e "$FILE" ]] ; then
if [[ "$FILE" == *".mapping" || "$FILE" == *".new_mapping" || "$FILE" == *".new" ]] ; then
# file is a fragment of an old run
rm "$FILE"
continue
fi
TMP_FILE="${FILE}.new"
TMP_MAPPING_FILE="${FILE}.mapping"
INDENT=" "
BASE_NAME=$(basename "$0")
if [[ "$0" != "" && "$0" != -* && "$BASE_NAME" == "local_dev.sh" ]] ; then
# we are not running inside of source ./local_dev.sh
set -e
DIR_NAME=$(dirname "$0")
cd "$DIR_NAME"
fi
# It is important that the file has already any mapping set before
grep '<mapping' "$FILE" > "$TMP_MAPPING_FILE"
if [[ ! $TMP_NEW_MAPPING_FILE ]]; then
TMP_NEW_MAPPING_FILE="${FILE}.new_mapping"
get_mappings >> "$TMP_NEW_MAPPING_FILE"
fi
if ! diff "$TMP_MAPPING_FILE" "$TMP_NEW_MAPPING_FILE"; then
echo "Updating path mapping '$FILE'"
grep '<mapping' -m 1 --before-context=1024 "$FILE" | grep -v '<mapping' > "$TMP_FILE"
cat "$TMP_NEW_MAPPING_FILE" >> "$TMP_FILE"
# this is not working on mac osx (--after-context) so we use a short script for getting the last few lines
#cat $FILE | grep '<mapping' -m 1 --after-context=1024 | grep -v '<mapping' >> "$TMP_FILE"
last_mapping_line=$(grep '<mapping' -n "$FILE" | tail -n 1 | awk -F: '{print $1}')
total_lines=$(wc -l "$FILE" | awk '{print $1}')
newline_correction=$((1 - $(tail -c 1 "$FILE" | wc -l))) # file might not end in a newline (then we need to add 1 to the lines at the end)
lines_at_the_end=$((total_lines - last_mapping_line + newline_correction))
tail -n ${lines_at_the_end} "$FILE" >> "$TMP_FILE"
# switch contents of the xml file
mv "$FILE" "$FILE.bak"
mv "$TMP_FILE" "$FILE"
rm "$FILE.bak"
else
echo "Unchanged path mapping '$FILE'"
fi
rm "$TMP_MAPPING_FILE"
fi
done < <(grep -Rl '<mapping' .idea/runConfigurations/ .run/ 2>/dev/null)
if [[ $TMP_NEW_MAPPING_FILE && -e "$TMP_NEW_MAPPING_FILE" ]] ; then
rm "$TMP_NEW_MAPPING_FILE"
fi
fi |
5cd2db9
to
80367fb
Compare
@ap-wtioit It’s almost ready to generate it using task.py, but we have a problem when reading the variables—we can’t figure out what’s going on. I’ll show you the error in the following image: Do you have any idea why this might be happening? Here you have the traceback
|
To me it looks like you have enabled the deep inspection of python variables in the current breakpoint context. This does not work well with Odoo's ORM / Cache. Update: can you have a look what value you are using for "Variables Loading Policy". The other reason for such stack traces (not the exact one) when debugging with PyCharm i get, is when the transaction is rollbacked but the debugger has not yet exited and is still trying to load variables through the ORM. |
80367fb
to
f31ad34
Compare
ok, it also could be that the pydevd you are using is not compatible with your pycharm. it looks like you are using the one installed in the doodba image. i'm usually running the one provided by pycharm (and using
(running a proprietary module test because this was the last working debug config for me, i don't have one with stock.picking installed/available) The following lines:
are produced by our code to fix the pycharm run / debug / profiling / coverage in our base image direxec to fix the listening ip to one that is working inside the container (available in the containers interfaces) and forwarded with socat (docker-whitelist) dynamically to the correct dynamic pycharm port on 172.16.0.5:41239 by another script that watches for those ports and connects them. But the docker / pydevd settings are highly specific for the PyCharm Major version as JetBrains is always changing the docker integration (and often breaking it). |
f31ad34
to
bf5c8be
Compare
bf5c8be
to
0cb2a55
Compare
Scaffolding support for debugging with pydevd/pycharm.
Depends on Tecnativa/doodba#665
How to test: clone/update a template with the option
--vcs-ref=dck-imp-pydev_debugger
Example:
copier update --vcs-ref=dck-imp-pydev_debugger --trust -f
Change dockerfile ref to
ghcr.io/tecnativa/doodba:${ODOO_VERSION}-pr-665-test-onbuild
Rebuild the image, run git aggregate and then start with --pycharm
Pycharm has an issue where stopping the remote debugger causes a constant stream of notifications and errors, only resolved by restarting pycharm. That is unrelated to this PR and has been reported to JetBrains for a month.