Skip to content
This repository was archived by the owner on Oct 1, 2019. It is now read-only.

Integration model for Prettier + Python #2

Open
taion opened this issue Dec 24, 2017 · 18 comments
Open

Integration model for Prettier + Python #2

taion opened this issue Dec 24, 2017 · 18 comments

Comments

@taion
Copy link
Contributor

taion commented Dec 24, 2017

This plugin stuff looks great!

I don't have a concrete proposal here, yet, but I'd like to raise a point about how integration should look. As a Python user, ideally I'd like my workflow to look something like:

$ brew install prettier
$ pip install prettier # Or maybe prettier-python.

Why? Well, it's nice not to have to reach out to npm when I'm working with Python. Additionally, while the vendoring here certainly works, it's not quite ideal (you'd have to tweak PYTHONPATH to scale things up).

It shouldn't be difficult to pull in the doc builders from Prettier and write them in Python, for example, which then ought to open up implementing all of this in Python.

The question, then, would be how to actually register the plugin.

@azz
Copy link
Member

azz commented Dec 24, 2017

You'll still need node installed for Prettier itself, but we could definitely do things to streamline that install.

@taion
Copy link
Contributor Author

taion commented Dec 25, 2017

Right – I wonder if you could use Homebrew to install Prettier though.

@taion
Copy link
Contributor Author

taion commented Dec 25, 2017

Or, like, make pip install prettier pull down both the core (somehow) and the Python plugin.

@taion
Copy link
Contributor Author

taion commented Dec 25, 2017

The thing I'd ultimately like to have is just:

$ pip install flake8-prettier

Like with eslint-plugin-prettier, and be able to think minimally about npm/Node in this context.

Consider someone running the equivalent of that in Travis or whatever – it's not always possible or convenient to pull in a Node runtime just to run my Python build pipeline.

@taion
Copy link
Contributor Author

taion commented Dec 25, 2017

(Of course that isn't possible right now, but a plugin-style architecture that makes the Node API just a client might make that possible downstream. As noted, the printing isn't the hard part, necessarily – so much as the rest of the stuff that Prettier Core offers, which could be useful in a multi-language project.)

@Timer
Copy link

Timer commented Dec 26, 2017

You could make it a self-contained executable with pkg.

@taion
Copy link
Contributor Author

taion commented Dec 26, 2017

My main concern here is less containing the Python parts than containing the Node parts. Ultimately, this project needs to target Python devs and work with Python workflows.

@taion
Copy link
Contributor Author

taion commented Dec 27, 2017

Starting to wonder if round-tripping through Node is a great idea. Given little inconsistencies like 479ecce#r26507439, it may be better to just pickle the AST, especially if we do the printing in Python.

That does bring up the question of how to make multi-parsers work, though.

@taion
Copy link
Contributor Author

taion commented Jan 2, 2018

Moving this back from prettier/prettier#3503.

ATM the most promising short-term approach seems to be to move the printing logic into Python, and have the "parser" output something closer to what most Prettier printers output, and make the printer be more of a stub. That's because there isn't a good canonical representation of the Python AST in JS anyway, so the distinction is somewhat moot.

That should be enough to make further progress here. If it turns out that, as with Markdown, the core Prettier printing code needs extensive modifications to work with Python, or if it becomes pressing to integrate with something like Flake8, then other things might be required down the road, but it's not really pressing.

@azz
Copy link
Member

azz commented Jan 2, 2018

as with Markdown, the core Prettier printing code needs extensive modifications

That's an overstatement, the changes required were only to support the blockquote format:

> lorem ipsum dollar
> stat amit.

And those changes were generic so we can support any kind of line break/ wrapping characters now.

I doubt Python will require any changes to Doc.

@taion
Copy link
Contributor Author

taion commented Jan 2, 2018

That’s great to hear, then.

@bd82
Copy link

bd82 commented Mar 6, 2018

Could someone help me understand the constraints and requirements?

What I understood so far:

  • The plugin targets mainly python developers.
  • Python developers do not want to to deal with node.js runtime and dependencies.

What I did not understand is:

  • How would moving the printing code to python make a difference if the base prettier library
    which is written in JavaScript has to be loaded anyhow?

What I'd like to ask is:

  • Would a python parser written in JavaScript assist this project in any manner?

Thanks.

@dhirschfeld
Copy link

As a Python user I'm not personally fussed with which language prettier-python is implemented in. I'm happy using npm as it's easily conda-installable and is already required for the Jupyter ecosystem.

In any case, I wouldn't expect to be manually installing it but instead would like to simply use it from my IDE being either VSCode or PyCharm.

@bd82
Copy link

bd82 commented Apr 16, 2018

Pinging in case any of the project authors have answers to my questions above?

@azz
Copy link
Member

azz commented Apr 17, 2018

Would a python parser written in JavaScript assist this project in any manner?

It'd be great, but wouldn't solve the "problem" of still needing node.js to format Python code.

@bd82
Copy link

bd82 commented Apr 17, 2018

It'd be great, but wouldn't solve the "problem" of still needing node.js to format Python code.

If this project would be a "pure" node.js project without any python parts.
Won't it be easier to bundle it as a native executable using specialized tools?

Or could this already be done?

  • even when the project utilizes two runtimes and communication between processes?

@azz
Copy link
Member

azz commented Apr 17, 2018

It is probably already doable - worth doing a spike to prove the concept?

@bd82
Copy link

bd82 commented Apr 17, 2018

I've just learned a new world for POC, "spike" 😄

I don't know if it is worth it or not, depends how severe the issue of requiring a node.js runtime is...

I am considering creating a Python Parser in JavaScript using the parsing library I've authored - Chevrotain.

If I create such a parser would you it be advantageous to use it in the python prettier plugin?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants