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

Code style standardisation for Seldon Core Python modules #947

Closed
3 tasks
axsaucedo opened this issue Oct 13, 2019 · 10 comments
Closed
3 tasks

Code style standardisation for Seldon Core Python modules #947

axsaucedo opened this issue Oct 13, 2019 · 10 comments
Assignees

Comments

@axsaucedo
Copy link
Contributor

As discussed on the roadmap towards 1.0, one of the points which was suggested was to standardise (and keep standardised) the code style in the Python modules.

We had revisited the Python Black Formatter briefly, and there were some nuances that people disagreed on the style approach.

Black does appear to be quite popular, so may be worth going forward with the 1.0 approach. It has over 10k stars, and its opinionated non-config approach would fit quite well with the integrateion tests we have.

The only other python formatter that would be worth considering is YAPF (Yet another python formatter), which is a project by google, which seems to have also quite a lot of traction, and has been there for longer (which can be both a good and a bad thing).

For a more practical view of how each of the tools would change our codebase:

The next steps would be:

  • Decide on which formatter to go forward with
  • Run the formatter for the codebase (ensure PRs are all landed)
  • Set up formatter checks in CI
@adriangonz
Copy link
Contributor

Nice one @axsaucedo!

I quite like black's approach. In Javascript there is a similar alternative, prettier. It's also super-opinionated but thanks to that it has managed to solve most "style wars".

@axsaucedo
Copy link
Contributor Author

/assign @cliveseldon @jklaise @axsaucedo

@ukclivecox
Copy link
Contributor

@jklaise What does Alibi use and why?

@jklaise
Copy link
Contributor

jklaise commented Oct 14, 2019

In alibi we follow PEP8 (enforced by flake8 linter), with a few exceptions, most notable being the 120 line length, although I feel this is too generous and needs to be brought down (black uses 90). I do think adopting black across the projects would be the easiest thing, there are some minor quirks (e.g. it may do weird splitting if you do lengthy inline comments), but nothing we couldn't overcome. @arnaudvl @gipster @alexcoca

@axsaucedo
Copy link
Contributor Author

Awesome stuff - we currently only have #946 and #942 opened which affect the Python code, so it seems it could be a good time to do the change, and could be pretty cool to announce at the Seldon Community meeting on Thursday

@alexcoca
Copy link

I personally think making the line length shorter does not always make sense - if you have to indent 3 or 4 times and try and write a comprehension/another for loop, for example, you might end up with random line breaks which make the code not readable. I'd stick with the 120, personally.

@jklaise
Copy link
Contributor

jklaise commented Oct 15, 2019

@alexcoca my suggestion mostly stems from a lot of the time not being able to have 2 editor windows side by side even on a decent resolution monitor...

@axsaucedo
Copy link
Contributor Author

Yeah I definitely see it being annoying on having multiple indents, but I agree with @jklaise on that one point about not being able to have stuff side-by-side. Black Formatter does seem to have an option for line length (https://black.readthedocs.io/en/stable/the_black_code_style.html#line-length), which is good. I think best would be to start with defaults to get going, and perhaps see how this goes within a month?

@alexcoca
Copy link

That being said, I propose then to optimise s.t. we max the number of characters per line s.t. you can fit two windows side by side and not a character less 🕺

@axsaucedo
Copy link
Contributor Author

This was resolved by adding black + git-commit-hooks

This issue was closed.
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

5 participants