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

Explicitly providing targets to util.publish() or pyblish_qml.show() excludes "default" target #345

Open
BigRoy opened this issue Jul 15, 2019 · 5 comments

Comments

@BigRoy
Copy link
Member

BigRoy commented Jul 15, 2019

Issue

In Pyblish whenever one registers a custom target it still includes the default target - as if it is always present.

import pyblish.api
import pyblish.util
pyblish.api.register_target("render")

pyblish.util.publish()
# Pyblish will now use targets: ["default", "render"]

This concept propagates correctly to pyblish_qml.show() when no targets are provided:

import pyblish.api
import pyblish_qml
pyblish.api.register_target("render")

pyblish_qml.show()
# Pyblish QML will now use targets: ["default", "render"]

However when providing targets explicitly to pyblish_qml.show() it will only include default when explicitly provided. This behavior does nicely match what Pyblish currently does when using pyblish.util.publish(), like:

pyblish.util.publish(targets=["render"])
# Pyblish will only use targets: ["render"]

pyblish_qml.show(targets=["render"])
# Pyblish QML will only use targets: ["render"]

Note that here "default" is not included in the targets


Discussion

The consusion rises when you query pyblish.api.registered_targets() , it never lists "default" even though it is included by default, yet not when you start to explicitly providing targets.

Somehow it left me confused for two hours where the behavior started to differ when I triggered QML with a target and it lacked the default plug-ins. I'm wondering whether we should be able to simplify the logic so it's the same in all those cases. Additionally the Documentation led me off the path too as it indicated by default plug-ins would target anything with *:

Targets work the same way as families, so a wildcard of * enables the plugin for all targets. Since all plugins are registered with * as targets, this workflow is backwards compatible with existing plugins that has not overwritten the targets attribute.

However the code indicates the default target is set only to targets = ["default"]


Reference:

@BigRoy
Copy link
Member Author

BigRoy commented Jul 15, 2019

With the above being said, I believe there might be a bug where it's not explicit for Pyblish-base looking at the code here since it doesn't exclude the ones that are not explicitly passed along.

E.g.

import pyblish.api
import pyblish.util

pyblish.api.register_target("local")
pyblish.util.collect(targets=["default", "render"])
# I believe pyblish runs with targets ["default", "render", "test"]

However for Pyblish QML the registered_targets are excluded whenever targets is passed to pyblish_qml.show().

Similarly, it actually removes them from registered targets.

import pyblish.api
import pyblish.util

pyblish.api.register_target("render")
pyblish.api.register_target("test")
pyblish.util.collect(targets=["default", "render"])

print pyblish.api.registered_targets()
# ['test']
# Note that "render" is now removed from the registered targets.

I believe this is a bug and pyblish.util should use a context manager to manage the targets (when explicitly passed along) during the processing so that after the call the registered targets are not messed with.

@tokejepsen
Copy link
Member

Defo bug. PR is welcomed:-)

@mottosso
Copy link
Member

mottosso commented Mar 9, 2020

Had a look at this, which also involves pyblish/pyblish-qml#362, #363 and #345.

There are two points being made, one of which is a bug the other is misunderstood.

  1. The bug is this, where the API is used to globally register targets from within an internal function. That shoudn't happen and is a bug with side-effects.
  2. The misunderstanding is what register_target and registered_targets does, both of which works as intended.
    1. register_target adds another target, deregister_target removes a target, this works as intended
    2. registered_targets shows you the registered targets, and default is not one of them, it is never registered. It might be a good idea to add a api.all_targets() or api.targets() if visualising all including default is helpful.
    3. targets=["a", "b"] is an explicit list of targets being assigned; it isn't relative what already exists, and should override and take complete control which it does. If you want default you should and need to explicitly include it.

With that in mind, fix the bug but leave the behavior of register_target and registered_targets. They are innocent.

@buddly27
Copy link
Contributor

buddly27 commented Mar 9, 2020

I think the confusion comes from the fact that "default" is sometimes treated as a normal target and sometimes as a special target.

It doesn't need to be explicitly registered when adding an extra target:

pyblish.api.register_target("render")
pyblish.util.publish() # uses "default" and "render"

...But it must be passed when using explicit targets:

pyblish.util.publish(targets=["render"]) # uses "render" only
pyblish.util.publish(targets=["default", "render"]) # uses "default" and "render"

Wouldn't it make the logic more consistent if "default" were not a special target and were simply registered by default when pyblish is imported? User could easily deregister it if necessary, or explicitly change the targets within pyblish.util functions. What do you think?

The bug is this, where the API is used to globally register targets from within an internal function. That shoudn't happen and is a bug with side-effects

Hopefully the bug should be fixed by #364, please let me know if it behaves as expected.

@mottosso
Copy link
Member

With 1.8.5 released, is this still an issue?

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

No branches or pull requests

4 participants