justinfx / MayaSublime

Send selected Python and MEL code snippets from SublimeText to Maya via commandPort
MIT License
149 stars 38 forks source link

Add "no_collisions" setting to toggle namespacing Python code #25

Closed darkvertex closed 8 years ago

darkvertex commented 8 years ago

Hey,

In my opinion while it's good to namespace code by default, it can cause confusion as it's not really mentioned to the user.

I actually had an issue where I was defining a class in Sublime and using MayaSublime to send it to Maya, then trying it out in the Script Editor... except that it wasn't in the main environment, so weirdness ensued.

My proposed change leaves the current behaviour as default but allows the user to disable the namespacing at their own peril. Let me know what you think or if you'd like me to adjust anything.

justinfx commented 8 years ago

Thanks for the contribution! I have one comment and one question...

Since the variables to that command template are starting to grow, what if we switch it to named params?

        try:
            if {ns}:
                namespace['__file__'] = {cmd!r}
                {xtype}({cmd!r}, namespace, namespace)
            else:
                {xtype}({cmd!r})
        except:
            traceback.print_exc() 
    ...
    opts = dict(xtype=execType, cmd=mCmd, fp=file_path, ns=no_collide)
    mCmd = self.PY_CMD_TEMPLATE.format(**opts)

Something like that, to make it more readable in the command without remembering which positional arg is which.

The question I had was whether you think it might be beneficial to make a second command available, which can do this send without namespacing, as opposed to only making it a preference? Is there ever a use case where you might want either one mapped to your preferred hotkeys? That is...maybe you want ctrl+enter to send it to maya with namespacing, and ctr+shift+enter to send it without, for snippets that you expect to be set into the main namespace? If we wanted to go that route, it would just need to be a refactor that creates two command functions which delegate to a 3rd function that actually does that full body of work, with specific extra options (namespacing or not). Thoughts?

darkvertex commented 8 years ago

Hi Justin,

I think switching to named args for the command template is a good idea. I'll make the adjustment.

As for providing a second option to run without namespacing, I can't think of a reason why anyone would want to selectively namespace at will. To me I see this as a sort of "advanced" setting for people who don't need their hand held while coding in the main environment.

darkvertex commented 8 years ago

Thanks for merging! :)

Forgive this dumb question but as I've not dealt much with PackageControl from a package dev point of view... how soon does it take for the new release tag to be noticed? I see that https://packagecontrol.io/packages/MayaSublime shows "MODIFIED 3 months ago" -- is the guy running like a daily cronjob to detect new versions?

justinfx commented 8 years ago

I'm actually not sure how quickly package control automatically reacts to updates. I was able to manually go to Upgrade for the mayasublime package. I assume if I had waited long enough, it would have been pushed down.

ross-g commented 8 years ago

FYI - coming to work this morning my MayaSublime package is reporting errors.

You have a rogue comma in the MayaSublime.sublime-settings file after the "no_collisions" setting.

justinfx commented 8 years ago

@ross-g, thanks for pointing that out. I have tagged a 2.3.1 patch release.

darkvertex commented 8 years ago

Damn. Sorry about that @ross-g.