sourcery icon indicating copy to clipboard operation
sourcery copied to clipboard

Default python version code action to create project-level config rather than user-level

Open pzelnip opened this issue 2 years ago • 4 comments

Issue description or question

I have to work on a project that is still Python 2 for work, but all the other projects I work on are Python 3.8 or better. However, when I open up the Python 2 project in VS Code I get refactoring suggestions from Sourcery showing things like switch .format() calls to f-strings, or use the walrus operator, etc, which is not helpful. I can turn those off by picking "Do Not Show Proposals requiring 3.8 or better" in the Quick Fix menu, but then that seems to disable 3.8+ suggestions for all projects I open in VS Code.

I just want to disable the Python 3 suggestions in this single project, not all projects I open.

Sourcery Version

Sourcery v0.10.3 (according to the VS Code extension page)

Code editor or IDE name and version

Version: 1.65.0 Commit: b5205cc8eb4fbaa726835538cd82372cc0222d43 Date: 2022-03-02T11:11:20.886Z (5 days ago) Electron: 13.5.2 Chromium: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0

OS name and version

OSX: Darwin x64 19.6.0

pzelnip avatar Mar 07 '22 20:03 pzelnip

Hi @pzelnip, thanks for opening this issue!

I totally agree, setting a maximum Python version should be project-specific. I added this to our roadmap.

The good news is that you can solve this already by manually creating a .sourcery.yaml file in your Python 2 project with the following contents:

refactor:
  python_version: '3.3'

If .sourcery.yaml already exists, just make sure that the python_version field is included in refactor with an appropriate value.

Please let me know if this works for you.

ruancomelli avatar Mar 08 '22 18:03 ruancomelli

That does work for me, thanks!

pzelnip avatar Mar 09 '22 18:03 pzelnip

Alongside .sourcery.yaml, the second place sourcery could look for settings could be PEP 518's pyproject.toml perhaps?

diceroll123 avatar Mar 12 '22 04:03 diceroll123

@diceroll123 that's definitely something we want to have in the future! Actually, there's already an open issue to track this enhancement proposal: https://github.com/sourcery-ai/sourcery/issues/159.

ruancomelli avatar Mar 14 '22 12:03 ruancomelli