![]() ![]() Once I opened these files and repeated the refactoring these were included. However the curious thing was that the refactoring seemed to miss some occurrences in files I didn't have opened. It's not clear to me whether you're normally expected to set your main package folder as a 'source folder' or not. Same result when designating the root folder as the only source folder and excluding all else. Once I do that and then move the pinvh function with F6, it at least changes the import statement in dpgmm.py to "from import pinvh" which should work although it doesn't follow the existing relative import usage. (Make sure there is no blue 'Source folder' listed in the right side panel.) May also need to 'invalidate caches and restart'. ![]() Something I thought was interesting is that you get different behavior if you don't designate a source folder at all. I usually just manually fix the import statements, but yeah, it's annoying. I have also run into this behavior in my projects. I see what you mean now and have reproduced it. ![]() ![]() This issue is somewhat alleviated if you have the project code installed under the venv as P圜harm will also look for the missing import under site-packages. The import statement that P圜harm offers references which is wrong, it should be - the top level root directory is ignored. Put your caret on the pinvh reference, hit Alt+Enter (on OSX). This will create several errors, one on line 215 because the pinvh function isn't found. Simulating you writing the new code and later just adding the needed imports. utils.extmath import logsumexp, pinvh, squared_norm Open and delete the import statement from line 20įrom. Say you write an awesome new function that uses pinvh. Which will fail when you run the code, as that function actually lives under .įirst, undo the all previous changes (the refactor) and remove sklearn from the venv (undo python setup.py develop) So you look for, hit F6 to move the function and move it to You of course want all the references to that function to also change, for instance the one in (line 20). Let's say you wanted to refactor - you realise that the pinvh shouldn't be there but should instead be under. Is there are better way to get the auto-imports to work properly? )Ģ) Mark the entire project directory as a Source directory and then Exclude all the directories that don't actually contain any sources - this is just stupid The import should of course be `from sklearn import cluster`, but P圜harm discounts the top of the Source tree.ġ) create a separate 'src' directory under the project root and then the top level package in in there - this doesn't actually rhyme well with a lot of existing projects (sklearn, scipy, numpy, gensim. So the `sklearn.cluster` package will be imported as just `import cluster` which will of course fail when trying to run your code. Doing this however will cause all the auto-imports to fail because P圜harm won't take the Source directory itself into account when auto-importing. Given that the `scikit-learn/sklearn` directory is the root of the entire source directory tree one would be inclined to mark that as `Source`, especially when all the other directories don't really contain any sources, just auxiliary things. To get P圜harm to recognise what is what, one tends to mark some directories as Source directories in Settings - Project Structure. sklearn/cluster <– sklearn cluster package containing stuff related to clustering sklearn <– all the sources for the project Scikit-learn <– top-level directory created during git clone (project root) So usually a Python project is structured in the following manner (using scikit-learn as an example but this also applies to scipy, numpy, gensim etc.) This seems like a bug to me as it isn't in line with the project structure of a lot of existing Python projects. There is a problem that arises from an interaction between P圜harm's auto-import logic and the described project structure. ![]()
0 Comments
Leave a Reply. |