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

Shell commands throw parse error #21

Closed
sghodke-angelone opened this issue Mar 3, 2022 · 1 comment
Closed

Shell commands throw parse error #21

sghodke-angelone opened this issue Mar 3, 2022 · 1 comment

Comments

@sghodke-angelone
Copy link

sghodke-angelone commented Mar 3, 2022

Cells with shell commands throw a parse error in build 0.6.4.

To reproduce this issue create a single cell in a notebook with the following contents !ls and run blackbricks on it.

Here's a snippet of the error:

  File "/usr/local/opt/pyenv/versions/3.8.12/envs/test/lib/python3.8/site-packages/blackbricks/cli.py", line 184, in main
    n_changed_files = process_files(
  File "/usr/local/opt/pyenv/versions/3.8.12/envs/test/lib/python3.8/site-packages/blackbricks/cli.py", line 32, in process_files
    output = format_str(content, config=format_config)
  File "/usr/local/opt/pyenv/versions/3.8.12/envs/test/lib/python3.8/site-packages/blackbricks/blackbricks.py", line 111, in format_str
    black.format_str(
  File "src/black/__init__.py", line 1131, in format_str
  File "src/black/__init__.py", line 1141, in _format_str_once
  File "src/black/parsing.py", line 128, in lib2to3_parse
black.parsing.InvalidInput: Cannot parse: 1:0: !ls
@bsamseth
Copy link
Collaborator

bsamseth commented Sep 4, 2022

Using these !command style shell commands leaves you with a file that no longer parses as a valid Python file. I'm not particularly keen on trying to special-case this, as detecting and handling this, in general, would be highly non-trivial.

You can just use a %sh-cell instead, that will work, and IMO will be clearer.

%sh
ls -l

Which Databricks saves in the file as

# COMMAND ----------

# MAGIC %sh
# MAGIC ls -l

@bsamseth bsamseth closed this as not planned Won't fix, can't repro, duplicate, stale Sep 4, 2022
bsamseth added a commit that referenced this issue Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants