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

Add type hints to manim.cli module #3988

Merged
merged 12 commits into from
Nov 4, 2024

Conversation

chopan050
Copy link
Contributor

@chopan050 chopan050 commented Oct 28, 2024

As required by the issue #3375, I added typings for the manim.cli module.

I also added an entry in the docs for the cli module, although it's a work in progress.

Links to added or changed documentation pages

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@chopan050 chopan050 mentioned this pull request Oct 28, 2024
22 tasks
manim/cli/checkhealth/checks.py Dismissed Show dismissed Hide dismissed
manim/cli/render/global_options.py Fixed Show fixed Hide fixed
manim/cli/render/render_options.py Fixed Show fixed Hide fixed
manim/cli/render/render_options.py Fixed Show fixed Hide fixed
@JasonGrace2282
Copy link
Member

Could you remove this module from mypy's ignore list?

https://github.com/ManimCommunity/manim/blob/main/mypy.ini#L61-L63

@chopan050
Copy link
Contributor Author

Done!

@chopan050
Copy link
Contributor Author

I'll have to fix the MyPy errors later.

manim/cli/default_group.py Fixed Show fixed Hide fixed
manim/cli/render/render_options.py Dismissed Show dismissed Hide dismissed
@chopan050
Copy link
Contributor Author

I fixed all the errors reported by mypy.
In order to do that, I had to modify files outside of manim.cli:

  • manim._config.cli_colors.parse_cli_ctx()'s return value was typed as a cloup.Context, but it was actually a dict[str, Any], so I had to modify it.
  • I had to type OpenGLRenderer.__init__() and Scene.__init__() in order to use them in typed contexts.
  • The manim.utils.file_ops.open_file() function was missing type annotations and I had to use it in a typed context, so I also typed it.

Copy link
Member

@JasonGrace2282 JasonGrace2282 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 putting in this effort, this is amazing progress towards typing Manim fully :)

I did leave some minor comments, so I would appreciate if you could take a look at those.

manim/cli/cfg/group.py Outdated Show resolved Hide resolved
manim/cli/cfg/group.py Outdated Show resolved Hide resolved
manim/cli/cfg/group.py Outdated Show resolved Hide resolved
manim/cli/cfg/group.py Show resolved Hide resolved
manim/cli/checkhealth/checks.py Outdated Show resolved Hide resolved
manim/cli/checkhealth/checks.py Outdated Show resolved Hide resolved
manim/cli/checkhealth/checks.py Outdated Show resolved Hide resolved
# No command name matched.
ctx.arg0 = cmd_name
ctx.meta["arg0"] = cmd_name
Copy link
Member

Choose a reason for hiding this comment

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

Didn't know about this, nice change :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I was struggling to do this assignment without having mypy complain about it, so I ended up looking at click.Context in the hope of finding some dictionary, which I fortunately found!

manim/cli/init/commands.py Outdated Show resolved Hide resolved
manim/cli/init/commands.py Show resolved Hide resolved
@JasonGrace2282 JasonGrace2282 changed the title Add type hints to cli Add type hints to manim.cli module Oct 29, 2024
Copy link
Member

@JasonGrace2282 JasonGrace2282 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!
Just one minor thing, and I think this PR is good to go :)

start, end = map(int, re.split(r"[;,\-]", value))
except Exception:
logger.error("Couldn't determine a range for -n option.")
exit()
Copy link
Member

Choose a reason for hiding this comment

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

We should probably use sys.exit here, exit() is only intended for use in the REPL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right! I just made that change.

@chopan050 chopan050 enabled auto-merge (squash) November 4, 2024 15:49
@chopan050 chopan050 merged commit ee0501c into ManimCommunity:main Nov 4, 2024
17 of 18 checks passed
@chopan050 chopan050 deleted the cli-typehints branch November 4, 2024 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants