Change highlighting setting for every file (by default) in PyCharm CE - python

I just started using PyCharm as my IDE for Python. At the moment whenever I open a new .py file, I have to go to Code -> Configure Current File Analysis..., and then change the highlighting to syntax (preference) for every individual .py file.
Is there a way to change this for every file automatically, by default?
First post on stackoverflow by the way.
Thanks!

If you prefer not to see PyCharm's code inspections, I would suggest creating a new inspections profile that does no inspections. To do that, go to the Code -> Configure Current File Analysis dialog like you have been, but this time click on the Configure inspections link. At the top, click the "Manage" dropdown and copy the current profile into a new profile which you'll name "No inspections". Then uncheck everything, save the new inspections profile, and you'll be done. All new .py files should now be created under your "No inspections" profile.
Note that as far as I can tell, the inspection settings get saved per-project, rather than as a global setting. But changing the inspection profile once per project shouldn't be too much of a hassle.

Related

Meaning of X next to file icon in Project View in PyCharm

I suddenly saw this marking next to one of the files in my Python project working on PyCharm. What does it mean?
I didn't get any tooltip when hovering over this icon to tell me what it meant, nor did I find any reference to it in a Google search.
The .py file is greyed out and marked with an X in the Project View because you chose the option "Mark as Plain Text". You can reverse it by choosing "Mark as 'Python'". Both options are available by right-clicking on the file in Project View.
Exclude files and folders
Marking dynamically generated files as excluded can speed up the indexing and overall IDE performance. Excluded files remain a part of a project, but are ignored by code completion, navigation, indexing, and inspections.

Jupyter notebook: Display dataframe such that clicking cells opens files in file explorer (e.g. Windows explorer)

Is there a way to display a dataframe in a Jupyter notebook such that clicking cells opens a Windows explorer (or any other native explorer) in a given directory?
I tried
def make_clickable(url):
return f'{url}'
df = pd.DataFrame({'dir': '.'}, index=[0])
styled = df.style.format({'dir': make_clickable})
display(styled)
df = pd.DataFrame({'dir': 'file:///C:/'}, index=[0])
styled = df.style.format({'dir': make_clickable})
display(styled)
The former opens a new browser tab in which the Jupyter tree is displayed (at the correct relative location, if I replace . by another relative path).
The latter doesn't do anything. If I right-click open in a new tab, it gives about blank#blocked and if I copy and paste it in a new tab address line, it shows the browser built in explorer, not the Windows explorer.
I tried replacing _blank by _explorer.exe but that doesn't change anything for either variant.
Thus, both options are far from what I want.
(I know, security... but, this is for an in-house tool in a a completely off-line setting)
I know it is somehow possible to open explorers from the browser, because I can just use os.startfile in a Jupyter cell, so I was thinking maybe there is a way to execute arbitrary code when cells of a dataframe are clicked? Maybe this requires some sort of widget?
I could always write an entire Python GUI of course, but I'd really rather not.
I am a bit late but I finally figured it out. Javascript itself is unable to open file explorer for security reasons. However javascript can execute python code inside Jupyter notebook(Jupyter.notebook.kernel.execute) and python can open windows explorer using(os.startfile('.'),subprocess.run etc.).
Below is the code. The linux one works fine as intended but with windows the explorer opens but doesn't move into user focus it also shows the orange beeping light behind the icon show it should be fine.
import pandas as pd
import os
import subprocess
windowsv1 = """
<p onclick="Jupyter.notebook.kernel.execute(`os.startfile('C:\\Users')`)">File Explorer.</p>
"""
windowsv2 = """
<p onclick="Jupyter.notebook.kernel.execute(`subprocess.run(['explorer', 'C:\\Users'])`)">File Explorer.</p>
"""
linux = """
<p onclick="Jupyter.notebook.kernel.execute(`subprocess.call([opener, r'/home/equinox'])`)">File Explorer.</p>
"""
def make_clickable(url):
return windowsv2
df = pd.DataFrame({'dir': '.'}, index=[0])
styled = df.style.format({'dir': make_clickable})
display(styled)
I am not 100% on this but I think this will depend on the browser you are using. Furthermore, I think most browsers will block this kind of behavior and not allow a web page link to open your file browser.
Please, someone, correct me if I'm wrong.
EDIT 2020-08-15
It is possible to do it if you install a Chrome Browser extension.
Just follow the below link. After your code worked for me.
https://www.alphr.com/browse-and-open-folders-files-chrome/
Scroll down to Title "Open Any Local File From Chrome".
Follow all the steps
Don't forget to restart Chrome after installing the browser extension (and the extra installation file)

Why is Pycharm not highlighting TODO's?

In my settings, I have the TODO bound to highlight in yellow, yet in the actual code it does not highlight. Here is a screenshot of my settings: Editor -> TODO
Does anyone know how to fix this?
EDIT: I even tried re-installing Pycharm and I still have the issue.
EDIT 2: In the TODO Window, it is saying "0 TODO items found in 0 files". I believe this means it is looking in the wrong files to check for TODO items. However, when I try to find TODO items in "this file" it still doesn't work. Does anyone know why this is?
Go to Preferences (or Settings), Project Structure, and make sure the folder with your files is not in the "Excluded" tab's list.
Click the folder you want to include and click on the "Sources" tab. Click Apply, then OK!
It should work.
I recently updated PyCharm Professional and my TODOs no longer worked. I went into settings and changed the alert icon, then saved, and retyped them and they worked. I imagine for my case, there was a delay in the new version picking them up. Might just need to retype them to get them working again, though the reboot should have addressed this.
Not sure if your pattern is causing this, but mine is set up like so, with two separate patterns:
\btodo\b.*
\bfixme\b.*
Neither is case sensitive, BTW...
Perhaps try some other patterns to see if you can get those to work.
I think the problem for me was the same as explained by #theBrownCoder but I couldn't find the project structure settings.
Apart from not showing TODO's another symptom was impossibility to go to function definitions defined in other files and inability to rename python files with the error: "Selected element is used from non-project files. These usages won't be renamed."
Googling for this the solution that worked for me was to delete the .idea folder (make sure to back it up just in case, you will lose the configurations).
I had the exact same problem, and the solution suggested by theBrownCoder worked perfectly.
For those who cannot find which menu theBrownCoder is referring to, go to File > Settings > Project: "Title of Project" > Project Structure.
It is in the dropdown of Project in Settings where you can also select your Python interpreter.
It might be the file type.
Right click, Override File Type.
I had this issue with a text file and it's copy, only the first one would use #TODO

Open program files in the Firefox browser window

I wanted to open the get-pip.py file in a new tab so that I could view it, but in Firefox, unlike Chrome, I cannot find a way to view code in a tab with an odd extension. When clicking on the code it asks if I want to download it, but I don't want to.
When I selected Firefox as the default program to open it (hoping it would just treat it like a text file or something, the same way Chrome handles odd extensions like .new) new tabs kept opening like a runaway freight train! It was difficult to get it under control and salvage my session.
Does anyone know how I may modify Firefox so that it will treat extensions like .py as a text file and open it in a new tab?
My version of your problem was solved like so: (on Linux)
cp /etc/mime.types ~/.mime.types # Note the dot in front of .mime
Edit ~/.mime.types, and comment out or delete everything but this:
text/plain asc txt text pot brf srt lua py
Add whatever file types you want to force as text/plain. In the above example, I added lua and py, they were not in the original /etc/mime.types.
Restart Firefox.
Note that this is for all apps that look at that/those files, not just Firefox. For example, if you run a web server, depending on the server, it may also affect that. This is why I did it in my home dir rather than /etc.
How I figured it out:
about:config
mime
This shows three settings:
helpers.global_mime_types_file /etc/mime.types
helpers.private_mime_types_file ~/.mime.types
plugin.java.mime application/x-java-vm
In my case I did not have the private file, so I did the copy/edit/restart as above.
Also Note: I can't get this to work for C files.

Pycharm change Identifier Name where ever it has been used automatically if i change it where it has been defined

I am using Pycharm professional edition for my Python and Django project.
Is there anything in pycharm so that whenever i change the Varibale name/Function name/class name where it has been defined in the middle of my project. It will automatically changes the name wherever it has been referenced in a project with multiple files.
So that i dont have to check manually where it is used and change it accordingly.
Any suggestion please suggest.
Right click -> refactor -> rename
Then you get a dialog that will preview the changes for you.
Very slick.

Categories

Resources