win_path: Add option or function to append a value to PATH without enforcing index
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
Thanks for the request! Definitely will be useful.
@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, please feel free to work on this. Thanks!
@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 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!
@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.
Implemented via pull request #9642. Default is now index=None with no index checking unless index is provided.
Thanks @Geo23589!