salt icon indicating copy to clipboard operation
salt copied to clipboard

win_path: Add option or function to append a value to PATH without enforcing index

Open otrempe opened this issue 13 years ago • 8 comments

Let's say you have multiple win_path states for which you just want to append to the existing PATH and don't care to enforce that it is the last value at every highstate run, for example:

C:\Python27 C:\Python27\Scripts C:\gnuwin32\bin

Using index: -1 for all of them will add these at the end of PATH in the first run. In all subsequent runs, each of them will be moved again at the end of PATH.

Using higher index values can give problems because you don't know how many PATH values are already set and you may start to mess with windows critical path values located at the beginning of PATH like:

c:\windows\system32;c:\windows;c:\windows\system32\wbem

Having the possibility to just append the value to PATH if it isn't already in PATH would be great. It could be either an option like 'enforce_index: false' in win_path.exists or simply a new function like win_path.append

otrempe avatar Nov 06 '13 17:11 otrempe

Thanks for the request! Definitely will be useful.

basepi avatar Nov 06 '13 23:11 basepi

@basepi Is anyone working on this? If not, I could fix it. @otrempe 's suggestion seems appropriate. I could add something like enforce_index or ignore_index.

Geo23589 avatar Jan 02 '14 16:01 Geo23589

@Geo23589, please feel free to work on this. Thanks!

UtahDave avatar Jan 02 '14 16:01 UtahDave

@Geo23589,

Maybe instead of adding a new argument, using index=None could be an option.

Currently, the default value is index=0, so it would not break backward compatibility and it would not require a new argument.

otrempe avatar Jan 03 '14 20:01 otrempe

@otrempe I thought about that. The current implementation is that if they don't provide an index, it'll always be at the front of the path. If we change to index=None, then conceivably, someone who never placed an index value on it, and is counting on their directory being at the beginning of the path [since we told them default is 0], could get a surprise. I also think ignore_index would be more obvious as a self-documenting feature. Thanks for your help on this!

Geo23589 avatar Jan 06 '14 03:01 Geo23589

@otrempe,

On the other hand, having a default of index=0 bothers me because I don't like the idea of putting search directories before \windows\system and \windows\system32 without having a really good reason to do so.

Maybe index=None would be a good default, appending the directory.

Geo23589 avatar Jan 06 '14 06:01 Geo23589

Implemented via pull request #9642. Default is now index=None with no index checking unless index is provided.

Geo23589 avatar Jan 11 '14 17:01 Geo23589

Thanks @Geo23589!

otrempe avatar Jan 13 '14 22:01 otrempe