-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add examples to shell
documentation
#656
Comments
I looked at the docs again, trying to come up with a pattern or concept how things could be made more accessible. I thought it would be nice to have a "roll your own interpreter support" as an example to learn on the job. Concretely, I think we could document what would be needed to support running a Python interpreter as a shell. Whether or not we would actually provide such functionality, it seems to be sufficiently different from present implementations that it would not "just work". A narrated example, with content like "why do we need this additional piece?", and "what base functionality can we customize?" would be rather insightful, I think. |
I looked into it. Python is a challenge because it uses Having said that, if we only concentrate on from datalad_next.shell import shell
from datalad_next.shell.response_generators import (
VariableLengthResponseGenerator,
)
class PythonResponseGenerator(VariableLengthResponseGenerator):
@property
def zero_command(self) -> bytes:
return b'True'
def get_final_command(self, command: bytes) -> bytes:
return f'''try:
{command.decode()}
print('{self.end_marker.decode()}')
print(0)
except:
print('{self.end_marker.decode()}')
print(1)
raise
'''.encode()
# a simple demo of `PythonResponseGenerator`
with shell(['python', '-u', '-i'], zero_command_rg_class=PythonResponseGenerator) as py:
for command in [
'1 + 1',
'a = 2 * 3',
'a / 0',
'a * 2',
]:
r = py(command)
print(command, r) The resulting output is:
This works in principle but lacks easily accessible error information. The error information could be added by rendering exceptions to Is that the kind of example that you had in mind? We could describe how an extended response generator can reliably handle exceptions in another, more complex, example. |
#596 already has extensive documentation. However, there is a significant gap between this documentation and the ability to get something going.
I believe we need to add concrete examples on:
with
blockAnd there need to be guidelines/examples on how to deal with different/unknown shell capabilities/platform detection.
Quite a few examples snippets already exist. It could be sufficient(?), but certainly useful to point them out explicitly in the top-level module docs.
The text was updated successfully, but these errors were encountered: