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

Feature request: support Cython and Jupyter magic? #1079

Closed
9r0x opened this issue Dec 5, 2022 · 11 comments
Closed

Feature request: support Cython and Jupyter magic? #1079

9r0x opened this issue Dec 5, 2022 · 11 comments
Labels
core Related to core functionality

Comments

@9r0x
Copy link

9r0x commented Dec 5, 2022

Hi,

I was wondering if we could consider Cython support and/or Jupiter magic because

  1. Cython code sometimes exists alongside Python code in a project, and a unified linter would be very useful?
  2. Many code and lint inside Jupyter notebook, and % in the code cell could break the lining, would be great if it can be ignored/supported.

Thanks

@charliermarsh
Copy link
Member

Cython I don't have much experience with so can't commit to anything on that front right now.

Jupyter integration though is very interesting to me and something I'd like to support!

@MarcoGorelli
Copy link

MarcoGorelli commented Dec 6, 2022

Hey,

I don't know how to use rust, but I've done some relevant work here on the Python side

For Cython, you might be interested in https://github.com/MarcoGorelli/cython-lint (which does everything flake8 used to, plus more) and seeing if that's portable to rust?

For Jupyter, I contributed its support to black, there's this file that deals with masking/unmasking magic symbols (%, %%, !, ?) - if possible, I'd strongly suggest something like that over regular expressions

@charliermarsh
Copy link
Member

Amazing, thank you @MarcoGorelli -- that's super helpful. I'll probably just port that file to Rust then.

@charliermarsh
Copy link
Member

Ruff was actually integrated into nbQA in the latest release, so you can now run (e.g.):

❯ nbqa ruff Untitled.ipynb
Untitled.ipynb:cell_1:2:5: F841 Local variable `x` is assigned to but never used
Untitled.ipynb:cell_2:1:1: E402 Module level import not at top of file
Untitled.ipynb:cell_2:1:8: F401 `os` imported but unused
Found 3 error(s).
1 potentially fixable with the --fix option.

Super cool :)

(Would still like to have a first-party integration at some point.)

@charliermarsh charliermarsh added core Related to core functionality and removed enhancement labels Dec 31, 2022
@dhruvmanila
Copy link
Member

(2) is being worked on (see #5030)

@vyasr
Copy link

vyasr commented Jul 14, 2023

@charliermarsh On the Cython side it's worth noting that isort supports Cython as of isort 5.0.0 so you may also be able to port those features over to rust (in the same way that you're hoping to port @MarcoGorelli's excellent cython-lint project). Between cython-lint and isort support I would probably consider that enough to claim Cython support, especially since flake8's support has always been patchy and incidental (prior to the change last year that disabled it entirely, necessitating flake8-force) and I believe the same is true for pylint. Just in case you were curious where to set the goalposts for this issue 😃

This might also be a strong argument for #283, though, and in particular supporting Python plugins alongside Rust plugins. Cython is a prime example of a case where the ruff developers may not have the expertise or interest in maintaining their own solution, but could happily delegate to a plugin author who doesn't have Rust experience but is willing to write one in Python.

Great work on ruff, by the way! Definitely a fan of ruff.

@MichaReiser
Copy link
Member

@dhruvmanila do we support this now that we support ipython magics?

@dhruvmanila
Copy link
Member

@dhruvmanila do we support this now that we support ipython magics?

@MichaReiser Yes, we support (2) but not (1). I'm not familiar with Cython so can't say what will be required to support it.

@MichaReiser
Copy link
Member

@9r0x could you help us understand what features you would expect from a linter supporting cpython? Is it Cython specific lint rules or is it something else?

@charliermarsh
Copy link
Member

Cython is a superset of Python. So at minimum it would require a different parser. Lets close this and create a new issue to track Cython, since there are really two independent requests here.

@MichaReiser
Copy link
Member

Done, #10250

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to core functionality
Projects
None yet
Development

No branches or pull requests

6 participants