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

Introduce better coding style #171

Merged
merged 19 commits into from Oct 23, 2021
Merged

Conversation

Superskyyy
Copy link
Member

@Superskyyy Superskyyy commented Oct 22, 2021

This PR migrates existing usage of old-style string manipulation (%, .format and +) to f-strings for better clarity and some performance boost.

Adds stricter coding style.

Optimizes debug messages for performance.

Signed-off-by: Superskyyy superskyyy@outlook.com

Signed-off-by: Superskyyy <superskyyy@outlook.com>
Signed-off-by: Superskyyy <superskyyy@outlook.com>
Signed-off-by: Superskyyy <superskyyy@outlook.com>
Signed-off-by: Superskyyy <superskyyy@outlook.com>
Signed-off-by: Superskyyy <superskyyy@outlook.com>
Signed-off-by: Superskyyy <superskyyy@outlook.com>
Signed-off-by: Superskyyy <superskyyy@outlook.com>
Signed-off-by: Superskyyy <superskyyy@outlook.com>
Signed-off-by: Superskyyy <superskyyy@outlook.com>
Copy link
Member

@kezhenxu94 kezhenxu94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Superskyyy

BTW, @Superskyyy can you help to set up the quote style in flake8? I see we use double quotes (") somewhere and single quotes (') elsewhere, I'd like see them consistent. WDYT?

I'm also wondering whether we can have flake8 rules to check there is no more old-style string manipulation other than f-string?

@kezhenxu94 kezhenxu94 added chore Project chores enhancement New feature or request labels Oct 22, 2021
@kezhenxu94 kezhenxu94 added this to the 1.0.0 milestone Oct 22, 2021
@Superskyyy
Copy link
Member Author

Superskyyy commented Oct 22, 2021

Thanks @Superskyyy

BTW, @Superskyyy can you help to set up the quote style in flake8? I see we use double quotes (") somewhere and single quotes (') elsewhere, I'd like see them consistent. WDYT?
@kezhenxu94
Yeah that I did try to mitigate last night, Idk if there's a rule to enforce the style, do you know of one?

@Superskyyy
Copy link
Member Author

Superskyyy commented Oct 22, 2021

https://github.com/zheller/flake8-quotes I'm going to try this one.

That worked, got a mountain of code to fix.. AFAIK single quotes are generally more preferred.

@Superskyyy
Copy link
Member Author

Let's wait a bit, almost done, got automation.

Signed-off-by: Superskyyy <superskyyy@outlook.com>
Signed-off-by: Superskyyy <superskyyy@outlook.com>
Signed-off-by: Superskyyy <superskyyy@outlook.com>
- intentional lint failure

Signed-off-by: Superskyyy <superskyyy@outlook.com>
Signed-off-by: Superskyyy <superskyyy@outlook.com>
@wu-sheng
Copy link
Member

Please add this to the ASF repo control file. The approval seems not dismissed.

https://github.com/apache/skywalking/blob/master/.asf.yaml#L49

Signed-off-by: Superskyyy <superskyyy@outlook.com>
@Superskyyy
Copy link
Member Author

Please add this to the ASF repo control file. The approval seems not dismissed.

apache/skywalking@master/.asf.yaml#L49

Done

@Superskyyy
Copy link
Member Author

@kezhenxu94 It should be good now.

Lint enforcement for quotes added, fixed existing.
Added doc for coding style.
Optimized debug statements for throughput.

💀 I noticed the renaming of tests brought ~6k LOC to my credit, sorry about that...

@Superskyyy Superskyyy changed the title Migrate to 3.6+ style string format Introduce better coding style Oct 22, 2021
Signed-off-by: Superskyyy <superskyyy@outlook.com>
@Superskyyy
Copy link
Member Author

Ah, I forgot about the f-string check.. adding now.

Signed-off-by: Superskyyy <superskyyy@outlook.com>
Signed-off-by: Superskyyy <superskyyy@outlook.com>
@Superskyyy
Copy link
Member Author

More rules coming in next PR, have some more cleanup to do.

@wu-sheng
Copy link
Member

It is great to have these cleanup before our important 1.0.0 release!

Please do not use other styles - `+`, `%` or `.format` unless f-string is absolutely unfeasible in the context, or
it is a logger message, which is [optimized](https://docs.python.org/3/howto/logging.html#optimization) for the `%` style

Run [flynt](https://github.com/ikamensh/flynt) to convert other formats to f-string, pay **extra care** to possible corner
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding this to a new Makefile target, for example fix-lint?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding this to a new Makefile target, for example fix-lint?

NVM, let's do this in following PRs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have another PR coming. Was taking a nap :)

bar = f"This repo is called 'skywalking-python'"
```

Run [unify](https://github.com/myint/unify) `unify -r your_target --in-place` to fix your quotes if flake8 complaints about it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding this to a new Makefile target, for example fix-lint?

@kezhenxu94
Copy link
Member

💀 I noticed the renaming of tests brought ~6k LOC to my credit, sorry about that...

Never mind, it's OK because GitHub counts renamed files' lines in contribution graph but the renaming doesn't change the git blame, we can track the changes still.

@kezhenxu94 kezhenxu94 merged commit 9b0f83d into apache:master Oct 23, 2021
@Superskyyy Superskyyy deleted the migrate2fstring branch October 24, 2021 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Project chores enhancement New feature or request
Projects
None yet
3 participants