-
Notifications
You must be signed in to change notification settings - Fork 36
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
Editor Autocomplete #5
Comments
Yes, I have heard of several ways to get autocomplete working. One is building blender as a python module (see Blender as a Module and Building Blender as Module). Another probably easier option is getting/making a pyprefdef file (e.g. mutantbob/pycharm-blender) which are just stubs of the api, should work regardless of the editor. I've also found this: nutti/fake-bpy-module, not sure if it's also generating stubs or doing something else. I have not had time to test and confirm they work and document everything. Will do when I have some time. If anything is particularly confusing I will also make a video. |
I was just able to build blender as a module. The make process is fairly straightforward despite there being some gotchas. Generally the process is
I am close to having a setup.py (for pip) which will do this automatically in a temp directory, then copy to the current site-packages directory. Thinking about your comment the other day, this would probably be the way to go; what you said made a lot of sense. I'll open an issue for further discussion, but it will be less of an issue, more like a feature request. |
Bit of an understatement... Just finally got this working and having never done this before, as I suspected, at least for windows, it's not very straightforward, the information is scattered across guides, some I had to find elsewhere, like the fact that you need to be sure to install the C++ workload (or I'm not sure what the equivalent would be for VS 2015? anybody know?). And if you already have the Visual Studio C++ Build Tools installed, but not the IDE, as I did, the way the Also if you configure directly from the cmake gui (which will detect the build tools without problems), it's not very obvious how to build it. I eventually figured it out, but it's easier to do Also the build is in REM To use: Copy to build folder. Run "install YOURPYTHONPATH PYTHONVERSION BLENDERVERSION" e.g. "install C:\Python36 36 2.79"
REM No backslash after path.
set pypath=%1
set pyversion=%2
set version=%3
copy bin\Release\bpy.pyd %pypath%\Lib\site-packages\
copy bin\Release\*.dll %pypath%\Lib\site-packages\
del %pypath%\Lib\site-packages\python%pyversion%.dll
xcopy /E bin\Release\%version% %pypath%\%version%\ It's not too much of a pain to run everything now that it's setup, though I could probably make an easy update script to pull in changes and rebuild. When I have some time I will test how the other methods compare to this. This isn't really ideal if you're only interested in autocomplete. Although I do wonder, are the dlls even needed for autocomplete? because if they aren't it would be fairly trivial to have an occasional build run to package the bpy.pyd and the .py files. @TylerGubala Would be interested in seeing the setup.py you've come up with. |
@AlansCodeLog Hi, I have no real issues installing or making the blender pyd from sources, as you said there are some issues with the documentation, looks like that hasn't been updated in a long time, but there are open and resolved issues that have led me on the path of success (I was having trouble because I was on a venv trying to reproduce the steps) I've created a setup.py for bpy.pyd/so over in https://github.com/TylerGubala/blenderpy but is very initial/ experimental. I am having much more of an issue finding specific documentation to let me create a valid setuptools distributable than building bpy from sources. My current concern is that the way I have it set up now, if someone were to run the setup script, I have a bunch of python files that control the build process. It's by no means perfect and needs a second pair of eyes. The real trouble is, my python files that control the build process... I only want those alive as part of the lifecycle for the setup program... after that they should go POOF (be deleted in some way...? I don't have too much experience writing a setup.py in this way) because the .so or pyd (depending on the platform) really should be the true module, and that has to be built. Furthermore, I'm having some trouble figuring out how to specify the files so that when it uploads to pypi, pypi will only get the python scripts that control the build process, that way when a user grabs it, the dependencies are installed from requirements.txt, they get the automated build python scripts, setup.py runs, and they get the bpy package installed into their site packages. Last thing to note: what will happen when the user runs "uninstall blenderpy"? How can I make it know to grab the binaries that I sneakily placed in the user's site-packages? Like I said, this definitely is far from perfect. I need some help in that regard, but as a proof of concept I'd like another set of eyes to critique. So that's where I am with that. As far as making a setup script for your blender debugger for vscode, I'm kind of wondering how much value would be added. As you said the setup really isn't that complicated but I have a few ideas in my mind that I will publish different forks for probably this weekend if all goes well. One idea would be to use python's requests library to download the get-pip script into a temporary file and subprocess.call blender's bundled python to run that temp file, then to change the blender-debugger-for-vs-code to read ptvsd from the blender site-packages dir (haven't actually looked at how your code is doing it currently, got sidetracked with the automated build script for bpy). Additionally maybe there could be an additional option in the setup script to create a venv for you with bpy already installed. Another idea would just be to literally perform all the steps that you performed in the youtube video, but instead of opening blender to install the addon just extract it to the addons directory (more research on my end is needed) I have things to look up still for certain.
I wasn't aware of the limitation. I have the IDE so maybe it "just works" for me but I'd need to look; I call
EDIT: There are some things that are broken that I'm trying to deterministically fix now, but it involves some windows registry hackery, and possibly I will just fall back on the directory if I can find it based on the issue that you were having. |
Wow. After a lot of tomfoolery I'm able to get my setup.py to build blender from sources. Side note: this is actually a going to represent the sdist version of the bpy.so/pyd in my initial thoughts? I'm still learning a lot about setuputils and pip as packaging solutions and would really appreciate any help or recommendations. Taking this into consideration I think that supplying bdist_wheels for most known platforms would be better than asking users to go through the whole build process from start to finish, which may not be something they want considering it requires downloading all Blender sources (on a potentially slow connection) and having VC build tools installed. I just committed something that might fix the build process on Windows. Of course if it suits you better to just have the polyfill/autocomplete file, then going with that makes sense. I'll try to make more improvements over the week |
@TylerGubala It is an interesting approach, but I can't say I understand much of what's going on except the general idea (correct me if I'm wrong: a python module that downloads Blender, builds it as a module, and installs the build correctly), it's a bit over my head. Sorry. I don't personally see much use for it now that I have downloaded everything and got it working, but it's still interesting. I have considered setting up a CI build for Blender as a Module, but I have too many side projects as it is and the better approach seems to be generating python stubs.
When the addon is activated, the field for the path to ptvsd has a default function that runs and executes
What happened to me was a specific case, I was kind of anticipating it. For most people it should not happen, and a simplified version of the build instructions will do, but it is useful to know (for if you have the build tools or don't care to install Visual Studio just the build tools). What happens is that in the Notes Regarding Python StubsI have taken the day to test the two repos I mentioned above. I thought fake-bpy-module would be the better solution as it was newer but although both projects are creating a similar end result (python stubs), they do it differently. pycharm-blender is just a python script which when run by blender goes through the api and records it so to speak. Autocomplete with it seems to be working. I would like to compare it how the module does, but see below. The way it works looks promising though. It might be possible to include a modified version of it or write something like it so that stubs can be generated from this addon (or another, technically the stubs are editor agnostic) and we can kill two birds with one stone. fake-bpy-module was actually designed to be used with the blender source files. Did not realize this at first glance. It's instructions are a little confusing, but I eventually got it working. It's taking the docs in the source files and generating stubs from those directly instead of directly from Blender if I understand correctly. But although it does autocomplete, I'm not getting any definitions. They seem to be empty. I did get some errors when running it though, so maybe it was me. Will have to test further. Also it must be noted for these two options that you have to set the path manually in VS Code, there's a setting called Now I wanted to compare how these did to the module I compiled but now I can't get it to work. The autocomplete just gets stuck on |
Sorry are you talking about the built blender as a python module? I can get my code completion to work (albeit it takes about 10s for the autocompletion list to populate) in a venv that I have However please if you are doing this do it in a venv. Pip does not track these files yet... I am working on a way to have pip track these files but for now it must be done in a venv otherwise you will have to remove these manually if you plan on uninstalling. |
@TylerGubala Yes, I built blender as a module manually (as I said, sorry I didn't try your script, but I had already downloaded everything, took ages), and installed it (in a conda env), but it was taking way more than 10 seconds for me, sometimes it wouldn't complete at all. So I tried it again just now though with a clean conda env and a newer version of VS Code and now it's kind of usable with a 3-5 second delay. Not sure what was happening before.. But the preloadModules option doesn't seem to make any different. Somebody has already filed an issue over at vscode-python (#1704) so hopefully this will eventually get fixed. As for how it compares to pycharm-blender, it's much better, pycharm-blender seems to be missing a lot of parts. For example, So building blender as a module seems to be the way to go for now. I will add this to the documentation as soon as I can. Also the "Building Blender as a Python Module" documentation no longer exists on the wiki, gotta ask what that's about. If anybody wants to have a look at it, I was able to find it by searching the link above in the wayback machine. |
I'm just glad to hear it's working. Maybe pycharm-blender can be improved upon as well. Not sure what's going on in the docs; odd to see that section of the documentation removed... I was able to get backups of the old documentation usable through wikitaxi, if you want it. |
Yes, I'm sure it's just old code but I don't have time to look at it for now. Yes it's weird, I think it was just a mistake from moving the wiki. I'm going to wait a little bit, maybe they're still transferring stuff, then ask. |
Putting this here in case it helps others trying to get intellisense going for bpy. @Korchy has a handy guide for setting up autocomplete in VSCode for Blender 2.8 that I was successfully able to follow on Windows. https://github.com/Korchy/blender_autocomplete It's not great to have to manually follow this process after installing this extension, but it's not too difficult to follow the important steps for a given project: Download the fake bpy stubs, then modify your (likely project-local) settings.json to add the stubs as an extra autocomplete path. |
For me the fake-bpy-module |
Hi, I just followed your explanation and all works well !
Only one thing, I enabled pyLint in vs Code and it warns me it doesn't know bpy :
E0401:Unable to import 'bpy'
So autocompletion doesn't work well.
Have you got a tips to bypass this problem ?
Thank you !
The text was updated successfully, but these errors were encountered: