Skip to content

Conversation

@kajinamit
Copy link
Contributor

@kajinamit kajinamit commented Jun 8, 2025

Fix flake8 errors to improve readability of the code and also avoid potential bugs.

@kajinamit
Copy link
Contributor Author

Note: Most of the fixes (especially fixes about blank line and white space errors) are generated by autopep8

Copy link
Member

@CendioOssman CendioOssman left a comment

Choose a reason for hiding this comment

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

Nice cleanups!

Have you explored getting this in to GitHub actions as well? So we don't regress.

@kajinamit kajinamit force-pushed the flake8 branch 2 times, most recently from 92796b6 to 0bd84b8 Compare June 9, 2025 12:54
@kajinamit
Copy link
Contributor Author

Nice cleanups!

Have you explored getting this in to GitHub actions as well? So we don't regress.

I've added the workflow to run pep8 check. There are still number of checks disabled but at least we can detect any new errors. Does it make sense to you ?

We can probably use tox for the existing unit tests but I'll leave it for now.

index = 1
for f in cfg_files:
for line in [l.strip() for l in open(f).readlines()]:
for line in [raw_line.strip() for raw_line in open(f).readlines()]:
Copy link
Member

Choose a reason for hiding this comment

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

Is this a flake8 rule? I'd say it's common (desired?) to use a short name when doing list comprehension.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

flake8 does not allow ambiguous variable name and detects the following error.

./websockify/token_plugins.py:55:40: E741 ambiguous variable name 'l'

Comment on lines +1 to +2
from websockify.websocket import * # noqa: F401,F403
from websockify.websocketproxy import * # noqa: F401,F403
Copy link
Member

Choose a reason for hiding this comment

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

Can't these be easily fixed instead?

Copy link
Contributor Author

@kajinamit kajinamit Jun 12, 2025

Choose a reason for hiding this comment

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

IIUC the intention of this is to allow importing all objects from these two submodules. We can use explicit import and probably __all__ to avoid errors but I think that's overcomplicated.

Comment on lines 298 to 320
# Save off proxy specific options
self.target_host = kwargs.pop('target_host', None)
self.target_port = kwargs.pop('target_port', None)
self.wrap_cmd = kwargs.pop('wrap_cmd', None)
self.wrap_mode = kwargs.pop('wrap_mode', None)
self.wrap_cmd = kwargs.pop('wrap_cmd', None) # noqa: E221
self.wrap_mode = kwargs.pop('wrap_mode', None) # noqa: E221
self.unix_target = kwargs.pop('unix_target', None)
self.ssl_target = kwargs.pop('ssl_target', None)
self.heartbeat = kwargs.pop('heartbeat', None)
self.ssl_target = kwargs.pop('ssl_target', None) # noqa: E221
self.heartbeat = kwargs.pop('heartbeat', None) # noqa: E221

self.token_plugin = kwargs.pop('token_plugin', None)
self.host_token = kwargs.pop('host_token', None)
self.auth_plugin = kwargs.pop('auth_plugin', None)
self.host_token = kwargs.pop('host_token', None) # noqa: E221
self.auth_plugin = kwargs.pop('auth_plugin', None) # noqa: E221
Copy link
Member

Choose a reason for hiding this comment

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

This gets very messy, so not a win.

It doesn't seem like flake8 has a way to disable a rule for a block of code. And E221 is a very broad check with both useful and controversial stuff in it.

The lesser evil might be to do what PEP8 wants here.

@samhed, @kanaka, opinions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has been a while since we discussed this. I wonder if we can agree with following the pep8 guideline now (I mean, remove the adjustment commit for now) and "fix" these later if we want.
I know this is not urgent but I hope we can merge this soon, because this likely conflict with any new change, due to multiple lines being updated.

@CendioOssman
Copy link
Member

I've added the workflow to run pep8 check. There are still number of checks disabled but at least we can detect any new errors. Does it make sense to you ?

Sounds great! It allows us to lock down what we already agree on, and explore other things as we want/need.

@kajinamit kajinamit force-pushed the flake8 branch 2 times, most recently from ac750a7 to 1c0d086 Compare June 12, 2025 13:53
@kajinamit
Copy link
Contributor Author

So I think I addressed all of the points (except for ones which I believe we can't/shouldn't).

@kajinamit kajinamit changed the title Fix flake8 errors partially Fix flake8 errors Jun 13, 2025
kajinamit added 11 commits June 24, 2025 21:27
... so that we can run flake8 check more easily. Note that the check
is not yet enforced in CI.
print statement is no longer available in Python 3.
... and fix the wrong format of Sec-WebSocket-Protocol header in test
case.
... instead of == or != .
... to fix "E265 block comment should start with '# '".
Copy link
Member

@CendioOssman CendioOssman left a comment

Choose a reason for hiding this comment

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

Thanks for all the adjustments! I think this is pretty much ready to go.

There was one indentation change that looked strange, though. Could you have a look at that, after which we can merge this.

@kajinamit kajinamit force-pushed the flake8 branch 2 times, most recently from 03cac53 to 2d39629 Compare June 25, 2025 13:44
@kajinamit kajinamit requested a review from CendioOssman June 25, 2025 13:44
@kajinamit
Copy link
Contributor Author

Thanks for the additional feedback !
The indentation change is what the E125 rule requires. Please see my inline comment.

@kajinamit
Copy link
Contributor Author

kajinamit commented Jul 2, 2025

Hmm it's wired that tox.ini is ignored in CI. I can't reproduce the issue in my local...

Ignore this. I noticed I didn't commit the additional change in tox.ini properly.

kajinamit added 9 commits July 3, 2025 23:01
... which are now complained by flake8.
... to ensure the logic works only valid exceptions.
... to avoid pep8 errors caused by implicit import of a few modules.
... to get rid of F401 error by flake8.
The existing code does not expect 79 characters limit. Extend the limit
to avoid mass update.
Copy link
Member

@CendioOssman CendioOssman left a comment

Choose a reason for hiding this comment

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

Looks great!

Thanks for doing all the hard work here!

@CendioOssman CendioOssman merged commit bdf1ebf into novnc:master Jul 3, 2025
9 checks passed
@kajinamit kajinamit deleted the flake8 branch July 3, 2025 14:23
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

Successfully merging this pull request may close these issues.

2 participants