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

Fix python syntax in modm_tools #1189

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

rleh
Copy link
Member

@rleh rleh commented Jul 13, 2024

With recent python versions there are a lot of warnings (DeprecationWarning until python 3.11, SyntaxWarning from version 3.12 onwards) generated from the modm_tools python code:

$ scons
scons: Reading SConscript files ...
/...blink/modm/modm_tools/bmp.py:13: SyntaxWarning: invalid escape sequence '\*'
  """
/.../blink/modm/modm_tools/build_id.py:13: SyntaxWarning: invalid escape sequence '\*'
[...]

Is it necessary to adapt the way this doc strings are extracted form the python files, @salkinium? I don't know where exactly that happens...

@salkinium
Copy link
Member

salkinium commented Jul 13, 2024

These docs are assembled here:

class BuildModuleDocs:
def __init__(self):
self._content = None
def __str__(self):
if self._content is None:
self._content = Path(localpath("module.md")).read_text(encoding="utf-8").strip()
tools = ["avrdude", "openocd", "bmp", "gdb", "size", "info", "jlink",
"unit_test", "itm", "rtt", "build_id", "bitmap", "elf2uf2"]
for tool in tools:
tpath = Path(repopath("tools/modm_tools/{}.py".format(tool)))
doc = None
# Documentation is inside a Markdown file
if tpath.with_suffix(".md").exists():
doc = tpath.with_suffix(".md").read_text(encoding="utf-8")
# Documentation is inside the tool as a docstring
elif tpath.exists():
doc = re.search('"""(.*?)"""', tpath.read_text(encoding="utf-8"), flags=re.DOTALL | re.MULTILINE)
if doc: doc = doc.group(1);
if doc is not None:
self._content += "\n\n\n" + doc.strip()
return self._content

Best check with lbuild discover -n :build if the * star is still displayed correctly. I forgot that doesn't do any formatting, so it'll display \*. 🤦

@salkinium
Copy link
Member

Hm, I don't know, the homepage built test shows that the * star is also rendered \*.

@rleh rleh force-pushed the fix/modm_tools_python_syntax branch from 92892a2 to 824646c Compare August 7, 2024 21:08
Copy link
Member

@salkinium salkinium left a comment

Choose a reason for hiding this comment

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

It makes the website show \* instead of *. Do we want to use this one instead?

@calebchalmers
Copy link
Contributor

Could you simply remove the slashes and put (* *only ...*) in the doc strings? I believe the first asterisk will be preserved in markdown because of the space after it.

@rleh
Copy link
Member Author

rleh commented Aug 21, 2024

Using raw string seems to work fine:

Comparison screenshots 🖼️ 🖼️

image
image

@rleh rleh requested a review from salkinium August 21, 2024 10:17
Copy link
Member

@salkinium salkinium left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@rleh rleh force-pushed the fix/modm_tools_python_syntax branch from bceeda1 to f58b42f Compare August 21, 2024 17:09
@rleh rleh merged commit f58b42f into modm-io:develop Aug 21, 2024
12 checks passed
@rleh rleh deleted the fix/modm_tools_python_syntax branch August 21, 2024 18:11
@salkinium salkinium added this to the 2024q3 milestone Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants