cmcpasserby / MayaCharm

Maya integration for PyCharm.
MIT License
177 stars 44 forks source link

>= 2019.3 Support #43

Closed cmcpasserby closed 3 years ago

cmcpasserby commented 4 years ago

So 2019.3 has brought lots of issues with how pydev works

Update: 2021-02-15

some progress has finally been made, and i got a prerelease version for testing ~https://github.com/cmcpasserby/MayaCharm/releases/tag/prerelease/vv3.2.1-test.3~

Update: 2021-03-17

Issue resolved, and working versions are available in the plugin marketplace and on the releases page.

defTechAndrew commented 4 years ago

Thanks for spending your weekend on this Chris.

cmcpasserby commented 4 years ago

yeah hopefully will get the rest sorted out, it is something to do with the pydevd that is shipped with it. Including my own, or telling it to use the one from 2019.2 makes it work again. but distributing my own pydevd would be a pain since it does have some binary dependencies and is not pure python

MTCoster commented 4 years ago

Anything I (or anyone else here) can do to help get this update out the door?

PadraigOCuinn commented 4 years ago

Keep up the good work Chris send me a message if needed.

zZnghialamZz commented 4 years ago

Hi Chris,

Do you have any updated information about this plugin support for 2019.3 ?

cmcpasserby commented 4 years ago

Sorry its been a while since looking at this. So have not been able to make no progress in getting the Debugger in newer versions of PyCharm to work with Maya.

Question is do people feel its worth releasing A update to support versions greater than 2019.2 if those versions do not support debugging?

If i do this it would mean it would not be able to attach its debugger, but it still would be able to grab the Maya log, and still would be able to execute code in Maya via the command port. The other thing i would be able to do, is ensure PyCharm detects the proper python version of mayapy as well.

joe-sunblink commented 4 years ago

Sorry its been a while since looking at this. So have not been able to make no progress in getting the Debugger in newer versions of PyCharm to work with Maya.

Question is do people feel its worth releasing A update to support versions greater than 2019.2 if those versions do not support debugging?

If i do this it would mean it would not be able to attach its debugger, but it still would be able to grab the Maya log, and still would be able to execute code in Maya via the command port. The other thing i would be able to do, is ensure PyCharm detects the proper python version of mayapy as well.

It'd be worth it for me. I don't often use the debugging, but it would be nice to be able to update my PyCharm and still use the other MayaCharm features. Thanks for your work on this.

defTechAndrew commented 4 years ago

I'm stuck in .2 land until "attach to process" works for Maya. Do people have a way for debugging Maya without the use of MayaCharm?

chadlichty commented 4 years ago

I would only use the newer version if I can use the debugger.

On Thu, Apr 2, 2020 at 6:56 AM Chris Cunningham notifications@github.com wrote:

Sorry its been a while since looking at this. So have not been able to make no progress in getting the Debugger in newer versions of PyCharm to work with Maya.

Question is do people feel its worth releasing A update to support versions greater than 2019.2 if those versions do not support debugging?

If i do this it would mean it would not be able to attach its debugger, but it still would be able to grab the Maya log, and still would be able to execute code in Maya via the command port. The other thing i would be able to do, is ensure PyCharm detects the proper python version of mayapy as well.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cmcpasserby/MayaCharm/issues/43#issuecomment-607862182, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADM3I3BRQBEYIIO5C7JLRWLRKSKQHANCNFSM4JYA5BLA .

cmcpasserby commented 4 years ago

@defTechAndrew It looks like a lot about how pydevd works changed in 2019.3. looks like both the local debugger which i based the mayacharm attach from, and the remote one in 2019.3 do not work with maya. When ever i attach it only partially works but it makes Maya unstable and never hits breakpoints.

defTechAndrew commented 4 years ago

Oof, maybe it's time to switch over to VS.

cmcpasserby commented 4 years ago

yeah when i have time want to dig into it more, and might try some plugin builds against 2020.1 EAP to see if things have improved there. I am not exactly sure what changed with it either. like for example if i run something in mayapy directly it can still attach a debugger just fine to it. But when trying to attach to a running Maya instance is where i hit problems.

j0yu commented 4 years ago

I'm stuck in .2 land until "attach to process" works for Maya. Do people have a way for debugging Maya without the use of MayaCharm?

It's a bit tricky but I'll try my best to describe it. Works for other software too like Nuke/Katana/etc.

  1. In Settings/Preferences | Build, Execution, Deployment | Python Debugger
    • Set the Attach to Process name filter to maya.bin
    • Tick Attach to subprocess automatically while debugging
  2. Copy down your full, absolute path to

    <PyCharm install root>/plugins/python-ce/helpers/pydev

    which we'll call PYDEV_PATH from now

  3. In Maya script editor, run these lines
    import sys
    sys.path.prepend("PYDEV_PATH")
    import pydevd_pycharm
  4. Then paste in this line. You need to come back later on in a hurry to change and run it!
    pydevd_pycharm.settrace(host='localhost', stderrToServer=True, stdoutToServer=True, port=NUMBER_IN_CONSOLE, suspend=False)
  5. Go back to PyCharm, then Run | Attach To Process but read the next steps before clicking your Maya process!
  6. Once you click on your Maya process, quickly go into the debug console to check the output
  7. You may have to scroll right quite a bit, but you're looking for the port number PyCharm has used that's unique to this instance of attaching to Maya
  8. Go into Maya, replace NUMBER_IN_CONSOLE with that port number, run that line
  9. If you did it in time, PyCharm will have successfully attached to Maya. If you failed, you can just try again from Run | Attach To Process
YKdvd commented 4 years ago

If you can do an update of the plugin that still allows debugging in 2019.2, and disables it but doesn't claim incompatibility with 2019.3+, that would probably be useful.

Was MayaCharm able to do debugging with Maya on MacOS or Linux before this problem? Is it Windows-only breakage?

You said pydev is not pure Python - does it include C extensions, or libraries that use Microsoft C Runtime, and would PyCharm be providing anything like this that is specific for Python 2.7? The Python 2.7 inside Maya on Windows has been recompiled by Autodesk with a newer compiler than the ancient Visual Studio setup that the stock Python 2.7 distribution used. In theory, Python packages for use with Maya that have C extensions should be built with the same VS setup as Maya's Python, otherwise they use different versions of the C runtime, which can be a problem. Any chance this is now causing a problem?

cmcpasserby commented 4 years ago

i only have older Maya versions to test with, but i could test on macOS as well. but yes it looks like i can upload multiple packages, limited to versions. so on the weekend i should be able to add a new package for 2019.3 that does not have debugger support, but has the rest of the features working for 2019.3.

PadraigOCuinn commented 4 years ago

Hi Chris For now I am ok on the previous version of pycharm and mayacharm. I use the debugger quiet a lot so it's a must for me. Hit me up if you need any help with anything!Padraig O CuinnTechnical DirectorFilm and Games Division

cmcpasserby commented 4 years ago

So which versions of Maya do the various people in this issue have access to? I have only been able to test on a limited set of older versions of it, so would be curious what this issue looks like if i gave someone a copy of the plugin to test on a modern version.

I am starting to break off a branch for maintaining the old version of the plugin and support for <= 2019.2 versions that included debugger support. Then i will be pushing the 2019.3 stuff into main, even if that means i can not support the debugger in it yet.

YKdvd commented 4 years ago

Our versions of interest are 2016SP6 and 2020 with Windows 10 - I also have access to 2018 and 2019, although I don't know what service pack is installed for those offhand. I also have access to Maya 2020 on a Mac, although we don't use MacOS in production.

I haven't been using MayaCharm in production as much lately because of my Issue#44, but I could certainly fire up and test a version of the plugin for standalone attaching and debugging.

YKdvd commented 4 years ago

Do you know for sure that debugging breaks in 2019.3+ on platforms other than Windows? I assume if I try and install a 3.11+ .jar from disk in PyCharm 2019.3+ it won't work because of your recent versioning restriction. If I were to install a 3.10 MayaCharm .jar file from disk on MacOS though, I should be able to see if that is broken?

cmcpasserby commented 4 years ago

@YKdvd if you want to play around, i can make you a jar file that targets 2019.3 and greater and still has the debugger enabled. My tests have been on 2016 and Windows so it would be good to know if the issue is only Windows and or older versions of Maya, or effects other OS's. Will get a chance to make that up tomorrow.

YKdvd commented 4 years ago

If you don't know already, I wouldn't mind finding out if debugging is broken on MacOS as well as Windows. We also have a Linux machine with a GUI lying around, although I don't know if it is still in a condition to run Maya.

What's the basic theory of MayaCharm/PyDev debugging on Windows? Does it inject Python 2.7-specific DLLs or .pyd libraries into the Maya process, where C runtime version issues might crop up?

Were you able to reach out to the JetBrain forums or the PyDev maintainers?

cmcpasserby commented 4 years ago

@YKdvd I have not reached out yet, but yes it does look like it is injecting some dll's, or so's and dynlibs on the Linux and mac side of things. On the windows side of things you can see the entry point to this process at. It looks all the windows ones were compiled with VS 2014 for both 2019.3 and versions before it. But the code is very different between the 2.

<= 2019.2 versions %LOCALAPPDATA%\JetBrains\Toolbox\apps\PyCharm-P\<channel>\<version>\helpers\pydev\pydevd_attach_to_process/attach_pydevd.py

>= 2019.3 versions %LOCALAPPDATA%\JetBrains\Toolbox\apps\PyCharm-P\<channel>\<version>\plugins\python\helpers\pydev\pydevd_attach_to_process/attach_pydevd.py

Most of the code you can see in those locations can be found here as well. https://github.com/fabioz/PyDev.Debugger/tree/master/pydevd_attach_to_process

But it does seem JetBrains did make some of there own modifications to it.

cmcpasserby commented 4 years ago

@YKdvd and anyone else interested. Here is a release that is installable on 2019.3, and can be used to test what versions and OS's the debugger does not work on. https://github.com/cmcpasserby/MayaCharm/releases/tag/v.3.2.0-test.1

YKdvd commented 4 years ago

I downloaded the test 3.2.0 plugin and installed it - PyCharm 2019.3.4 on MacOS 10.14.6. I double-clicked Maya 2020 and set things up. MayaCharm Active SDK is: /Applications/Autodesk/maya2020/Maya.app/Contents/bin/mayapy | 4435

The project interpreter is set to that mayapy 2020 as well, and I've run the code in Maya that opens up that port 4435. I can successfully do Run->Execute Document in Maya. But when I choose Run->Attach To Process..., the "Local Host" processes says "No processes to attach to". I tried launching Maya from a terminal prompt with the same result.

cmcpasserby commented 4 years ago

k, i will have to get a proper mac dev environment setup to figure that out. In the mean time does running readlink /proc/<maya pid>/exe or which ps -o `comm= -p <maya pid>` where the is the PID of a running Maya instance give you its executable path?

YKdvd commented 4 years ago

I don't think MacOS has a procfs, and your "which" command doesn't seem to be valid syntax on MacOS. But given a Maya PID of 98105, here's some ps output for it.

ps -p 98105 -f
  UID   PID  PPID   C STIME   TTY           TIME CMD
  501 98105     1   0 12:02pm ??         0:23.14 /Applications/Autodesk/maya2020/Maya.app/Contents/MacOS/Maya

Are you generating and scanning a list of processes using something like ps?

cmcpasserby commented 4 years ago

kind of, the Intellij platform has a method for getting info about processes to attach to. but it lacks some of the information i need. So i had to build some methods that take a PID and get me the executable path with it. So on windows i am using wmic for that, on Linux the procfs, then on mac i will need to find a way. After work tonight i will have more time to look at that, and get macOS setup for testing this.

PadraigOCuinn commented 4 years ago
2020.1 is making the plugin incompatible haha.    Padraig O CuinnTechnical AnimatorFilm and Games Division  From: Chris CunninghamSent: Monday 6 April 2020 16:56To: cmcpasserby/MayaCharmCc: Padraig O Cuinn; CommentSubject: Re: [cmcpasserby/MayaCharm] >= 2019.3 Support (#43) kind of, the Intellij platform has a method for getting info about processes to attach to. but it lacks some of the information i need. So i had to build some methods that take a PID and get me the executable path with it. So on windows i am using wmic for that, on Linux the procfs, then on mac i will need to find a way. After work tonight i will have more time to look at that, and get macOS setup for testing this.—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or unsubscribe. 
chadlichty commented 4 years ago

@cmcpasserby I have access to just about every version of Maya 2013 -2019 and will have 2020. Let me know if you anything tested.

cmcpasserby commented 4 years ago

@chadlichty will take note of that, hoping to try a few more things out on Saturday and see if progress can be made

chadlichty commented 4 years ago

Can I get you a coffee or lunch for your efforts?

mathbou commented 3 years ago

Any news about a 2020.* support ?

guitarjorge24 commented 3 years ago

Are there any plans to upgrade the plugin to PyCharm 2020.3? or any of the 2020 versions? I see the last time the developer posted here was 10 months ago...

cmcpasserby commented 3 years ago

Maybe someday but currently i very much lack the time to fix it, nor do i want to spend money to get what i would need to do any serious work on it again.

guitarjorge24 commented 3 years ago

I see, I'm currently considering MayaCharm + PyCharm for a job I'm applying to. Would probably know around late March if I get the job, but if I do, I'd willing to donate to this project. Hopefully others would want to donate too, so if you are able to do it in the near future, maybe setting up some kind of kickstarter or donation page could take care of the monetary expenses to fix it, and compensate you for your time as well.

chadlichty commented 3 years ago

Yes, I would contribute. Also, I wonder if Chris could utilize our fellow programmers to help with the update. I would gladly work on the update. I'm just not sure where to start.

On Wed, Feb 3, 2021 at 10:06 AM Jorge Luque notifications@github.com wrote:

I see, I'm currently considering MayaCharm + PyCharm for a job I'm applying to. Would probably know around late March if I get the job, but if I do, I'd willing to donate to this project. Hopefully others would want to donate too, so if you are able to do it in the near future, maybe setting up some kind of kickstarter or donation page could take care of the monetary expenses to fix it, and compensate you for your time as well.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cmcpasserby/MayaCharm/issues/43#issuecomment-772709281, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADM3I3HAW6ODUELQ6U54QR3S5GGCTANCNFSM4JYA5BLA .

YKdvd commented 3 years ago

Telling PyCharm that to look for the string "maya" in processes, I can "Attach to Process..." to a running Maya on Windows, and the Pycharm debugger Console shows the output of "print()" commands done in the Maya Script Editor window, and the PyCharm debugger says it is connected. So the basic attachment works, it is just that breakpoints don't?

BTW, here's a JetBrains issue that Chris posted to: https://youtrack.jetbrains.com/issue/PY-44778 and another one with the actual breakpoint issue: https://youtrack.jetbrains.com/issue/PY-43545 Doesn't seem like JetBrains is interested in helping figure this out.

cmcpasserby commented 3 years ago

@YKdvd From what i can tell, the way code is injected to do the 2nd half of the attach is bugged in the pydevd version that 2019.3 and above use. so it will say it attaches, and will be partially connected since you can see maya log output in the debugger window. But breakpoints do not get hit. During my own debugging i have managed to get things to connect properly, but think its a good bit of work to get from that to making that reliable again.

JetBrains i would say is only giving limited to little support since its a hard problem to reproduce unless you already own a expensive product to test against.

cmcpasserby commented 3 years ago

Not production ready yet, but I have had some success getting things working again. So here is a pre release for people to test and give feedback on. Its built against PyCharm 2020.3 and requires that version or greater to install and run. ~https://github.com/cmcpasserby/MayaCharm/releases/tag/prerelease/v3.2.1-test.1~ ~https://github.com/cmcpasserby/MayaCharm/releases/tag/prerelease/vv3.2.1-test.3~

MartinPolygonflow commented 3 years ago

I've tested this now and I can't get the debugging to work. Unsure if problem is on my end or not. Maya 2020.2 - PyCharm 2020.3 - MayaCharm pre-release. I installed your pre-release by copying the MayaCharm folder to the PyCharm plugins folder.

Installation appears to have gone thru fine. MayaCharm pops up in project settings/plugins and under run configs. Connection can be made to Maya and I am able to Attach to the Maya process. However no debug functionality seems to be there. I set a bunch of breakpoints in the init of a class, and then I runt a test-script which creates an object of said class.

Breakpoints are ignored and the debug-"ladybug" -icon is greyed out - including every debug action under Run > Debugging action.

Also: output from Maya is not redirected back to PyCharm. MayaLog remains empty: but script editor shows my object was created successfully. Python console shows no errors and neither does the debug tab.

I would like to say that I have missed MayaCharm tremendously. I've never managed to get the ordinary PyCharm debugger to work, always had problem with Maya not finding the pycharm-pydevd module so I've had to do print-debugging for like a year now. To be honest with you: It makes me feel like a retarded Junior Developer. I really hope I can get back to using this debugger. Thanks for all the hard work!

cmcpasserby commented 3 years ago

@MartinPolygonflow did not know you can just copy it to the folder, I normally install via Settings > Plugins windows then in the cog icon you can select Install Plugin from Disk.

So forgot to mention it in the above post but this version relies much more heavily on the commandPort then previous ones, and the logic to create the command port has changed slightly. In the Settings > MayaCharm menu, you should see a list of your mayapy's and port numbers. if yours is not there just add it. If you double click on the entry you are trying to target you should get a window like. edit_port_number so just make sure that code it provides in that window has been run in maya at least once. i generally just add it to the userSetup.py in Maya's scripts folder

if that does not do it, it could be how you are running you code, if you are just executing a file, sometimes that causes issues, but you you are importing your module then running a function from it, i find that is more reliable.

Also I have only tested any of this on Windows so far and a fairly old maya version.

MartinPolygonflow commented 3 years ago

I wasn't sure you can do that either but apparently PyCharm will look into subfolders in the Plugins folder, and there it found the MayaCharm jar file.

Anyway, I removed everything and installed it in the way you recommended (from disk). I noticed two things: 1) First there was a warning from PyCharm saying that the plugin is incompatible with this version of PyCharm (build something - don't remember the number). But after restarting the IDE the warning is gone and MayaCharm shows up. I was unable to reproduce this error. Again: I am running 2020.3 - the latest version. 2) There is no code view for the command port: no code view However I wrote down the command port connection logic from your image and added it to my userSetup.

Unfortunately I get precisely the same problem as before: All debugger options are greyed out. I can run my script via the MayaCharm runner but the whole code executes, ignoring breakpoints. And no console output is directed back to PyCharm.

image

This is my version of PyCharm: pycharm version

I'm wondering if perhaps I am doing something wrong on my end. What is your workflow for getting the debugger actions enabled? For me it's all just greyed out. Do these appear for you after you've attached to the Maya process?

(This is Nightshade from tech-artists.org btw!)

cmcpasserby commented 3 years ago

@MartinPolygonflow So looks like Maya is either not receiving the SetTrace call or it hitting a error trying to run it. On a successful connect in the debugger console, you will see successfully attached to maya underneath the really long line that runs the custom attach_pydev script.

The debugger run config is disabled at this time, since i could not find a way make the timing of connecting the debugger and then executing the script reliable. So the current workflow is run > attach to process... then you can either run the code from maya or use the run config to start your script. There is a other bug i need to sort out, where if you execute a file it will not hit break points. But if you just import a module and run a function on it it should still work.

The connection text not displaying properly I just fixed, was a simple mistake when built to a jar file it did not know how to path to the file correctly.

In the connection command you can see in debugging console, can you check the path of the script it is trying to run as well as the, and path after --pydevPath and ensure they are both point to valid locations

cmcpasserby commented 3 years ago

~https://github.com/cmcpasserby/MayaCharm/releases/tag/prerelease/vv3.2.1-test.3~ test version 3, fixes issues with executing files directly instead of importing

mathbou commented 3 years ago

This version looks promising. However, I get a strange behavior when using the __file__ variable, it returns CommandPort.py, shouldn't it be empty as in the previous versions? or return the launched document?

mathbou commented 3 years ago

Another thing I noticed during my tests: if the code fails or an exception is thrown, nothing is printed in the MayaLog nor in the ScriptEditor, it just crashes silently

cmcpasserby commented 3 years ago

will look into the __file__ thing not sure why that would have changed, might be due to me passing globals() from my code sent to the CommandPort into the execfile call that executes your script. had to do this to solve some problems with stuff in wrapped in if __name__ == "__main__": blocks not getting executed. Way more stuff needs to use the commandPort in this version than before, since injecting code directly into things is no longer reliable.

@mathbou thanks for the feedback, likely will not have time to look again till the weekend.

cmcpasserby commented 3 years ago

@mathbou still no time to do enough testing for a proper release, but this might fix the 2 issues you were talking about. ~https://github.com/cmcpasserby/MayaCharm/releases/tag/v.3.2.1-test.4~

it does require the command port setup be changed back and reverted to the old way

cmcpasserby commented 3 years ago

v3.2.1 is released and on the marketplace now so am closing this issue https://plugins.jetbrains.com/plugin/8218-mayacharm

chadlichty commented 3 years ago

Has anyone been able to get breakpoints to work? I'm running Maya 2020. MayaCharm connects and I get Maya outputs in the pyCharm console but any breakpoints are ignored.

Chad.

On Mon, Mar 15, 2021 at 5:05 AM Chris Cunningham @.***> wrote:

Closed #43 https://github.com/cmcpasserby/MayaCharm/issues/43.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cmcpasserby/MayaCharm/issues/43#event-4458289784, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADM3I3BDOSYRR6CFJPHIMADTDXZYNANCNFSM4JYA5BLA .