px icon indicating copy to clipboard operation
px copied to clipboard

v0.9.2 - px.ini created in the directory of process caller and not in the one of px.exe

Open beaulieukevin opened this issue 10 months ago • 3 comments

I have automated the configuration of px through a PowerShell script.

$startParams = @{
            FilePath     = "C:\mypath\px\px.exe"
            ArgumentList = "--server=$proxy", "--listen=$localHost", "--port=$localPort", "--noproxy=$noProxy", "--workers=4", "--save"
            WindowStyle = "Hidden"
        }

        Start-Process @startParams | Out-Null

Px generates a px.ini file but in the directory from where the PowerShell script has been launched. For example if the powsershell script is executed from the C:\anotherdirectory the px.ini file will be created in the anotherdirectory and not in the intended C:\mypath\px.

I see you are using the getcwd function to create px.ini file: https://github.com/genotrance/px/blob/07b6668a2962011bd61fc31c3c9f37ae5e2f5111/px/config.py#L720C9-L732C40

Is it the expected behavior?

PS: I did a workaround by adding the WorkingDirectory path option to override the working directory of the Start-Process command.

beaulieukevin avatar Apr 05 '24 14:04 beaulieukevin

The px.ini configuration loading order was changed in v0.9.0:

  • Changed loading order of px.ini - from CLI flag first, environment next, working directory and finally from the Px directory

You could also add the --config flag to point to another location.

There is an open bug though that needs to be fixed: #213

genotrance avatar Apr 05 '24 15:04 genotrance

Wouldn't be better in term of UX to create a px.ini in the directory of the px.exe while using --save option? And to use another option to override the default location mentioned previously?

beaulieukevin avatar Apr 08 '24 13:04 beaulieukevin

Problem is that binary can be in a read/only or admin location whereas config files are user specific. Working directory was preferred for that reason.

It is a change from legacy behavior.

Related: https://github.com/genotrance/px/issues/189.

genotrance avatar Sep 11 '24 18:09 genotrance