PyCharm - Send directory to run configuration from right-click menu? - intellij-idea

I have a run configuration in PyCharm with script parameters that take in a directory. Then, I have several directories (a changing number) in my project which I would like to easily be able to run this configuration on. Is there anyway to add an option to the right-click menu of directories to run the configuration passing that directory to the configuration? Or some other method which provides similar accessibility to running the configuration on a directory?
For my specific problem, I have many log directories for TensorBoard (from TensorFlow) and I would like to selectively and easily be able to start up an instance of TensorBoard running on a given directory.

Basically if you would run it in pycharm You can write your own plugin to add some functionality to the IDE. There is a great documentation on how to create plugins in idea/pycharm:
http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started.html
We have done it before and it was a successful plugin, it really sped up the development processs. :)

Related

Why did Pycharm ask me to set up a sync folder every time when I add a remote interpreter?

Every time I tried to config a remote interpreter, Pycharm asked me to set a sync folder. In my routine, I usually have the Cannot find declaration to go to error which can not be solved by invalidating caches. So I have to config the interpreter again. And these caused the redundant folders in my remote machine. And another situation is that I want to create other projects with the same interpreter. Where I have to config the folder mapping for each project to make the interpreter valid.
I do not understand this way. In my opinion, the sync folders should correspond to my local project. And the interpreter should be independent of the projects.
Every time I tried to config a remote interpreter, Pycharm asked me to set a sync folder.
To be able to execute a script on the remote machine, it is necessary to make sure it exists on it. This is by design, but if you already have a project folder deployed, you can change the suggested paths to needed ones during the interpreter configuration.
See step 7. https://www.jetbrains.com/help/pycharm/configuring-remote-interpreters-via-ssh.html#ssh
And another situation is that I want to create other projects with the same interpreter. Where I have to config the folder mapping for each project to make the interpreter valid.
Unfortunately, this setup does not work, please vote for
https://youtrack.jetbrains.com/issue/PY-40680/Allow-reusing-a-single-remote-interpreter-in-multiple-project
to increase its priority.

IntelliJ & Global Config Files

I've been searching for a solution but I can't find one.
I have a global configuration directory in my IntelliJ workspace. I also have several dozen modules. I would like each module to automatically include the global config directory in its path when I run or test a class.
Is there anyway to do this within IntelliJ? I don't think I should need to edit the configuration for each "Run/Debug" config to include the directory.
You'll want to set it in the Defaults for the type of Run or Debug Configuration that you are using.
For example, if I always want a Java Application to have the VM Option -XPutYourThingyHere, then I could go to Edit Configurations, Defaults, Application, and put -XPutYourThingyHere in the VM Options box. Then all new Applications that I run will have that option.

Setup golang environment using jetbrains

I have setup an golang developing envionemnt using idea (13.1 community edition).
It seems the SDK is recognized.
However, I could not create a GO file by right click the "New" under the source folder. (The item of "go" is grayed)
Currently I have to manually set the file extension to ".go" and edit the file, but autocomplete is OK.
This only exist on my Mac(with version 10.9.4)
I have set the GOPATH directory access mode to 777 but still not work.
This works fine on windows7.
So what should I do ?
This is what it looks like in windows
Thanks VonC, I already tried the /Users/Tom/go setting, this doesn't work and I switch to this root path.
here's my previous setting
macbook:home root# go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mac/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
And this is what is look like in the /Users/Tom/Go
Thanks VonC, however, this doesn't work. I am not sure what's the reason.
This is the envionment setting using GOCODE
This is several steps!
step1
By the way, I noticed that there are a difference from mac and windows when creating a new Go Project
at this step, the windows platform will show a "project sdk" while mac won't.
Make sure your IntelliJ project reference the right path within GOPATH.
From the plugin page:
If you have only one directory in the GOPATH and you are creating a project inside that path when you are working with packages that are part of the project you must still specify the whole import path for them, not the relative one. Example:
GOPATH is: /home/florin/go
the correct way to setup a project called demogo is: /home/florin/go/src/github.com/dlsniper/demogo/
new package is: /home/florin/go/src/github.com/dlsniper/demogo/newpack
the correct import statement is: github.com/dlsniper/demogo/newpack not newpack
Also make sure you have the latest version of the plugin, as issue 756 illustrates that IntelliJ IDEA 13 doesn't create the project directory structure on Mac OS X.
Finally, check if IDEA has correctly detected GOROOT and GOPATH:
See the page "Fix missing environment paths (Mac)".
The OP python adds in the comments:
If I have create a new Go project, this new feature is disabled.
If I create a new Java Command line App, then I could right click and add new Go file.
Right-click on either the top-level project or on the src directory and then go to Mark Directory As > Sources Root. After this you will be able to access the enabled Go context menus.

How do I share IntelliJ Run/Debug configurations between projects?

I have many different versions of my app. Each one is a separate IntelliJ project. Every time I open a new one, the list of configurations starts blank:
The annoying thing about this is I deploy to 1 VM and I have to copy and paste the debug configurations each time I want to test a different version. IntelliJ makes this dialog modal per IntelliJ Instance, so I can't copy and paste the fields between Project Instances.
I end up taking a screenshot of one configuration and copying the fields by hand into the other project. It's a pretty primitive solution. Is there a more convenient way to get a run configuration from one project to another?
I'm using IntelliJ 13 on Windows 7.
Can I share settings for IntelliJ Idea across different projects? may have the answer to this, but the question is different. It's about window layout. Therefore I don't consider it a duplicate.
The best way to do this is to click the "share" checkmark next to Name field when you edit/create the configuration. You can get to this Dialog with Run > Edit Configurations.
The share check-mark pulls the setting out of your workspace.xml and instead puts it in the directory .idea\runConfigurations. This is designed so you can share the setting with others.
You could copy this file and put it in the same location in all your idea projects.
However, in the future, you might want to consider using source control branches for app versions rather than separate projects. IntelliJ handles these very well.
UPDATE (June 2021):
IntelliJ now puts this in the .run folder as its own file, no longer in .idea/runConfigurations.
Run configurations are stored in .idea/workspace.xml by default. First alternative is to share this file but it is not feasible because you also share a lot of unnecessary configurations.
As already said, the first step is to check "share" option to separate run configurations from workspace.xml.
After that, I recommend adding runConfigurations to source control. But the main problem is, probably you have already marked .idea folder as ignored.
You can unignore the folder by configuring your source control system. For example, if you are using git, you can change .gitignore file as follows:
.idea/*
!/.idea/runConfigurations
don't forget adding * after .idea/
As the last step, add your run configurations to source control and enjoy your shared configurations!
goto
Run > Edit Configuration > create or select existing configuration you want to use > click save and persist it on file system > click on share check mark
now copy this file from
PROJECT_ROOT_DIRECTORY/.idea/runConfigurations/ConfigurationName.xml
to your NEW_PROJECT_ROOT_DIRECTORY/.idea/runConfigurations at the same place and it is available now to your run configuration
You should copy the folder
~/your-old-project/.idea/runConfigurations
to
~/your-new-project/.idea/
That's the folder that contains the run configurations.
An update for this question with the new IntelliJ updates:
Now you can "Store as project file" which will create a folder named ".run" and export your setting to that folder. In the example below, I did it for all my test settings. This removes the requirement of editing .gitignore since files are now not outside of ./idea
This is not exactly an answer to your question but it answers a question similar to your question and one that I had, and I'm assuming others might as well.
That is, How to save unit and instrumentation test run configurations? I usually right-click on the test directory which brings up a menu with the option to Run whatever is in that directory. AndroidStudio then creates a run configuration on the fly and in the Run Configuration drop-down menu a new option will appear, "Save new configuration?" or something similar.
Clicking that option brings up the Run Configuration menu and at that point I check the Share box as many others have already mentioned. This then will prompt the version control system to ask me if I want to add this new run configuration file. If you haven't registered your version control system you can find the new files under .idea/runConfigurations.

Start two instances of IntelliJ IDE

Well my question is pretty simple, how do I start two instances of IntelliJ (community edition).
When I have one instance started and I try to start another one, all that happens is that my started instance gets focus.
I'm developing Android applications using IntelliJ.
Any thoughts?
Press Ctrl+Alt+SChoose Appearance & Behavior, then System Settings, check radio button: Open project in new window.
You need to configure each instance to use its own folders for config/plugins/system locations by editing idea.properties file on Windows/Linux and Info.plist on Mac. You can find the details in FAQ.
Note that normally it's not necessary since you can open multiple projects in different IDEA frames within the same instance using File | Open or Open Recent.
CrazyCoder has roughly the right idea. However, setting the config file alone was not sufficient for me to run multiple instances. Here are my steps to get this going (in GNU/Linux, I am sure you can figure out equivalent in other systems):
Create a folder/directory per instance you want to run.
mkdir -p ~/idea/instance-0
Go to the installation directory (e.g. /opt/intellij) and copy the idea.properties (in bin) file over to your instance directory.
cp /opt/intellij/bin/idea.properties ~/idea/instance-0/
Copy 3 more directories: system, plugins, and config. I highly recommend doing this without the running instance
cp -r /opt/intellij/system ~/idea/instance-0/
cp -r /opt/intellij/plugins ~/idea/instance-0/
cp -r /opt/intellij/config ~/idea/instance-0/
mkdir ~/idea/instance-0/log
Open your idea.properties file and update the configurations for your directories:
#---------------------------------------------------------------------
# Uncomment this option if you want to customize path to IDE config folder. Make sure you're using forward slashes.
#---------------------------------------------------------------------
idea.config.path=${user.home}/config
#---------------------------------------------------------------------
# Uncomment this option if you want to customize path to IDE system folder. Make sure you're using forward slashes.
#---------------------------------------------------------------------
idea.system.path=${user.home}/system
#---------------------------------------------------------------------
# Uncomment this option if you want to customize path to user installed plugins folder. Make sure you're using forward slashes.
#---------------------------------------------------------------------
idea.plugins.path=${user.home}/plugins
#---------------------------------------------------------------------
# Uncomment this option if you want to customize path to IDE logs folder. Make sure you're using forward slashes.
#---------------------------------------------------------------------
idea.log.path=${user.home}/log
Now, you can start IntelliJ with the new setup:
IDEA_PROPERTIES=~/idea/instance-0/idea.properties /opt/intellij/bin/idea
Obviously, you probably want to put the command in a script file for invocation. This seems to work for me.
File->Settings->General and in section "Startup/Shutdown" check "Confirm window to open project in"
With Ultimate 2020.2, go to Appearance & Behavior > System Settings in the settings dialog and select the "Ask" option for "Open project in"
As per the directions from jetbrains you'll need go to the 'General' page of the 'Settings' dialog and chose 'Open project in a new window'. Then proceed to open a project as you normally do. IntelliJ should then startup a completely new instance.
There is an other very quick way of doing it. There is always an EAP version of the IDE and it can run at same time with the current one. For example I am using AppCode 2017.2 and 2017.3 EAP in parallel.
Go go to IntelliJ | Tools | Create Command-line Launcher...
Keep the defaults (which creates a binary named "idea"):
Now, go to your command line.
Cd to your project directory and type: idea .
This will create a .idea directory for IntelliJ configurations for that project, which it will re-use each time to start IntelliJ from that directory.
You can now go to a different project directory and type: idea .
Assuming you left the previous IntellJ IDE open, you will now have two IntellJ IDEs open, one for each project.
Notes:
1) If your project uses environment variables, then I'd recommending opening a separate terminal tab/window for each project and set that project's environment variables before running: idea .
2) Depending on what you're trying to accomplish, you may need to modify your classpath (or settings like Project GOPATH) for each IntelliJ instance.
My answer is not directly related to the question but its a solution for some cases where we think we need 2 Intellij instances.
For my issue I was thinking to launch 2 Intellij instances. But after careful thinking and searching for other options, I found an easy and quick solution and I wanna share with the community
If you are looking to compare files between different branches, and you wanna compare the difference, that can be done with git comparison. You don't need 2 different Intellij instances.
My Case:
In my case, I wanted to copy very specific code from 1 branch to another and I wanted to compare the difference between the code. The restriction was, I can't do git merge or cherry-pick because we didn't want full commit to be part of new branch. Just few necessary lines were required in the new branch.
My Solution:
Select the branch
Open the file where you wanna insert code
Right Click -> Git -> Compare with... (refer to pic)
Select the branch and you will get the difference
Append or Copy the difference
If you have new files or directories, you can create it manually and copy-paste the content
I know this answer doesn't directly relates to what has been asked, but sometimes we miss alternative solutions.
Hope this can be helpful as an alternative solution.
In addition to the above comments from #crazycoder and #magice, Make sure that you are not trying to load Pycharm with the same project two times which happened to me!!!.
For example, in windows10 already loaded with ONLY one project in PyCharm and tried to load another Pycharm instance by clicking on the PyCharm desktop shortcut or from task-bar if added. In this case, Pycharm will not load the second instance.
I have wasted some time here. So, wanted to share with the community as it will help someone out there!!
Cheers,