Coder Social home page Coder Social logo

Set up auto-formatting of Python about oil HOT 10 OPEN

FooBarQuaxx avatar FooBarQuaxx commented on September 28, 2024 2
Set up auto-formatting of Python

from oil.

Comments (10)

andychu avatar andychu commented on September 28, 2024

The code is in the Google Python style, which is basically pep8 with 2 space indents and CapWords for function and method names. All the contributions will have to be in that style going forward, at least until the point where there's a significant amount of code not coming from me.

I changed this bug to be to set up auto-formatting. I have experimented with yapf but didn't apply it to all the code yet. I do want there to be a consistent style and for contributors to not have to worry about reformatting their code.

When the C++ code lands it will use clang-format as well.

from oil.

andychu avatar andychu commented on September 28, 2024

Now running flake8, thanks @cclauss. It doesn't auto-format but it catches significant errors.

I'm still somewhat interested in yapf, but it's not a big priority.

from oil.

asokoloski avatar asokoloski commented on September 28, 2024

@andychu Hiya, I looked around for an Emacs mode for Google's python style, and couldn't find one anywhere. This seems to be the canonical source: https://github.com/google/styleguide

Based on that, it looks like Google doesn't use 2-space indentation for python anymore -- so they recommend using the default Emacs python mode style now. I don't know if that's enough reason to change the oilshell project style.

Assuming it's not, are you aware offhand of any Emacs mode files floating around for Google's old python style?

from oil.

andychu avatar andychu commented on September 28, 2024

Sorry I'm not sure, I'm a vim user :-)

I will say that I accept any PR that passes tests :) The functionality is the more important part.

I may go back and update the style with subsequent commits. Or if there are consistent contributors then we can automate things more.

Right now flake8 runs in Travis, and I keep it green. It could be made more strict in the future.

from oil.

andychu avatar andychu commented on September 28, 2024

Also this issue keeps getting closed because I type #1 in other contexts!

I'm reopening it although there a lot of other things that I think would benefit contributors more, e.g.

https://oilshell.zulipchat.com/#narrow/stream/121539-oil-dev/topic/Dev.20Dependencies.20Problem

from oil.

asokoloski avatar asokoloski commented on September 28, 2024

Ok, thanks, no worries. I just didn't want to make a mess once I figure out a good way to contribute, but I'm sure I'll manage.

from oil.

cclauss avatar cclauss commented on September 28, 2024

The Python Software Foundation is proposing the canonical way to format Python code and it is called black. It has integrations to Emacs, Vim, other editors. pre-commit hooks, and CI systems. Let's follow Google's lead for the formatting of Go code with gofmt but let's follow the PSF's lead for the formatting of Python code.

from oil.

andychu avatar andychu commented on September 28, 2024

test/lint.sh format-oil does this for C++

from oil.

cclauss avatar cclauss commented on September 28, 2024

Oil bundles legacy Python which went end-of-life on 1/1/2020.
The black formatting tool for Python code will not run on Python 2.

from oil.

andychu avatar andychu commented on September 28, 2024

Black can be installed by running pip install black. It requires Python 3.6.0+ to run but you can reformat Python 2 code with it, too.

https://pypi.org/project/black/

In any case this is a moot point until people who have contributed patches want it . It could be black or something else they prefer

from oil.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.