ruff icon indicating copy to clipboard operation
ruff copied to clipboard

[Windows] Issues when running as a module

Open andriilahuta opened this issue 2 years ago • 3 comments

If the interpreter path contains spaces (e.g. C:\Program Files\Python311\python.exe), then ruff produces the following output: Files\Python311\Scripts\ruff:0:0: E902 The system cannot find the path specified and exits with code 1.

Replacing

sys.exit(os.spawnv(os.P_WAIT, ruff, [ruff, *sys.argv[1:]]))

with

sys.exit(subprocess.call([ruff, *sys.argv[1:]]))

in __main__.py seems to resolve the issue.

andriilahuta avatar Nov 20 '22 16:11 andriilahuta

@andriilahuta Could you confirm this is still an issue? We've added windows testing in the meantime, so if it's still an issue we should extend our testing suite (and fix it).

sbrugman avatar Jan 30 '23 12:01 sbrugman

@sbrugman Still an issue.
To reproduce, you can run ruff like this: "C:\Program Files\Python311\python.exe" -m ruff ..
Replacing os.spawnv with subprocess.call fixes the issue for me.

andriilahuta avatar Jan 30 '23 16:01 andriilahuta

Suppose we could add this to the maturin test stage in the CI pipeline. Needs some testing to ensure there are no regressions.

sbrugman avatar Jan 31 '23 22:01 sbrugman

Coming in to confirm this is happening for me too. Synced the vscode setting from my macbook (where ruff runs fine), to my windows PC and when ruff is set to handle source.fixAll, its actually wiping the python file on save.

Replacing the file with

[
    {
        "code": "E902",
        "message": "The system cannot find the file specified. (os error 2)",
        "fix": null,
        "location": {"row": 1, "column": 1},
        "end_location": {"row": 1, "column": 1},
        "filename": "c:\\Users\\rhino\\Downloads\\folder with spaces in it\\-",
    },
    {
        "code": "E902",
        "message": "The system cannot find the file specified. (os error 2)",
        "fix": null,
        "location": {"row": 1, "column": 1},
        "end_location": {"row": 1, "column": 1},
        "filename": "c:\\Users\\rhino\\Downloads\\folder with spaces in it\\line-length = 100",
    },
]

Thankfully, black comes in after and auto corrects the JSON to a Python friendly dict or I'd have been REALLY sad :,)

srhinos avatar Mar 06 '23 09:03 srhinos

Woah, the Python file contents are replaced by that JSON?

charliermarsh avatar Mar 06 '23 13:03 charliermarsh

yeah, super weird interaction!

Running python 3.11 but it might be an issue too with the fact that my Windows PC's installation is syncing settings from my Macbook's with no regard for what that might mean. I can dig into what settings are needed for repro if y'all can't get a repro of the issue down

srhinos avatar Mar 06 '23 13:03 srhinos

We've now implemented this change in #5115, this should also fix your problem. If it doesn't, please feel free to reopen.

konstin avatar Jun 15 '23 18:06 konstin