Code analysis doesn't work in subdirectories of the source folder - pydev

I'm working with a Python-Project with several subdirectories within the source folder.
The code analysis seems to work only on scripts directly in the src folder. All scripts in subfolders are not analyzed.
I have added the top-level source folder to the PYTHONPATH. Is it necessary to add all subdirectories as well? I'm using Eclipse Indigo with PyDev 2.4.0.
Thanks for your help!

Probably your file is beneath the PYTHONPATH but not under a python package (i.e.: a python package is a folder that has an __init__.py file in it -- note that all the folders up to your module need to have that __init__.py file) or your folder is not a valid python name (in which case it's also not treated as a package -- i.e.: folders with '.', '-', etc in the name).
If that's not the case, please post a snapshot of the PyDev package explorer.
(as a general rule, subdirectories of a source folder shouldn't be set as source folders... although you can do to support some exceptional use-cases)

Your files need not to be in PYTHONPATH to be code-analyzed,at least this is true for my PyDev 2.6.0.
I only add my project(not packages) root dir to PYTHONPATH in project properties, and the files in subdirectories are analyzed.
Be be sure to check the dir names and python file names. They must be valid python identifier for it to be imported to be analyzed. It cannot contain some innocent-looking characters, like dot and dash.

Related

Eclipse project shows an unnecessary project folder that cannot be removed

I have a Java project in Eclipse IDE for Enterprise Java Developers 2018-12 (4.10.0) built with Maven.
For some reason the folder src/test shows in Project Explorer as a "project folder" (by that I mean a Eclipse project folder, not a file system folder), besides being shown in the project as a source folder as well. That seems unnecessary and anomalous. For example, the same does not happen with src/main, which appears as a source folder only:
If I try to delete the project folder src/test, Eclipse warns me that it contains source folders which will be deleted along with it. I actually tried it anyway once: made a copy of the files, deleted the src/test project folder, and then replaced the files in the disk, but when I do that, the project folder just pops back.
Why is this happening and how can I clean it up?
src with its subfolder test is shown for reasons
There are regular and source folders. For faster access source folders are displayed compacted on the first level instead of in the regular folder tree. In your case, there are five source folders src/main/java, src/main/resources, src/test/java, src/test/resources and - probably by mistake (see below) - src/main which are not shown in the regular folder tree, but on the first level.
In contrast, src and its subfolder test are regular folders and therefore are shown (even if they are empty except for the source folders) in the regular folder tree. They are shown so they can be selected and the right-click menu can be shown containing commands (which might be contributed by additional installed plug-ins) related to selected folders only. Selecting all source folders contained in src is not the same as selecting the src folder, for instance when doing a file search on the selected folders, a .gitignore file in the src folder would otherwise be missed.
src/main should not be a source folder
To have src/main and its subfolder src/main/java as source folders do not make sense since they are nested. In your case, it is a Maven project so you can right-click the project folder and choose Maven > Update Projects... to derive the source vs. regular folders settings from the pom.xml file and overwrite the settings made manually. These settings are stored in the .classpath file. In Maven projects the .classpath file can be derived from the pom.xml file and therefore it is recommende not be shared or versioned.

Root file properties

I followed this help page to add folder to a features based product. In build.properties file I added:
root=iwrepo
'iwrepo' corresponds to a folder with sub-folders residing in a feature where the above mentioned properties file is. After the build, I get only folders under 'iwrepo' folder moved to Eclipse install directory (annogen,antlr, etc), not what I expected - 'iwrepo' folder with its sub-folders.
What am I doing wrong?
As per documentation
Similar to the "root" and "root." properties, except that instead of being copied into the root of the eclipse install, files and folders are instead copied into the given subfolder.
Instead of root=iwrepo, I need to use root.folder.iwrepo=iwrepo. This correctly subfolders folders under iwrepo.

How can I create Eclipse-style folders from the Terminal?

Is it possible to create Eclipse-style folders (Project Folder, Package and so on) via the Terminal?
I once renamed an Eclipse package like this: mv oldname newname, and I noticed that after doing so, Eclipse no longer considered the folder a Package.
This possibly means that it is a matter of metadata, but I have so far been unsuccessful in locating the files containing the relevant information.
Eclipse does not provide anything to do this and it is not really possible manually.
For a project some information is stored in the .project file in the project folder. Depending on the type of project there may also be a .classpath file and there will also be data stored in the .metadata folder in the workspace and also in a .settings folder in the project.
All the file and folder names starting with . are considered to be hidden on Linux, Unix and Mac systems and are not shown by default. Use the -a flag of ls to see them.

IntelliJ IDEA 9/10, what folders to check into (or not check into) source control?

Our team has just moved from Netbeans to IntelliJ 9 Ultimate and need to know what files/folders should typically be excluded from source control as they are not "workstation portable", i.e.: they reference paths that only exist on one user's computer.
As far as I can tell, IntelliJ wants to ignore most of the .idea project including
.idea/artifacts/*
.idea/inspectionProfiles/*
.idea/copyright/*
.idea/dataSources.ids
.idea/dataSources.xml
.idea/workspace.xml
However, it seems to want to check in the .iml files that exist in each module's root directory.
I originally checked in the entire .idea directory via the command line which is obviously not aware of what "should" be ignored by IDEA. Is the entire .idea directory typically ignored?
We have a FAQ article covering this question.
[The .idea] format is used by all the recent IDE versions by default.
Here is what you need to share:
All the files under .idea directory in the project root except the workspace.xml and tasks.xml files which store user specific settings
All the .iml module files that can be located in different module directories (applies to IntelliJ IDEA)
Be careful about sharing the following:
Android artifacts that produce a signed build (will contain keystore passwords)
In IDEA 13 and earlier dataSources.ids, datasources.xml can contain database passwords. IDEA 14 solves this problem.
You may consider not to share the following:
.iml files for the Gradle or Maven based projects, since these files will be generated on import
gradle.xml file, see this discussion
user dictionaries folder (to avoid conflicts if other developer has the same name)
XML files under .idea/libraries in case they are generated from Gradle or Maven project
.idea directory is a replacement for the old .ipr (Idea Project) file and if you want to share the project between users, then you need to share .idea folder (with the exceptions mentioned in the FAQ) and all the .iml files.
Refer to GitHub's JetBrains.gitignore file to always have an updated listing of which files to ignore.
Not an exact answer to the question, but there are sample .gitignore files available here, including one for JetBrains which includes IntelliJ.
You might find this post interesting: Merges on IntelliJ IDEA .IPR and .IWS files
It seems to conclude that you should add all files except for: workspace.xml, dataSources.xml, sqlDataSources.xml and dynamic.xml. The answer there is focusing on having files that do not change simply from opening the editor or making ide specific changes.
I'm using PHPStorm.
Here is an example snippet for your .gitignore
# Ignore the following 2 PHPStorm files only workspace and tasks file
**/.idea/workspace.xml
**/.idea/tasks.xml
All other files in the .idea directory should be committed to your repository.
e.g: (commit everything else in the .idea directory)
new file: .idea/.name
new file: .idea/encodings.xml
new file: .idea/framework.iml
...
Docs: How to manage projects under Version Control Systems
Here is what you need to share:
All the files under .idea directory in the project root except the workspace.xml and tasks.xml files which store user specific settings
All the .iml module files that can be located in different module directories (applies to IntelliJ IDEA)
So basically, commit everything except workspace.xml and tasks.xml.
Yes, I believe so. You can check the SVN configuration to see what's ignored and add anything that you think should be ignored.
IntelliJ now creates its own .gitignore file in the .idea folder so you can safely add it to repository.

setting source classpath in eclipse with stupid project structure

What do you guys do, when you have huge project built with ant for instance, where the source folders are right bellow the root project folder, for building classpath from source files ?
Putting entire project as a source folder is nonsense.
Putting separate folders as source folders can't be done if they are part of the package hierarchy and the only thing I could think of, is to copy the source folders into a separate folder and add it then as source folder which is weird but I don't know how else to do it.
Having to duplicate sources just because of the eclipse way of making classpath and also because of somebody doing stupid project structure
It's really pain in the ass...because the ant scripts are written for this structure.
Even if it was just one folder, it's a problem anyway. There must be included the upper folder to the source classpath which means it is included with all the crap around and also it means that package explorer is flooded with the packages.
example:
Instead of /project/src/java/utils where we can put src folder into source classpath...
there is project/java/utils + lot of crap like /project/docs is in the project as well.
The trick is:
An Eclipse project root directory is defined by where the .project and .classpath are.
Two options here:
Those Eclipse project files are located in the workspace (and the 'project', the one with 'java/utils' inside, is not)
Then you can make a linked folder within the Eclipse project to reference 'project', calling that linked folder as 'src', using it as your source folder.
The ant script remains right where it originally is (in the 'project' directory, along with all the other sub-directories)
Those Eclipse project files are located directly within the 'project' directory (along with 'java' and 'docs': don't.
Delete that Eclipse project (not its content, only its definition, that will only remove the .eclipse and the .classpath), and recreate anywhere else.
Then go back to 1.
For each source folder in eclipse you can choose which subfolders of it you want to include or exclude as a source folder (you can also use patterns). If I understand correctly, in your situation you can add the project root folder as a source folder and include only those folders that contain source. So in your example only "java" would be included.