Repository navigation
Make --add-data and --add-binary path separators OS independent - #6724
Conversation
|
@rpodgorny, @johnthagen, @danyeaw, @Iniquitatis, @RaSan147 Any votes for |
|
Linking to #6320 |
|
I don't have a strong opinion as long as it can work cross platform without modification. The purest in me thinks there should be a single, universal character that is used. |
|
Not voting for colon, since may cause some trouble since C:/ as a permanent path or relative path. |
i agree with @johnthagen -> as long as it works on all platforms without modification, i don't really care. (btw, as a unix-y guy, i'd prefer : but @RaSan147 is correct about the c: case) ...oh, and also, please try to avoid playing with the backslash at all cost - it's a real pain in the ass to work with, especially in nested shells etc. |
|
Also checked on SO, |
|
well, there's always another option, the "sed" way -> specify the separator character explicitly... --add-data ":/some/path:/other/path" (as in sed "s/replace_from/replace_to/" or sed "s|replace_from|replace_to|") another option would be to have --add-data-comma, --add-data-semicolon, --add-data-colon etc. |
It's not quite ambiguous. As the drive separator the colon must be followed by either a # Split by colons not immediately followed by a slash.
source, dest = re.split(r":(?![/\\])", input`)does do the job. It makes the invalid but understandable case where someone does
The problem is though that they're all valid file names. There aren't a lot of type-able characters that Linux won't let you use. > touch '\\' '=>' ':' ';' '?'
> ls
: ';' '=>' '?' '\'That's why I thought |
|
Just use Very 1st slash means permanent path on linux, without it, it will be counted as relative path. Windows got c:/path... |
please NO! multiple slashes are valid path in unix systems -> /home/radek = /home///////radek also, the path may be calculated programatically and several consecutive slashes are often a valid result of such calculations... |
That's a news to me, sorry, ignore my opinion 😥 |
|
Does the top half of this not make everyone comfortable with using
Just to give an example of what @rpodgorny is saying - this happens on macOS but not Linux: |
|
I think supporting both ; and : would be ideal. 👍 |
|
If this isn't settled yet - why not make it Python syntax, for a Python tool? Dict: --add-data "{'c:\\my\\folder\\and\\file.ext': 'target\\folder'}" # Windows style, enclosed in quotes, need escapted backslashes?
--add-data "{'~/repos/my/folder/and/file.ext': 'target/folder'}" # unix style
--add-data {'source.file':'target_folder'} # if there are no spaces, don't need enclosing quotesOr List: --add-data ['source.file','target_folder']
--add-data "['source.file','target_folder']"Might be disadvantages to this from the quotes (need an extra layer for the command line parsing) and slashes - though if it can always accept fore or back slashes, regardless of platform, and with the ability to use both single and double quotes, it should be good. |
|
May I ask what the objections are to my original suggestion of splitting it like |
Just the compatibility for me - in particular that using the old syntax with the new version or vice versa will i almost no cases lead to an error message that correctly identifies where the user went wrong.
I'm not sure that it would anymore. #6660 takes away the need to split |
If the old style is kept for compatibility, then the parser would just need to see if there is 1 argument (old style) or 2 (new style) to the flag - if the file argument is required and is always a single argument, then that should be possible. |
Not quite. The whole expression will always have to be enclosed in quotes on unix (or even PowerShell) to stop the string's quotes from being evaluated causing |
|
At this point, I'm starting to think that breaking the compatibility and having But if we were to retain compatibility for old one-argument syntax, we're going to start running into ambiguities: and to properly interpret those, we'd need to first interpret the argument as single one, and see if it splits into two under the old rules. Which gets complicated even further, because under the two-argument form, the path separator character would actually be a valid one... |
|
I should also note that if we did go with splitting it into 2 arguments then that would get released with version 5, which is a major version change, where there will definitely be other breaking changes. |
Again, not many though. |
My point is that it's a major release, breaking changes are ok. You can't really complain about a breaking change in a major release. |
|
https://en.wikipedia.org/wiki/G%C3%B6del%27s_incompleteness_theorems is applicable here. You want to be able to express ANY sequence of characters BUT you have to split them into sub-sequences using only characters in the set of characters. The ONLY solution is to create new characters which are outside the set of characters but which can be expressed by the set of characters. A lot of people here are struggling with inventing a new system for delimiting path components. Rather than invent a new one, why not stick with an already-invented one? Use \ to quote characters, including : and \ itself. When you're done, you've got a Windows path if you interpret the backslashes, and a Unix path if you turn them into forward slashes. Is this ugly? Sure, but you already dug that ditch when you wanted to have a meta-character. May I suggest something less ugly? Specify paths as a list, possibly using "/foo/bar/piffle.dat".split("/") for easier reading. Then, at the last moment, you os.pathsep.join(pathname). |
6aaeaea to
76d0d19
Compare
|
Just to summarise what we eventually decided:
Because |
76d0d19 to
a43108f
Compare
…ip ci] `--add-data=source:dest` is now allowed (and preferred) on Windows as well as UNIX. On Windows, the prior behaviour of using `;` is still allowed to avoid breaking backwards compatibility. Special handling is given to ignore colons at the start of the string, preceded by a single letter and followed by a slash so as to avoid splitting `--add-data=C:\foo\bar:dest` in the wrong place. Because `:` is an illegal character in Windows filenames, this avoids being a breaking change since no Windows users could have been `:` literally.
a43108f to
622429a
Compare
I can't make up my mind which separator to use. I've done a commit for both. I don't like the look of the syntax for
=>.--add-data="foo=>bar"looks like something you'd find in a perl script. And in either case, I'm not sure if allowing\escaping of colons is a good idea. I think we should be providing a complete syntax but it makes something like--add-data=C:\some\folder\:.invalid because the colon is treated literally. Any thoughts?