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

test: Fix docs test, used wrong namespace #4090

Merged
merged 1 commit into from
Jan 2, 2024

Conversation

lgritz
Copy link
Collaborator

@lgritz lgritz commented Dec 23, 2023

We did import OpenImageIO as oiio then instead of using oiio, we used OpenImageIO.

This was failing sometimes. Frankly, I'm not sure why it ever worked.
Maybe it works on some versions of Python but not others?
I dunno. But this fixes it everywhere and is clearly correct.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
@@ -263,10 +263,10 @@ def example_make_texture():
config["maketx:filtername"] = "lanczos3"
config["maketx:opaque_detect"] = 1

ok = ImageBufAlgo.make_texture (OpenImageIO.MakeTxTexture,
ok = ImageBufAlgo.make_texture (oiio.MakeTxTexture,

Choose a reason for hiding this comment

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

For consistency with other examples, should this use MakeTxTexture instead of oiio.MakeTxTexture? All the other examples use stuff imported from from OpenImageIO import *.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure.

I'm not very immersed in Python culture. Remembering that this is not just a test, but its snippets will be directly used in the documentation as examples for the API calls, what's customary when documenting a library and providing code examples? Is it typical to omit any namespacing at all? Or to use a namespace in the examples? To always use the full namespace?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Numpy example: https://numpy.org/doc/1.26/user/absolute_beginners.html#how-to-import-numpy

They show how to import, use a short namespace alias, and then they use the namespace everywhere in the rest of the examples. I think this is wise, as for beginners it more easily distinguishes between the Numpy API and things that might be features of Python itself.

I think we should do the same. So I want to keep the use of the oiio namespace here. And let's make a mental note that, separately, we should find anyplace in the examples that does a full from OpenImageIO import * and change that to use a namespace to be more clear.

Copy link
Member

Choose a reason for hiding this comment

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

If possible, it's recommended to avoid using start imports. My initial comment was to keep the consistency, but it would be a good idea, like you suggest, to instead use import OpenImageIO or import OpenImageIO as oiio.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. In general, in both C++ and Python, I think it's better style to always use the namespacing explicitly, for clarity. At least as a default, and take exceptions one by one in cases where removing the namespacing clearly the code more readable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure where the * import came from. Git blame says me, of course, but it's contrary to my usual style, so I think I just wasn't considering it very carefully at that moment.

@lgritz
Copy link
Collaborator Author

lgritz commented Dec 27, 2023

Look ok other than that quibble?

@lgritz lgritz merged commit 48362b2 into AcademySoftwareFoundation:master Jan 2, 2024
48 checks passed
@lgritz lgritz deleted the lg-doctest branch January 2, 2024 06:22
lgritz added a commit to lgritz/OpenImageIO that referenced this pull request Jan 2, 2024
…4090)

We did `import OpenImageIO as oiio` then instead of using `oiio`, we
used `OpenImageIO`.

This was failing sometimes. Frankly, I'm not sure why it ever worked.
Maybe it works on some versions of Python but not others?
I dunno. But this fixes it everywhere and is clearly correct.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
1div0 pushed a commit to 1div0/OpenImageIO that referenced this pull request Feb 24, 2024
…4090)

We did `import OpenImageIO as oiio` then instead of using `oiio`, we
used `OpenImageIO`.

This was failing sometimes. Frankly, I'm not sure why it ever worked.
Maybe it works on some versions of Python but not others?
I dunno. But this fixes it everywhere and is clearly correct.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
Signed-off-by: Peter Kovář <peter.kovar@reflexion.tv>
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.

2 participants