Skip to content

Adding :class: ManimColor to manim and converting all types #3020

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

Merged
merged 75 commits into from
Aug 8, 2023

Conversation

MrDiver
Copy link
Collaborator

@MrDiver MrDiver commented Nov 13, 2022

Overview: What does this pull request change?

This pull request aims to remove all the duplicates of color handling in Manim and unify all colors under one Color type named ManimColor and a TypeAlias ParsableManimColor which represents all types that can be converted to a ManimColor

Motivation and Explanation: Why and how do your changes improve the library?

Links to added or changed documentation pages

Further Information and Comments

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

closes #2837

@MrDiver MrDiver added the enhancement Additions and improvements in general label Nov 13, 2022
Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

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

Is TypeAlias Python 3.10+ only? I'd perhaps be fine with deprecating Python 3.7, but skipping everything until 3.10 is somewhat inconvenient. :-)

@MrDiver
Copy link
Collaborator Author

MrDiver commented Nov 14, 2022

I think it was more about the reuse of all the lists in ManimColor and ParsableManimColor

And yes TypeAlias is only 3.10 that's why I didn't use it directly but you can still do it without typing

@Viicos
Copy link
Member

Viicos commented Nov 15, 2022

Is TypeAlias Python 3.10+ only? I'd perhaps be fine with deprecating Python 3.7, but skipping everything until 3.10 is somewhat inconvenient. :-)

Ah yes forgot about that, but indeed it can still be done without it (e.g. ManimColorInputType = str | int | list[...)

@MrDiver MrDiver marked this pull request as draft December 17, 2022 11:37
@MrDiver MrDiver marked this pull request as ready for review December 17, 2022 11:38
from typing import Any, Sequence, Union

import numpy as np
from typing_extensions import Literal, TypeAlias

Check notice

Code scanning / CodeQL

Unused import

Import of 'Literal' is not used.
@jsonvillanueva
Copy link
Member

For the record, #3264 introduces a new file and also a new class which could use the ParsableManimColor. I'm not sure to what extent you're trying to cover all instances of color within the library, but it's shaping out nicely. Should I maybe check this branch out and give it a closer look for/commit other missing occurrences?

@MrDiver MrDiver force-pushed the color_fix branch 2 times, most recently from 67772a8 to e1c8419 Compare August 4, 2023 04:03
@MrDiver
Copy link
Collaborator Author

MrDiver commented Aug 4, 2023

For the record, #3264 introduces a new file and also a new class which could use the ParsableManimColor. I'm not sure to what extent you're trying to cover all instances of color within the library, but it's shaping out nicely. Should I maybe check this branch out and give it a closer look for/commit other missing occurrences?

Already ✅ done thank you for the info! that was very helpful to know!

@MrDiver
Copy link
Collaborator Author

MrDiver commented Aug 4, 2023

Remaining TODOs, almost done here:

* check remaining TODOs still committed

There are 2 Todos still remaining, one is the fixing of the color structure passing down colors through constructors and making sure that there are sane default values for everything but it seems to work fine because labeled.py worked flawless without any changes.

The other one with the gradient is just some issue that we kind of also had before, because we just didn't have a good implementation. I just referenced the other function for now. So it can safely be done at a later stage.

* fix color example
  • Still needs to be done
* perhaps somewhat more information what "included in global namespace" means

In which file do we have this ?

* one-line docstrings for `core.py` would be nice

core.py is fully documented now!


"""

from .core import ManimColor

Check notice

Code scanning / CodeQL

Cyclic import

Import of module [manim.utils.color.core](1) begins an import cycle.

from . import AS2700, BS381, X11, XKCD
from .core import *
from .manim_colors import *

Check notice

Code scanning / CodeQL

'import *' may pollute namespace

Import pollutes the enclosing namespace, as the imported module [manim.utils.color.manim_colors](1) does not define '__all__'.
LOGO_RED = ManimColor("#E07A5F")
LOGO_BLACK = ManimColor("#343434")

_all_manim_colors: List[ManimColor] = [

Check notice

Code scanning / CodeQL

Unused global variable

The global variable '_all_manim_colors' is not used.
ManimColor
_description_
"""
import manim.utils.color.manim_colors as manim_colors

Check notice

Code scanning / CodeQL

Cyclic import

Import of module [manim.utils.color.manim_colors](1) begins an import cycle.
Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

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

I am very happy to finally get a sane(r) color model into the library. Thanks to everyone who was involved here, and in particular @MrDiver! 👏

@behackl behackl added the highlight For contributions that should be highlighted explicitly in the next changelog label Aug 8, 2023
@behackl behackl merged commit 82e55b5 into ManimCommunity:main Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking changes This PR introduces breaking changes enhancement Additions and improvements in general highlight For contributions that should be highlighted explicitly in the next changelog
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Finally fixing the Color situation
6 participants