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

Use correct source_path in example #1433

Merged
merged 6 commits into from
Dec 9, 2020

Conversation

aaronayres35
Copy link
Contributor

fixes #1432

This PR changes the search path the be the correct path to the directory that contains the image folder containing the images of interest.

Copy link
Contributor

@kitchoi kitchoi left a comment

Choose a reason for hiding this comment

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

May I also suggest adding a simple test to prevent this missing file link from happening again?
Something like this.

import os
import runpy
import unittest

#: Filename of the demo script
FILENAME = "Image_editor_demo.py"

#: Path of the demo script
DEMO_PATH = os.path.join(os.path.dirname(__file__), "..", FILENAME)


class TestImageEditorDemo(unittest.TestCase):

    def test_image_path_exists(self):
        search_path, = runpy.run_path(DEMO_PATH)["search_path"]
        self.assertTrue(os.path.exists(search_path))


from traitsui.api \
import ImageEditor
import View, VGroup, Item, ImageEditor

from pyface.image_resource \
import ImageResource

# Constants:

# Necessary because of the dynamic way in which the demos are loaded:
Copy link
Contributor

Choose a reason for hiding this comment

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

If I run the script from the command line, even just search_path = [] would work, but that's using some default magic (with inspection on where the code is running from etc.). I believe this is the magic:
https://github.com/enthought/traits/blob/a0d0a70331ec202eb33b6439570175c869fe353c/traits/trait_base.py#L256-L305

That would not work when this example is run from within the demo application. join(dirname(__file__)) remove the assumption and dependency on the magic: It is more explicit, which I think is a good thing to do anyway. Now the comment makes it look worse than this actually is.

What do you think about rewording the comment to something along the line of # The images folder is in the same folder as this file?

traitsui/examples/demo/Extras/Image_editor_demo.py Outdated Show resolved Hide resolved
Copy link
Contributor

@kitchoi kitchoi left a comment

Choose a reason for hiding this comment

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

Still LGTM. Thank you!

@aaronayres35 aaronayres35 merged commit 464b202 into master Dec 9, 2020
@aaronayres35 aaronayres35 deleted the fix/1432-incorrect-search-path branch December 9, 2020 14:43
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.

Incorrect search_path in example
2 participants