Remove code duplication in tutor.py#1034
Conversation
| def main(root_dir): | ||
| # Create a tutor and display the tutorial: | ||
| path, name = os.path.splitext(root_dir) | ||
| demo(dir_name=root_dir, title='Traits Demos') |
There was a problem hiding this comment.
A couple of things I noticed while testing the runner:
- Description of
doc_examplesfolder shows<img src="traits_ui_demo.jpg">, which is programmed to be default description if there’s no__init__.pyfile. - Description of
examplesfolder shows a thrown error:
FileNotFoundError: [Errno 2] No such file or directory: 'doc_examples/examples/__init__.py'
Do we want to add these __init__.py files with descriptions, should this be addressed in traitsui code or is it okay to be like this for now?
There was a problem hiding this comment.
Include the __init__.py and add a brief explanation of what is in the directory.
There was a problem hiding this comment.
Added both __init__.py files but the one indoc_examples isn't shown right now. To show it, use_files=True is needed, but that also picks up doc_examples.rst and with the new tree structure enthought/traitsui#792 bug is exposed. So I think it's better to show a reference to traits_ui_demo.jpg until the bug is fixed.
The explanations I added are very minimal. Didn't want to add the actual contents because that would require manual upkeeping, so I hope this is enough.
There was a problem hiding this comment.
@corranwebster Why do we want an __init__.py file in doc_examples? That directory is not a Python package. Is there some part of the machinery in tutor.py that needs this?
There was a problem hiding this comment.
tutor.py machinery looks for __init__.py of directories in order to extract their descriptions. It is optional for the root directory, with default description set to <img src="traits_ui_demo.jpg">, but all other subdirectories are expected to have __init__.py or the code raises a non-fatal error.
This would be the only need for __init__.py as far as I know.
There was a problem hiding this comment.
Got it. Thanks.
That's not nice, but it is what it is. There's definitely scope for rewriting and improving tutor.py one day. But not today.
Codecov Report
@@ Coverage Diff @@
## master #1034 +/- ##
==========================================
+ Coverage 73.05% 76.37% +3.32%
==========================================
Files 51 54 +3
Lines 6514 6600 +86
Branches 1309 1319 +10
==========================================
+ Hits 4759 5041 +282
+ Misses 1363 1211 -152
+ Partials 392 348 -44
Continue to review full report at Codecov.
|
kitchoi
left a comment
There was a problem hiding this comment.
LGTM!
I ran the code following the documentation instruction and it works fine.
(I did need to manually install configobj which is not a dependency in traits CI environment).
It is a dependency in TraitsUI for demo reasons only (as far as I can tell). Should it be added as a dependency to Traits as well? |
|
Yes, let's add it to the development dependencies in While we're there, we could also add |
Closes #505
The framework is already implemented in
traitsui.extras.demoso there is no need for code duplication here. The framework code is removed and insteadtutorial.pymakes use of demo code intraitsui.extras.demo.Checklist
[ ] Tests[ ] Update API reference (docs/source/traits_api_reference)docs/source/traits_user_manual)[ ] Update type annotation hints intraits-stubs