Skip to content

Make Text and Tex robust against non-existing text_dir and tex_dir #492

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 12 commits into from
Oct 14, 2020

Conversation

behackl
Copy link
Member

@behackl behackl commented Sep 29, 2020

List of Changes

  • When creating Tex and Text, check whether tex_dir and text_dir exist, respectively -- and if they don't, create them.
  • Remove TextWithBackground from text_mobject.py. This was a non-working feature that basically copied code from Text. Code like that makes manim extremely hard to maintain in the long run. (Actually, also currently.)

Motivation

Making Tex and Text robust against not created directories is required to use them in a setting where there is no Scene to set everything up (e.g., when writing tests for them outside of a scene, see #476).

Testing Status

Added doctests for testing initialization of Tex and Text.

Acknowledgement

@behackl behackl added pr:easy review There is nothing particular (i.e, it's about a general/small thing) to know for review! enhancement Additions and improvements in general labels Sep 29, 2020
Co-authored-by: Naveen M K <naveen@syrusdark.website>
@eulertour eulertour mentioned this pull request Oct 1, 2020
13 tasks
@behackl behackl added this to the Release v0.1 milestone Oct 1, 2020
@behackl
Copy link
Member Author

behackl commented Oct 7, 2020

Okay, I've added some very simple __repr__ methods to both Text and SingleStringMathTex (from which all other TeX classes inherit -- weird, but maybe a story for another day) and I've added a bunch of more doctests so that creating text and tex is always tested.

Review at will!

Co-authored-by: Leo Torres <dleonardotn@gmail.com>
@huguesdevimeux
Copy link
Member

I know you're going to hate me for that but ...

Do you think you could write a test for that ?

@behackl
Copy link
Member Author

behackl commented Oct 8, 2020

I know you're going to hate me for that but ...

Do you think you could write a test for that ?

It is, in fact, already tested with the doctests I have added. :-)

@huguesdevimeux
Copy link
Member

I know you're going to hate me for that but ...
Do you think you could write a test for that ?

It is, in fact, already tested with the doctests I have added. :-)

Could you clarify this ? I don't understand

@behackl
Copy link
Member Author

behackl commented Oct 9, 2020

I know you're going to hate me for that but ...
Do you think you could write a test for that ?

It is, in fact, already tested with the doctests I have added. :-)

Could you clarify this ? I don't understand

@huguesdevimeux The creation of Text etc is tested in https://github.com/ManimCommunity/manim/pull/492/files#diff-cf9247b89e1b4debba20823314a969f8R86 -- without an existing text_dir etc, these tests would fail.

If you would like to have a more explicit test, let me know what precisely you would like to have tested. I'll probably have to adapt to the PR that enabled Pango anyways.

@behackl
Copy link
Member Author

behackl commented Oct 12, 2020

There was a merge conflict in the TextWithBackground class (the inheritance changed from Text to CairoText) -- but I still argue that it should be removed. It is not functional, and if someone wants to add it at a later point, then they are welcome to do so.

I don't find the current co-existance of PangoText and CairoText with Text still defaulting to CairoText a particularly good idea, and I think we should have switched the default and logged information that in case of problems one should fall back to the old implementation, CairoText -- but this is probably a discussion for a different issue / PR.

Anyhow, the reason I bring this up is the representation string: currently, CairoText('asdf') and Text('asdf') both have Text('asdf') as their representation string (and I think this is okay, as Text is just a wrapper with the logged warning). In 6e50d94 I've added a __repr__ to PangoText that lets PangoText('asdf') also have Text('asdf') as its representation string, to keep this sort of "symmetry".

@huguesdevimeux
Copy link
Member

If you would like to have a more explicit test, let me know what precisely you would like to have tested. I'll probably have to adapt to the PR that enabled Pango anyways.

I hear that, but I do think that at some point we will need a test for the whole directory generation.
So, it's fine here, a test will be implemented in the future

@behackl
Copy link
Member Author

behackl commented Oct 12, 2020

I would appreciate if this could get a second approval so I can stop resolving merge conflicts over and over. 😅

Copy link
Member

@huguesdevimeux huguesdevimeux left a comment

Choose a reason for hiding this comment

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

SGTM

Copy link
Contributor

@nilaybhatia nilaybhatia left a comment

Choose a reason for hiding this comment

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

LGTM!

@behackl
Copy link
Member Author

behackl commented Oct 14, 2020

Thank you!

@behackl behackl merged commit 2304505 into ManimCommunity:master Oct 14, 2020
@behackl behackl deleted the tex-text-create-dir branch October 14, 2020 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Additions and improvements in general pr:easy review There is nothing particular (i.e, it's about a general/small thing) to know for review!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants