thegreenwebfoundation / admin-portal

The member portal and platform powering The Green Web Foundation
Apache License 2.0
24 stars 11 forks source link

Styleguide for writing python #23

Open mrchrisadams opened 4 years ago

mrchrisadams commented 4 years ago

In the last few pull requests, I've seen a number of ways of formatting strings, from f-strings, to the format, to the older way of concatenating strings like 'somestring' + some_var.

Can we discuss getting a consistent style for writing, so we only use one approach for consistency?

I like Trey Hunner's one as an example:

https://github.com/TruthfulTechnology/style-guide

Also, the for django, I think Octopus energy has a good one.

https://github.com/octoenergy/conventions

The value here is largely having some explicit things to check against, to make reviewing PRs easier.

@jonathan-s can you add any you think would also be good candidates please?

jonathan-s commented 4 years ago

Generally I would say that 'somestring' + some_var should be avoided. Personally I think either f strings or format strings works equally fine.

Perhaps the library black could help in keeping a consistent style without creating needless quibbles?

I'll look over the style guides. The one that comes to mind is the following one: https://edx.readthedocs.io/projects/edx-developer-guide/en/latest/style_guides/python-guidelines.html

mrchrisadams commented 2 years ago

I'm summarising the conversation we've had between @tortila and @roald-teunissen

We've agreed on the following tools as defaults:

  1. black for formatting
  2. isort for consistent and predictable module imports
  3. flake8 to catch common linting issues

We use broadly follow Octopus Energy's conventions as outlined below for python

https://github.com/octoenergy/conventions

And where that does not spell things out we refer to the Django style guide to for idiomatic django:

https://docs.djangoproject.com/en/4.1/internals/contributing/writing-code/coding-style/

It's ok to veer away from these, as long as we document when we do, and why.

But absent any other guidance, this is the basic level we refer to for any code review.