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

Extra module for utility functions #62

Merged
merged 5 commits into from
Apr 18, 2018

Conversation

swistakm
Copy link
Member

Refers to #33.

This creates a new extension named imgui.extra that contains all additional utility functions that are not part of core C++ API. It also leaves aliases with deprecation warnings for old function names in imgui.core extension that will re removed in 1.0.0 version.

This unfortunately increases the project complexity a bit but it is possible that net complexity will decrease over time as we start to add new helpers (maybe even custom python-specific widgets!) and after we remove the deprecated aliases.

@pconerly would you like take a look and review it?

@swistakm
Copy link
Member Author

swistakm commented Apr 16, 2018

I have just realized that this way of doing this (another Cython extension) is just a dead end. Both extensions will be statically linked against ImGui and this will break the whole integration of C++ assert statements with Python exceptions. Also this may break in other unexpected ways.

Right now I so see only following solutions to this isse:

  • imgui.extra module will be pure Python submodule that normally imports imgui.core module and calls its functions. This is the simplest and cleanest. We may lose the potential performance benefit of Cython cdefs but make whole packaging simpler. Still, it is possible that performance impact will be negligible.
  • We can leave all extra utilities in imgui.core module and "shadow" them using simple prefix (e.g. _, _extra_, etc.) and create pure Python module imgui.extra that would import those prefixed names and rename them. This will definitely create some issues for Sphinx docs but maybe we'll be able to find some workarounds.

@coveralls
Copy link

coveralls commented Apr 16, 2018

Coverage Status

Coverage increased (+1.0%) to 42.488% when pulling 3df17b5 on feature/extra-module-for-utility-functions into 6312e23 on master.

core.vertex_buffer_vertex_uv_offset = _core_to_extra_deprecated(extra.vertex_buffer_vertex_uv_offset) # noqa
core.vertex_buffer_vertex_col_offset = _core_to_extra_deprecated(extra.vertex_buffer_vertex_col_offset) # noqa
core.vertex_buffer_vertex_size = _core_to_extra_deprecated(extra.vertex_buffer_vertex_size) # noqa
core.index_buffer_index_size = _core_to_extra_deprecated(extra.index_buffer_index_size) # noqa
Copy link
Contributor

Choose a reason for hiding this comment

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

Random question, what does the # noqa comment mean?

Copy link
Member Author

Choose a reason for hiding this comment

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

This common mark for linters like pep8 (and many IDEs) to exclude current line from style checking. This line is longer than 79 columns but splitting into multiple lines would IMHO reduce readability.

Such things are already my habit. Now I see that project doesn't have linting in build pipeline. This is oversight. I will add another stage to Travis CI config so all # noqa will have a bit more sense.

vertex_buffer_vertex_uv_offset = core._py_vertex_buffer_vertex_uv_offset
vertex_buffer_vertex_col_offset = core._py_vertex_buffer_vertex_col_offset
vertex_buffer_vertex_size = core._py_vertex_buffer_vertex_size
index_buffer_index_size = core._py_index_buffer_index_size
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this, using the ._py_ prefix for the actual code, but exposing the function at the top level and without the prefix. 👍

but are useful in Python application.

"""
from . import core
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this just be import core ?

Copy link
Member Author

Choose a reason for hiding this comment

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

import core will fail on Python 3 as it no longer supports implicit relative imports.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, TIL!

setup.py Outdated
@@ -81,7 +81,21 @@ def get_version(version_tuple):
general_macros = []


extension_sources = ["imgui/core" + ('.pyx' if USE_CYTHON else '.cpp')]
def extension_sources(path):
sources = [path + ('.pyx' if USE_CYTHON else '.cpp')]
Copy link
Contributor

Choose a reason for hiding this comment

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

Super nitpicky, but it's a little safer to do string interpolation. "{0}{1}".format(path, '.pyx' if USE_CYTHON else '.cpp'

Copy link
Member Author

@swistakm swistakm Apr 17, 2018

Choose a reason for hiding this comment

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

Good point, it will look better.

@pconerly
Copy link
Contributor

LGTM, just a couple of small things. The build is failing, but it's not entirely clear why? Pythonhosted was giving 404s? You might give it a retry.

@swistakm
Copy link
Member Author

These pip failures are strange indeed. I have restarted Travis build immediately but apparently forgot about Appveyor.

@swistakm
Copy link
Member Author

Apparently this was just a transient issue.

@pconerly
Copy link
Contributor

👍

@swistakm swistakm merged commit 0d3b9b4 into master Apr 18, 2018
@swistakm
Copy link
Member Author

Released as 0.1.0

@swistakm swistakm deleted the feature/extra-module-for-utility-functions branch May 30, 2018 13:46
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.

None yet

3 participants