What to commit to source control in Eclipse Pydev - python

I've create a pydev project in eclipse.
At the top level of my workspace I can see these two files:
.project
.pydevproject
I can also see these in each of my subfolders that contain my actual projects.
At the top of my workspace there is also a
.metadata. folder.
What should I commit to source control?
Ie what can I delete and still be able to open the project with minimal effort (hopefully entirely automated regeneration of files)? If this was Visual Studios C++ project the answer would be to keep just the ".sln", "vcxproj" and "vcxproj.filters" because the "vs" folder and "suo" files will autogenerate on openning. I've tried to delete the ".metadata" folder, but after that nothing appears to load in my workspace.
Also, I am working with someone not using an IDE. What eclipse files do we need to update to keep in sync?

Disclaimer: I am not familiar with PyDev, just with Eclipse in general. You definitely should not check in the .metadata folder. That one is for your Eclipse workspace as a whole and contains your personal configuration. (That's why your workspace appeared empty after you deleted that folder.) In fact, you should not check in your workspace folder at all, but just the several project folders within it.
Whether to check in the .project files is sort of a matter of taste. Those contain project specific information and settings and with those its easier to import the project into Eclipse, but you can import the project without those, too, it's just a bit more work. If other developers are not using Eclipse, those are useless for them. In the worst case, your co-developers will delete those files from source control and when you update your project later, they are deleted on your end, too, messing up your project.
About deleting the files: Note that there is a difference between not checking files into version control and deleting them locally. So in short: Do not commit those files into version control, but don't delete them locally, either. Depending on what sort of version control you are using, you can set it to ignore those files.

Related

Move Pycharm project to another directory

My home dir ran out of space and I wanted to move the PyCharm project to another directory. I ended up copying it because refactoring didn't work. I deleted the pycache and the zip exception, that had appeared was gone and now everything works as expected. I still use the venv location of my initial project location though, from what I can see in settings/python-interpreter.
Is there anything wrong with this procedure, anything I'm not aware of?
Should I edit some of the files in the .idea folder?
The $PROJECT_DIR$ variable caught my attention, but I couldn't find where this variable is actually set.
A clean way to move your project is right-clicking on your project folder in "Project view" (Alt +1 ) , choosing Refactor and then Move Directory.
The $PROJECT_DIR$ variable is dynamic and taken from the directory your project is in, so that isn't a problem
Your .idea folder should be recreated by PyCharm even if you completely delete it. However I wouldn't advise deleting your folder mainly because you will loose your project-level dictionary (wordlist).
Invalidating caches has a wider impact because it will clear IDE wide settings not just project specific settings. (It's mostly useful if your cache becomes outdated, which tends to manifest itself by inexplicable errors.)
If something goes wrong just open the moved directory as a new project going to File > Open. For a simple project there are 2 main settings that you should check and may have to adjust:
In settings "Settings" (Ctrl + Alt + S) go to Project: your_project_name and there check that Project Structure makes sense and retains your configurations.
In Run > Edit Configurations make sure that Script path and Working directory are set to the locations you want.
Is there anything wrong with this procedure, anything I'm not aware of?
From your description you took the right steps since refactor didn't work, just ensure the above configurations are met and if the IDE doesn't issue any errors you should be good.
Should I edit some of the files in the .idea folder?
This would rarely be necessary and is generally discouraged. The files in the .idea are IDE generated and should not be touched. Any necessary changes should be made using the IDE graphical interface to set configurations (which means you don't have to worry about the contents of .idea).

Which (if any) project files to put in .gitignore for Pycharm projects (beyond those already in .idea/.gitignore)?

Pycharm generates a .idea directory at the root of a Pycharm project. What files/directories within .idea should be ignored by git in this directory? Is this properly handled by the .gitignore file automatically generated within .idea:
cat .idea/.gitignore
# Default ignored files
/shelf/
/workspace.xml
or do I need to add something to the project root's .gitignore file?
In general, you should not check in any files to the repository which are specific to your editor or IDE unless they are also absolutely required to build the project. So if you're using PyCharm for development, all of the files it generates should be ignored.
The reason is that on most projects with multiple developers, different people will use different editors. So while you use PyCharm, I might use Vim. We don't want our .gitignore to have to learn about every user's preferred editor files, and we don't want to have to maintain multiple sets of editor files, especially since we may work on multiple projects together. If we need to configure settings, it's better to use an .editorconfig file, which works across editors, or prefer a standardized set of tools, such as a code formatter (and check in any configuration we need for that).
Instead, you should configure core.excludesfile (or use the default, $HOME/.config/git/ignore) so that it excludes your editor files. This works for all repositories that you use so each project doesn't have to learn about those settings and lets you change one place if you change editors. So in this case, that means adding the /.idea line to that file.

Moving PyCharm projects folder and keeping reference to python interpreter

I'm using macOS 10.15.4 and PyCharm 2019.3.4
I currently have a folder inside the PyCharmProjects folder (that is automatically created when PyCharm first runs) where I keep projects for a class. I want to move this folder, which contains multiple other folders which each contain PyCharm projects, somewhere else on my computer (like the Desktop). The problem is if I move the folder (or even just a single PyCharm project) the next time I open the project in PyCharm, it says "Invalid python interpreter selected for the project." Now I can manually go into PyCharm preferences and point it to the new location I moved the folder so it can use the correct python interpreter. But this would be tedious to do for every single project I have. (And yes, every project I have uses its own interpreter and virtual environment.)
Is then a way I can move a folder containing multiple PyCharm projects without loosing the references to each of their respective python interpreters?
(Feel free to reword this question or the title.)
PyCharm uses configurations from your home directory. The docs say
macOS
Configuration
~/Library/Preferences/<PRODUCT><VERSION>
Caches
~/Library/Caches/<PRODUCT><VERSION>
Plugins
~/Library/Application Support/<PRODUCT><VERSION>
Logs
~/Library/Logs/<PRODUCT><VERSION>
where <PRODUCT> is PyCharm.
They are xml files. Among them also a list of configured interpreters. They are separate because they are available for all your projects to be chosen as the default interpreter. You'll have to edit the xml files.
For some reason PyCharm does not help with a moved virtualenv directory directly. (see comment from engineer: https://youtrack.jetbrains.com/issue/PY-32435#focus=Comments-27-3139072.0-0)
On the upside, everything else seems to work, except the path to the venv python. That one can be changed through preferences/project preferences/python interpreter. Just click on "add", "existing", and select the python compiler in your project folder.
Try not to select the ".virtualenvs" python compiler, as if you fumble like I did, it seems it's a bit of a pain to get rid of it and go back to the right one. If you do that, renaming the project folder once more gets you back to square one and you get to try again.
Note that I'm using MacOS. YMMV.

What do I need to do to get Django Unit Tests working again in PyCharm after renaming a project and its directory?

I have several projects open in one window, some of which are different branches of the same project. I decided to rename the directory and project for one of these branches in PyCharm using the Refactor option on the project. After doing so, the Django Unit Tests Run Configuration I had working no longer works. It is still trying to run the tests from the old directory name.
I have not found anywhere in the Run Configuration to specify the directory. The working directory, yes, but that doesn't fix it. I tried changing all instances of the old path to the new path in the workflow.xml file in the root project (which is where the Run Configuration was stored), but that didn't help, and may have messed up other configurations.
Does anyone know where to change the directory for Django tests in PyCharm?
The Django project root setting does not get updated when you use the Refactor / Rename option, so you'll have to update it yourself. Go to Preferences -> Languages & Frameworks -> Django. Select the project of interest. Just below the Enable Django Support checkbox is the Django project root: setting. Click the folder, navigate to your project root, and click Apply or OK.
(Note that while there are other questions with the same or similar answers, the questions being asked are different enough that neither Google searches nor SO searches found them, thus I chose to document the answer in a way that someone else can find the answer.)

How open existing PyDev project?

Experienced Programmer, but new to Python. Using OsGeoLive and PyDev on Eclipse.
A few weeks ago I started a new project in PyDev (my first one). I set the project aside and am only now coming back to it. But when I open Eclipse, I do not see any way to open the project I started. There is no Recent Projects on the File Menu, File > Import does not seem to be what I need. The Project menu has an Open Project item, but it is deactivated. When I open the project's .xml file from Eclipse, it opens it as an editable XML file.
How do I open an existing PyDev project, or alternately, how do I trouble shoot PyDev losing track of the directory structure?
Locate the Package Explorer window and see if there any project folders in there. You also have the option to see "Working Sets", which are convenient to create projects distributed through several folders. Just to make sure, check out if you see something like this (You can display Projects with the prompted submenu):
If you don't see anything there, perhaps your project folder is missing an init.py file, in order to be recognized as a package, which is a general Python standard.
Sorry if this doesn't help much, I cannot leave comments yet.

Categories