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

Chore: Fix typos and linter errors #196

Closed
wants to merge 5 commits into from
Closed

Conversation

antirotor
Copy link
Member

@antirotor antirotor commented Mar 19, 2024

Changelog Description

Fixing typos and linter errors in the repository.

Additional info

Based on #192 this is using codespell and ruff to cleanup the repo. (Un)fortunately any typo-fixed is marking the file as a food for ruff and so it starts triggering linter errors in pre-commit hook preventing the commit. The only way around it is obey the ruff tool - and that is a good thing, isn't it?

Note

This is using #192 for tools

Fixing workflow

  1. run codespell (you can set it as External tool in PyCharm for example) - ./.poetry/bin/poetry run codespell
  2. take the list of errors, fix them and run ruff on that changed file - ./.poetry/bin/poetry run ruff check /path/to/file.py
  3. fix linter errors
  4. commit

@MustafaJafar
Copy link
Contributor

MustafaJafar commented Mar 25, 2024

Hey, I gave it a shot.
Here are my exact testing steps.

I'm not used to install poetry manually. So, please correct me if any of the following steps are wrong.

  1. Copy tools\manage.ps1 from ayon-launcher repo
  2. Run ./tools/manage.ps1 create-env
  3. ./.poetry/bin/poetry run codespell
  4. ./.poetry/bin/poetry run ruff check client\ayon_core\hosts\houdini\api\lib.py .. (cool, no errors to fix)
  5. ./.poetry/bin/poetry run ruff check client\ayon_core\hosts\houdini\api\pipeline.py .. (found 1 fixable error with --fix)
  6. ./.poetry/bin/poetry run ruff check client\ayon_core\hosts\houdini\api\pipeline.py --fix .. (cool, found and fixed 1 error)
  7. git commit .. (cool, all clean.. here's my log)
PS E:\Ynput\ayon-core> git add client/ayon_core/hosts/houdini/api/pipeline.py
PS E:\Ynput\ayon-core> git commit -m "fix linting -  houdini pipeline.py"
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to C:\Users\Mustafa Taher\.cache\pre-commit\patch1711349959-35712.
[INFO] Initializing environment for https://github.com/codespell-project/codespell.
[INFO] Initializing environment for https://github.com/codespell-project/codespell:tomli.
[INFO] Initializing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Installing environment for https://github.com/codespell-project/codespell.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
don't commit to branch...................................................Passed
codespell................................................................Passed
ruff.....................................................................Passed
[INFO] Restored changes from C:\Users\Mustafa Taher\.cache\pre-commit\patch1711349959-35712.
[chore/fix_typos e432149d4f] fix linting -  houdini pipeline.py
 1 file changed, 1 deletion(-)

So, is that the expected behavior ?
Do I need to push any commits? or Did the commit part from the testing steps ?

@antirotor
Copy link
Member Author

So, is that the expected behavior ?
Do I need to push any commits? or Did the commit part from the testing steps ?

The stuff running in pre-commit hooks is run against the changed files to be commited - so if they are without typos and ruff isn't complaining, then you are fine. But try to fix typo it one of the huge files, like maya/api/lib.py - that will force you to ruff-clean the whole file :)

@antirotor
Copy link
Member Author

There is a place for fine tuning:

if you need to add some words to be ignored by codespell (like parms used in Houdini), you can edit pyproject.toml and add it to the ignore-words-list under [tools.codespell].

Warning

words in ignore-words-list must be lower-case otherwise they will be ignored.

In similar manner, ruff can be tweaked per file - remember, there is no file-wide noqa directive possible. But you can get around it using this configuration option:

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["E402"]

this will apply E402 for all __init__.py files (import must be on the top of the file)

Copy link
Collaborator

Choose a reason for hiding this comment

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

This file does not match the function in the .py file - shall we remove it completely? OR fix it up? e.g. remap_source does not have a source argument.

Also, it lacks many functions that are in the .py file.

Copy link
Member Author

Choose a reason for hiding this comment

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

we can remove it - this was there mainly for python 2 compatibility and with ayon-core, we can drop it.

@@ -1,5 +1,5 @@
from ayon_server.settings import BaseSettingsModel, SettingsField
from ayon_server.types import ColorRGBA_uint8, ColorRGB_uint8
from ayon_server.types import ColorRGBA_uint8
Copy link
Collaborator

Choose a reason for hiding this comment

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

While we're at it. Should we also remove the commented lines on lines 16-18 along with this?

Copy link
Member

@iLLiCiTiT iLLiCiTiT Mar 26, 2024

Choose a reason for hiding this comment

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

The lines are actually correct and should be used. But that would require to implement conversion of settings in server addon.

I wanted to do that when we split TVPaint to real addon.

@@ -9,7 +9,6 @@
)

from .pipeline import (
AfterEffectsHost,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if instead of removing this it should actually be added to the __all__ below instead? (Looking at what the api/__init__.py seems to do for e.g. Blender or Maya hosts.

@@ -7,7 +7,6 @@
import hiero.core
from hiero.core import util

import opentimelineio as otio
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this here to make sure otio is imported?

# append reformated tag
add_tags.append("reformated")
# append reformatted tag
add_tags.append("reformatted")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm pretty sure we should not be changing these "tags" keys unless we're entirely sure that ALL other code relying on reformated to be refactored as well?

E.g. here:

reformat_in_baking = bool("reformated" in new_repre["tags"])
and the use of the word reformated occurs in many other places instead of just here.

@@ -766,8 +766,7 @@ def _rename_groups(
group["red"],
group["green"],
group["blue"],
group_name
)
)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
)
)

@BigRoy BigRoy mentioned this pull request Mar 26, 2024
@@ -13,7 +13,6 @@ def tray_init(self):
# Add library tool
self._loader_imported = False
try:
from ayon_core.tools.loader.ui import LoaderWindow
Copy link
Member

Choose a reason for hiding this comment

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

Purpose of the method is to make sure the tool can be imported, removing the import makes it useless.

@@ -1,15 +0,0 @@
from .font_factory import FontFactory
Copy link
Member

Choose a reason for hiding this comment

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

I think removing content of api.py in this case is not a good idea. Probably rather add __all__.

@@ -720,7 +720,7 @@ class IntegrateHeroVersionModel(BaseSettingsModel):

class CleanUpModel(BaseSettingsModel):
_isGroup = True
paterns: list[str] = SettingsField(
patterns: list[str] = SettingsField(
Copy link
Member

Choose a reason for hiding this comment

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

This was kept as paterns on purpose for backwards compatibility. This would require to handle the change of the model in server addon.

@@ -1,5 +1,4 @@
import os
from .version import __version__
Copy link
Member

Choose a reason for hiding this comment

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

This is here on purpose...

Comment on lines 240 to 243
commandlet_cmd = [f'{ue_editor_exe.as_posix()}',
f'{cmdlet_project.as_posix()}',
f'-run=AyonGenerateProject',
'-run=AyonGenerateProject',
f'{project_file.resolve().as_posix()}']
Copy link
Member

@iLLiCiTiT iLLiCiTiT Mar 26, 2024

Choose a reason for hiding this comment

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

commandlet_cmd = [
    ue_editor_exe.as_posix(),
    cmdlet_project.as_posix(),
    '-run=AyonGenerateProject',
    project_file.resolve().as_posix()
]

@@ -1,13 +1,8 @@
from ayon_core.addon import (
AYONAddon,
Copy link
Member

Choose a reason for hiding this comment

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

They are here on purpose ayon_core.modules exists only for backwards compatibility.

@@ -1,4 +1,3 @@
import ayon_api
Copy link
Member

Choose a reason for hiding this comment

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

Is it ok to have first line empty?

@@ -58,7 +58,7 @@ def load(self, context, name=None, namespace=None, data=None):

normal_node.setInput(0, unpack)

null = container.createNode("null", node_name="OUT".format(name))
null = container.createNode("null", node_name="OUT".format())
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
null = container.createNode("null", node_name="OUT".format())
null = container.createNode("null", node_name="OUT")

@@ -72,5 +72,5 @@ def get_invalid(cls, instance):
if output_node.type().category().name() != "Cop2":
raise PublishValidationError(
("Output node %s is not of category Cop2. "
"This is a bug...").format(output_node.path()),
"This is a bug...").format(),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"This is a bug...").format(),
"This is a bug..."),

@@ -74,7 +74,7 @@ def process(self, instance):
renamed_to_extract.append("|".join(node_path))

with renamed(original_parent, parent_node):
self.log.debug("Extracting: {}".format(renamed_to_extract, path))
self.log.debug("Extracting: {}".format(renamed_to_extract, ))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.log.debug("Extracting: {}".format(renamed_to_extract, ))
self.log.debug("Extracting: {}".format(renamed_to_extract))

@iLLiCiTiT
Copy link
Member

This just can't be merged in single PR, or it would take too long. The PR contains crutial bugfixes, some changes that can be merged without much thinking, but also many questionable changes that need discussions. I'll start to make separate PRs based on changes here. We can keep this as reference.

@MustafaJafar
Copy link
Contributor

MustafaJafar commented Apr 1, 2024

I gave it another shot. I found out that /tools/manage.ps1 was added recently in another PR. (Cool!)

  1. Setup my environment I only need to run ./tools/manage.ps1 create-env.
  2. Running ./.poetry/bin/poetry run codespell listed a lot of files that code speed is not happy with.
  3. Fixing a typo manually and making a commit worked. (the checks only ran onto my modified files only)

I think this PR works but I wonder why do I in some case find inconsistent results ? (I have code-spell from this PR and VS extension)

Running tool provided by this PR:
It looks cool

PS E:\Ynput\ayon-core> ./.poetry/bin/poetry run codespell client\ayon_core\hosts\houdini\plugins\create\create_staticmesh.py
PS E:\Ynput\ayon-core> 

However, In the VS extension
image


A no0b question. (sorry I need to check my understanding).

  • we have ruff for linting.
  • we have code spell for Spelling checks.
    both tools check same code but for two different things. and when they conflict, ruff's opinion is stronger.

Fixing workflow mentioned in the PR description is basically:

  1. check against ruff
  2. check against code-spell
  3. fix errors
  4. check again against ruff (to ensure that spell fixes don't conflict with linting)

So, was that summary correct ?


Another question:
should we create follow up PRs to fix spelling ?
As, code-spell checks the entire file not only the changes which can be irrelevant in some PRs.

@moonyuet
Copy link
Member

moonyuet commented Apr 24, 2024

Tested with this code and it works as expected. Just wondering if this can be also applied to the addon repos which are already separate(e.g. zbrush, resolve etc.)? Or I have to add it into client folder for the check in the current stage?

@antirotor
Copy link
Member Author

closing as this was already merged via different PRs and is working

@antirotor antirotor closed this May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
host: Houdini module: Deadline size/L type: enhancement Improvement of existing functionality or minor addition
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

8 participants