-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Collection error v0.11.0 #91
Comments
Bumps [mkdocstrings](https://github.com/pawamoy/mkdocstrings) from 0.10.3 to 0.11.0. - [Release notes](https://github.com/pawamoy/mkdocstrings/releases) - [Changelog](https://github.com/pawamoy/mkdocstrings/blob/master/CHANGELOG.md) - [Commits](mkdocstrings/mkdocstrings@v0.10.3...v0.11.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Hi @pawamoy , just tried this locally, and haven't been able to produce any errors (it has all been working perfectly, with or without setup_commands). However, I have a fix in order to get the print statements back to stdout. We can do the following to catch the stdout and flush it:
Then you shouldn't need that if statement. What do you think? (Please no judgement on the variable names I just threw this together 🙈 ) |
Hey, sorry for not responding sooner, I was asleep. So this happens on https://gitpod.io, but not in CI or locally on my machine, which is interesting. Maybe this is because I have gitpod pre-configured to run |
@rossmechanic, thank you very much for looking into this! And thanks for the snippet (no judgement 😄)! I've refactored it in the following snippet. However if Python itself is executing a pre-script, faking sys.stdout might happen too late. @RDIL no problem! Is it possible to patch an installed Python library on gitpod.io? If yes, could you try to apply this patch to mkdocstrings to see if it fixes the issue? diff --git a/src/mkdocstrings/handlers/python.py b/src/mkdocstrings/handlers/python.py
index 88e8da3..f50d3f1 100644
--- a/src/mkdocstrings/handlers/python.py
+++ b/src/mkdocstrings/handlers/python.py
@@ -125,13 +125,27 @@ class PythonCollector(BaseCollector):
"""
log.debug("mkdocstrings.handlers.python: Opening 'pytkdocs' subprocess")
env = os.environ.copy()
+ env["PYTHONUNBUFFERED"] = "1"
- python_str = "; ".join(setup_commands) + "; " if setup_commands else ""
- cmd = python_str + "from pytkdocs.cli import main; main(['--line-by-line'])"
+ if setup_commands:
+ # prevent the Python interpreter or the setup commands
+ # from writing to stdout as it would break pytkdocs output
+ commands = [
+ "import sys",
+ "from io import StringIO",
+ "from pytkdocs.cli import main as pytkdocs",
+ "sys.stdout = StringIO()", # redirect stdout to memory buffer
+ *setup_commands,
+ "sys.stdout.flush()",
+ "sys.stdout = sys.__stdout__", # restore stdout
+ "pytkdocs(['--line-by-line'])"
+ ]
+ cmd = "; ".join(commands)
+ else:
+ cmd = ["pytkdocs", "--line-by-line"]
- env["PYTHONUNBUFFERED"] = "1"
self.process = Popen( # noqa: S603,S607 (we trust the input, and we don't want to use the absolute path)
- ["python", "-c", cmd], universal_newlines=True, stderr=PIPE, stdout=PIPE, stdin=PIPE, bufsize=-1, env=env,
+ cmd, universal_newlines=True, stderr=PIPE, stdout=PIPE, stdin=PIPE, bufsize=-1, env=env,
)
def collect(self, identifier: str, config: dict) -> Any: Otherwise could you tell us if the |
I can try it out. |
Hey @pawamoy, I tried the patch but it has just been frozen for 15 minutes. From the output of |
Hmmm forget about it. I'm trying it myselfin gitpod.io on your repo, and the error happens only when trying to collect filehandlers. |
Really not sure to understand what's happening here 😅 Thank you for trying it out @RDIL I'll investigate a bit more. Oh and the patch I gave you was wrong anyway... terribly sorry... |
@pawamoy no worries! |
Well I can confirm the issue only happens when running the process with mkdocs serve # fails
python3 -c "from mkdocs.commands.serve import serve; serve()" # works |
OK seems to be related to pyenv: /home/gitpod/.pyenv/shims/python3 -c "from mkdocs.commands.serve import serve; serve()"
# works
/home/gitpod/.pyenv/versions/3.8.2/bin/python3 -c "from mkdocs.commands.serve import serve; serve()"
# fails, the mkdocs script uses this path |
If think they have some issues on gitpod.io with Python venvs because I just can't install anything in a virtualenv. It works, message says "Successfully installed..." but then EDIT: needs |
Conclusion:
In the meantime @RDIL you can use I'll close this issue once the fix mentioned in point 4 is implemented! Thank you @RDIL and @rossmechanic for your help 🙂 |
Describe the bug
Collection error due to JSON failing to load the file line read on stdout. I suspect the Python interpreter to pre-execute code that is writing to stdout, or simply writing some blank lines to stdout for some reason.
To Reproduce
Waiting for feedback in rdilweb/docs@cc20660
Expected behavior
No collection error.
Information (please complete the following information):
mkdocstrings
version: 0.11.0Additional context
Possible fix:
Ping @RDIL @rossmechanic
The text was updated successfully, but these errors were encountered: