Skip to content
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

grass.script: Explain setting of debug level #2313

Merged
merged 4 commits into from
Jun 2, 2022

Conversation

neteler
Copy link
Member

@neteler neteler commented Apr 18, 2022

Add to script.core.debug() (manual) which debug levels are recommended (see g.message, manual).
The debug message visibility is controlled by the DEBUG level set with g.gisenv (see manual).

Here some examples how the DEBUG message level management generally works:

## set DEBUG=1
GRASS nc_spm_08_grass7/user1: > g.gisenv set="DEBUG=1"
...

# msg visible:
GRASS nc_spm_08_grass7/user1: > g.message -d message="my debug message" debug=1
D1/1: G_set_program_name(): g.message
D1/1: my debug message"
D1/1: G_set_program_name(): g.gisenv
D1/1: G_set_program_name(): g.gisenv

# msg not visible
GRASS nc_spm_08_grass7/user1: > g.message -d message="my debug message" debug=2
D1/1: G_set_program_name(): g.message
D1/1: G_set_program_name(): g.gisenv
D1/1: G_set_program_name(): g.gisenv

## switch to DEBUG=2
GRASS nc_spm_08_grass7/user1: > g.gisenv set="DEBUG=2"
...

# msg now visible
GRASS nc_spm_08_grass7/user1: > g.message -d message="my debug message" debug=2
D1/2: G_set_program_name(): g.message
D2/2: G_file_name(): path = /home/mneteler/grassdata/nc_spm_08_grass7/user1
D2/2: my debug message
D1/2: G_set_program_name(): g.gisenv
D1/2: G_set_program_name(): g.gisenv

## back to debug silence
GRASS nc_spm_08_grass7/user1: > g.gisenv set="DEBUG=0"

Explain that DEBUG level is set with `g.gisenv`.
@neteler neteler added backport_needed manual Documentation related issues Python Related code is in Python labels Apr 18, 2022
@neteler neteler added this to the 8.2.0 milestone Apr 18, 2022
@neteler neteler self-assigned this Apr 18, 2022
Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current text mixes setting debug level for the message and setting debug level to control which debug messages are displayed.

Perhaps split the text into a short (one line) description of the parameter and one or two sentences in a separate paragraph providing details about the debug level (such as g.gisenv).

python/grass/script/core.py Outdated Show resolved Hide resolved
Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the syntax does not work that way. This is what is rendered:

Screenshot from 2022-04-19 09-51-53

The code block is another paragraph, not part of the parameter description.

Keeping the parameter description to just one line is the safe way syntactically, but also in terms of complexity of the text. If it is so complex it needs more than few words, you better explain it in the text with proper sentences and paragraphs. After all, this is how Python documents most functions. (NumPy is different but that's also using different syntax in the docstrings which would be a good discussion for another time.)

The code block is assumed to be Python, so verbatim would need something else. This is more a table, but perhaps it should be a sentence or two. The assignment of recommended meaning to levels lacks context and it is misleading in terms of what is recommend, the numbers or their meanings? Recommend for who?

Perhaps something like "Use 1 for messages generated once of few times, 2 for messages generated for each raster row or vector line, ..."

How does 0 make sense as a parameter here anyway?

@wenzeslaus
Copy link
Member

Here some examples how the DEBUG message level management generally works:

Maybe an example in g.gisenv man page? But this seems to be yet another candidate for a tutorial/topic/overview/intro page.

@wenzeslaus wenzeslaus changed the title libpython core docs: explain setting of debug level grass.script: Explain setting of debug level Apr 19, 2022
@BadAssassin
Copy link
Contributor

BadAssassin commented Apr 19, 2022 via email

@BadAssassin
Copy link
Contributor

Just reviewed the entire thread...

Keep in mind that the debugging routines were designed to debug the core C code. 0 is there to disable debugging (this code generally gets removed for release builds). It is okay to add debug levels for python (ie. 2) without affecting how debugging works. Just document the ones that are python specific and avoid changing the levels that already exist.

@wenzeslaus
Copy link
Member

Hm, doc/debugging.txt, never seen that. It is little too C-only, but otherwise I guess that's exactly the page I had in mind. I guess first step would be to turn this to Markdown. The second is adding some of these Markdown files to HTML doc.

@wenzeslaus
Copy link
Member

...the debugging routines were designed to debug the core C code. ...add debug levels for python...

See the implementation, currently, the Python function debug which is in question just calls g.message if debug level is greater than zero. (The sync to gisenv is done in debug_level.) Python code does not add any levels. Is that what you are thinking?

@wenzeslaus wenzeslaus modified the milestones: 8.2.0, 8.4.0 Apr 22, 2022
@neteler
Copy link
Member Author

neteler commented Apr 24, 2022

I think the syntax does not work that way

Ok, fixed, now it looks like this:

image

@neteler
Copy link
Member Author

neteler commented Jun 2, 2022

@wenzeslaus ok for merge?

Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and clear!

@neteler neteler merged commit 1f2b448 into OSGeo:main Jun 2, 2022
@neteler neteler deleted the python_docs_explain_debug branch June 2, 2022 14:14
@neteler neteler modified the milestones: 8.4.0, 8.2.1 Jun 2, 2022
neteler added a commit that referenced this pull request Oct 17, 2022
* libpython core docs: explain setting of debug level
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Oct 26, 2022
* libpython core docs: explain setting of debug level
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
* libpython core docs: explain setting of debug level
neteler added a commit to nilason/grass that referenced this pull request Nov 7, 2023
* libpython core docs: explain setting of debug level
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
manual Documentation related issues Python Related code is in Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants