Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On macOS "Save as..." always defaults to saving with ".R" extension rather than ".py" #22248

Closed
9 of 10 tasks
battaglia01 opened this issue Jul 10, 2024 · 14 comments
Closed
9 of 10 tasks

Comments

@battaglia01
Copy link
Contributor

battaglia01 commented Jul 10, 2024

Issue Report Checklist

  • Searched the issues page for similar reports
  • Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • Reproduced the issue after updating with conda update spyder (or pip, if not using Anaconda)
  • Could not reproduce inside jupyter qtconsole (if console-related)
  • Tried basic troubleshooting (if a bug/error)
    • Restarted Spyder
    • Reset preferences with spyder --reset
    • Reinstalled the latest version of Anaconda
    • Tried the other applicable steps from the Troubleshooting Guide
  • Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

Every time I save a file, it always defaults to saving it as .R rather than .py, even though .py is the first extension in the filter being passed to Qt.

What steps reproduce the problem?

  1. Try to save a file
  2. It defaults to .R
  3. Even if you're calling "Save As..." on an existing python file, it still defaults to .R

What is the expected output? What do you see instead?

It should save as .py by default particularly if the existing file name is already .py

Thanks Mike, Is There A One-Line Solution?

There sure is! Look here on Line 133:

https://github.com/spyder-ide/spyder/blob/bb6d9301c9356162970e9ea7043bd4287e1ddb5b/spyder/config/utils.py#L119C1-L133C45

Change this

    favorite_exts = ['.py', '.R', '.jl', '.ipynb', '.md', '.pyw', '.pyx',
                     '.c', '.cpp', '.json', '.dat', '.csv', '.tsv', '.txt',
                     '.ini', '.html', '.js', '.h', '.bat']

to this:

    favorite_exts = ['', '.py', '.R', '.jl', '.ipynb', '.md', '.pyw', '.pyx',
                     '.c', '.cpp', '.json', '.dat', '.csv', '.tsv', '.txt',
                     '.ini', '.html', '.js', '.h', '.bat']

This solves the problem. For whatever reason, on Mac, it seems to read the second extension as default, maybe because it expects the first to be *.* or something. Not sure if the same behavior on all platforms - if so, you may want to do this only if it's Mac.

Versions

Spyder 5.5.5
Python 3.11.9 64-bit | Qt 5.15.8 | PyQt5 5.15.9 | macOS 14.5 (arm64)

Dependencies

# Mandatory:
applaunchservices >=0.3.0        :  0.3.0 (OK)
atomicwrites >=1.2.0             :  1.4.1 (OK)
chardet >=2.0.0                  :  5.2.0 (OK)
cloudpickle >=0.5.0              :  3.0.0 (OK)
cookiecutter >=1.6.0             :  2.6.0 (OK)
diff_match_patch >=20181111      :  20230430 (OK)
intervaltree >=3.0.2             :  3.1.0 (OK)
IPython >=8.13.0,<9.0.0,!=8.17.1 :  8.26.0 (OK)
jedi >=0.17.2,<0.20.0            :  0.19.1 (OK)
jellyfish >=0.7                  :  1.0.4 (OK)
jsonschema >=3.2.0               :  4.23.0 (OK)
keyring >=17.0.0                 :  25.2.1 (OK)
nbconvert >=4.0                  :  7.16.4 (OK)
numpydoc >=0.6.0                 :  1.7.0 (OK)
parso >=0.7.0,<0.9.0             :  0.8.4 (OK)
pexpect >=4.4.0                  :  4.9.0 (OK)
pickleshare >=0.4                :  0.7.5 (OK)
psutil >=5.3                     :  6.0.0 (OK)
pygments >=2.0                   :  2.18.0 (OK)
pylint >=3.1,<4                  :  3.2.5 (OK)
pylint_venv >=3.0.2              :  3.0.3 (OK)
pyls_spyder >=0.4.0              :  0.4.0 (OK)
pylsp >=1.11.0,<1.12.0           :  1.11.0 (OK)
pylsp_black >=2.0.0,<3.0.0       :  2.0.0 (OK)
qdarkstyle >=3.2.0,<3.3.0        :  3.2.3 (OK)
qstylizer >=0.2.2                :  0.2.3 (OK)
qtawesome >=1.3.1,<1.4.0         :  1.3.1 (OK)
qtconsole >=5.5.1,<5.6.0         :  5.5.2 (OK)
qtpy >=2.1.0                     :  2.4.1 (OK)
rtree >=0.9.7                    :  1.3.0 (OK)
setuptools >=49.6.0              :  70.2.0 (OK)
sphinx >=0.6.6                   :  7.3.7 (OK)
spyder_kernels >=2.5.2,<2.6.0    :  2.5.2 (OK)
textdistance >=4.2.0             :  4.6.2 (OK)
three_merge >=0.1.1              :  0.1.1 (OK)
watchdog >=0.10.3                :  4.0.1 (OK)
zmq >=24.0.0                     :  26.0.3 (OK)

# Optional:
cython >=0.21                    :  None (NOK)
matplotlib >=3.0.0               :  None (NOK)
numpy >=1.7                      :  None (NOK)
pandas >=1.1.1                   :  None (NOK)
scipy >=0.17.0                   :  None (NOK)
sympy >=0.7.3                    :  None (NOK)
@battaglia01
Copy link
Contributor Author

battaglia01 commented Jul 10, 2024

Before:
image

After:
image

@alishaexe
Copy link

I'm also having this issue, and I'm not able to fix it. Do you know what the file name in config is that needs to be edited to fix it?

@battaglia01
Copy link
Contributor Author

@alishaexe
Copy link

I'm probably being dumb but I can't find that file in any of the system folders, and then I tried saving the file with the changes and spyder still saves as .py.R

@battaglia01
Copy link
Contributor Author

What do you mean you can't find the file but you saved it with the changes?

@alishaexe
Copy link

I downloaded it from GitHub and saved it into the config folder. There wasn't an existing file called utilis.py if there was supposed to be one.
But even after downloading the file and making the change I still get .py.R

@shreyasshaurav
Copy link

I downloaded it from GitHub and saved it into the config folder. There wasn't an existing file called utilis.py if there was supposed to be one. But even after downloading the file and making the change I still get .py.R

Hi @alishaexe In case you are still facing the issue.
it would be best if you traverse this path from the command line: /Applications/Spyder.app/Contents/Resources/lib/python3.10/spyder/config
and open the utils.py file and edit it as suggested.

@schmoelder
Copy link

schmoelder commented Jul 14, 2024

It may be unrelated, but for the opening dialog, the default in Files of type field seems to be "none" (i.e. it appears empty) which means, I don't see any files at all, only directories. I always have to manually select "Python files" or "All files" so see the content of the current working directory.

Edit: Actually, I can see .md, .toml, .cfg, and .ipynb files. So it's actually just the python files, I'm missing. Also, I'm not actually on MacOS but on Ubuntu 24.04, so I can open another issue, but the issue just seemed to be quite similar...

@ccordoba12
Copy link
Member

Hey everyone, thanks for the feedback! We'll take a look at this one for 5.5.6, to be released shortly.

@ccordoba12
Copy link
Member

@mrclary, could you take a look at this one? It doesn't seem to hard to fix and only affects Mac users.

@ccordoba12 ccordoba12 changed the title On macOS Sonoma, "Save as..." always defaults to saving with ".R" extension rather than ".py" On macOS "Save as..." always defaults to saving with ".R" extension rather than ".py" Jul 18, 2024
@mrclary
Copy link
Contributor

mrclary commented Jul 18, 2024

I would guess that #22248 (comment) is related; I've noticed this as well, but haven't yet taken the time to track down when this first manifested.

I'm wondering if this could be related to Qt. Nevertheless, I'll investigate further and see what I find.

@mrclary
Copy link
Contributor

mrclary commented Jul 19, 2024

It seems the underlying issue is related to the pygments lexer ('Mojo', ('mojo', '🔥'), ('*.mojo', '*.🔥'), ('text/x-mojo', 'application/x-mojo')). The presence of the unconventional extension '*.🔥' in the QFileDialog filter causes the issue. I don't know why this extension causes the first extension in the list to be ignored. But it also causes the list of extensions to appear in the filter drop-down menu, which is also undesireable:
Screenshot 2024-07-18 at 5 31 41 PM

@AbhilashAradhya
Copy link

Is the issue resolved? Any updates? Can I use Spyder allowing the .R extension to normally write and run python files in the meantime?

@mrclary
Copy link
Contributor

mrclary commented Jul 21, 2024

Is the issue resolved? Any updates? Can I use Spyder allowing the .R extension to normally write and run python files in the meantime?

@AbhilashAradhya, I've submitted a PR that should resolve this issue for Spyder 5.5.6. Until then, you will need to explicitly select the "All files" option at the bottom of the file filter dropdown menu and manually type the .py extension. Sorry for any inconvenience.

I think this issue may have been introduced with the update from PyQt 5.12 to 5.15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants