-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
draft for path and path_list #513
draft for path and path_list #513
Conversation
this is working: echo "/abc/def/gh.txt:/xyz/uvw/ab.app" \
| jc --path-list -p [
{
"url": "/abc/def/gh.txt",
"scheme": null,
"netloc": null,
"path": "/abc/def/gh.txt",
"parent": "/abc/def",
"filename": "gh.txt",
"stem": "gh",
"extension": "txt",
"path_list": [
"abc",
"def",
"gh.txt"
],
"query": null,
"query_obj": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null,
"encoded": {
"url": "/abc/def/gh.txt",
"scheme": null,
"netloc": null,
"path": "/abc/def/gh.txt",
"parent": "/abc/def",
"filename": "gh.txt",
"stem": "gh",
"extension": "txt",
"path_list": [
"abc",
"def",
"gh.txt"
],
"query": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null
},
"decoded": {
"url": "/abc/def/gh.txt",
"scheme": null,
"netloc": null,
"path": "/abc/def/gh.txt",
"parent": "/abc/def",
"filename": "gh.txt",
"stem": "gh",
"extension": "txt",
"path_list": [
"abc",
"def",
"gh.txt"
],
"query": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null
}
},
{
"url": "/xyz/uvw/ab.app",
"scheme": null,
"netloc": null,
"path": "/xyz/uvw/ab.app",
"parent": "/xyz/uvw",
"filename": "ab.app",
"stem": "ab",
"extension": "app",
"path_list": [
"xyz",
"uvw",
"ab.app"
],
"query": null,
"query_obj": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null,
"encoded": {
"url": "/xyz/uvw/ab.app",
"scheme": null,
"netloc": null,
"path": "/xyz/uvw/ab.app",
"parent": "/xyz/uvw",
"filename": "ab.app",
"stem": "ab",
"extension": "app",
"path_list": [
"xyz",
"uvw",
"ab.app"
],
"query": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null
},
"decoded": {
"url": "/xyz/uvw/ab.app",
"scheme": null,
"netloc": null,
"path": "/xyz/uvw/ab.app",
"parent": "/xyz/uvw",
"filename": "ab.app",
"stem": "ab",
"extension": "app",
"path_list": [
"xyz",
"uvw",
"ab.app"
],
"query": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null
}
}
] slurp this is also working: echo "/abc/def/gh.txt:/xyz/uvw/ab.app\n/def/hij/klm.txt:/efe/app.txt" \
| jc --path-list -p -s | jq ".[][] .path"
"/abc/def/gh.txt"
"/xyz/uvw/ab.app"
"/def/hij/klm.txt"
"/efe/app.txt" echo "/abc/def/gh.txt:/xyz/uvw/ab.app\n/def/hij/klm.txt:/efe/app.txt" \
| jc --path-list -p -s [
[
{
"url": "/abc/def/gh.txt",
"scheme": null,
"netloc": null,
"path": "/abc/def/gh.txt",
"parent": "/abc/def",
"filename": "gh.txt",
"stem": "gh",
"extension": "txt",
"path_list": [
"abc",
"def",
"gh.txt"
],
"query": null,
"query_obj": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null,
"encoded": {
"url": "/abc/def/gh.txt",
"scheme": null,
"netloc": null,
"path": "/abc/def/gh.txt",
"parent": "/abc/def",
"filename": "gh.txt",
"stem": "gh",
"extension": "txt",
"path_list": [
"abc",
"def",
"gh.txt"
],
"query": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null
},
"decoded": {
"url": "/abc/def/gh.txt",
"scheme": null,
"netloc": null,
"path": "/abc/def/gh.txt",
"parent": "/abc/def",
"filename": "gh.txt",
"stem": "gh",
"extension": "txt",
"path_list": [
"abc",
"def",
"gh.txt"
],
"query": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null
}
},
{
"url": "/xyz/uvw/ab.app",
"scheme": null,
"netloc": null,
"path": "/xyz/uvw/ab.app",
"parent": "/xyz/uvw",
"filename": "ab.app",
"stem": "ab",
"extension": "app",
"path_list": [
"xyz",
"uvw",
"ab.app"
],
"query": null,
"query_obj": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null,
"encoded": {
"url": "/xyz/uvw/ab.app",
"scheme": null,
"netloc": null,
"path": "/xyz/uvw/ab.app",
"parent": "/xyz/uvw",
"filename": "ab.app",
"stem": "ab",
"extension": "app",
"path_list": [
"xyz",
"uvw",
"ab.app"
],
"query": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null
},
"decoded": {
"url": "/xyz/uvw/ab.app",
"scheme": null,
"netloc": null,
"path": "/xyz/uvw/ab.app",
"parent": "/xyz/uvw",
"filename": "ab.app",
"stem": "ab",
"extension": "app",
"path_list": [
"xyz",
"uvw",
"ab.app"
],
"query": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null
}
}
],
[
{
"url": "/def/hij/klm.txt",
"scheme": null,
"netloc": null,
"path": "/def/hij/klm.txt",
"parent": "/def/hij",
"filename": "klm.txt",
"stem": "klm",
"extension": "txt",
"path_list": [
"def",
"hij",
"klm.txt"
],
"query": null,
"query_obj": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null,
"encoded": {
"url": "/def/hij/klm.txt",
"scheme": null,
"netloc": null,
"path": "/def/hij/klm.txt",
"parent": "/def/hij",
"filename": "klm.txt",
"stem": "klm",
"extension": "txt",
"path_list": [
"def",
"hij",
"klm.txt"
],
"query": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null
},
"decoded": {
"url": "/def/hij/klm.txt",
"scheme": null,
"netloc": null,
"path": "/def/hij/klm.txt",
"parent": "/def/hij",
"filename": "klm.txt",
"stem": "klm",
"extension": "txt",
"path_list": [
"def",
"hij",
"klm.txt"
],
"query": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null
}
},
{
"url": "/efe/app.txt",
"scheme": null,
"netloc": null,
"path": "/efe/app.txt",
"parent": "/efe",
"filename": "app.txt",
"stem": "app",
"extension": "txt",
"path_list": [
"efe",
"app.txt"
],
"query": null,
"query_obj": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null,
"encoded": {
"url": "/efe/app.txt",
"scheme": null,
"netloc": null,
"path": "/efe/app.txt",
"parent": "/efe",
"filename": "app.txt",
"stem": "app",
"extension": "txt",
"path_list": [
"efe",
"app.txt"
],
"query": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null
},
"decoded": {
"url": "/efe/app.txt",
"scheme": null,
"netloc": null,
"path": "/efe/app.txt",
"parent": "/efe",
"filename": "app.txt",
"stem": "app",
"extension": "txt",
"path_list": [
"efe",
"app.txt"
],
"query": null,
"fragment": null,
"username": null,
"password": null,
"hostname": null,
"port": null
}
}
]
]
|
I know the |
should it makes sense to have an did we need [
{
"path": "/abc/def/gh.txt",
"parent": "/abc/def",
"filename": "gh.txt",
"stem": "gh",
"extension": "txt",
"path_list": [
"abc",
"def",
"gh.txt"
],
"encoded": {
"path": "/abc/def/gh.txt",
"parent": "/abc/def",
"filename": "gh.txt",
"stem": "gh",
"extension": "txt",
"path_list": [
"abc",
"def",
"gh.txt"
],
},
"decoded": {
"path": "/abc/def/gh.txt",
"parent": "/abc/def",
"filename": "gh.txt",
"stem": "gh",
"extension": "txt",
"path_list": [
"abc",
"def",
"gh.txt"
],
}
}
] |
Edge case:
|
73bbfac: added |
Edge Case:
echo "./path/to/file.txt" | jc --path-list -p note: the [
{
"path": "./path/to/file.txt",
"parent": "path/to",
"filename": "file.txt",
"stem": "file",
"extension": "txt",
"path_list": [
".path",
"to",
"file.txt"
]
}
]
the same with echo "~/path/to/file.txt" | jc --path-list -p [
{
"path": "~/path/to/file.txt",
"parent": "~/path/to",
"filename": "file.txt",
"stem": "file",
"extension": "txt",
"path_list": [
"~path",
"to",
"file.txt"
]
}
] |
jc/parsers/path_list.py
Outdated
raw_output: List[Dict] = [] | ||
if jc.utils.has_data(data): | ||
for line in data.split(":"): | ||
parsed_line = url.parse( | ||
line, | ||
raw=raw, | ||
quiet=quiet | ||
) | ||
raw_output.append(parsed_line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion from chatgpt - it is shorter but is it better readable?
raw_output: List[Dict] = [] | |
if jc.utils.has_data(data): | |
for line in data.split(":"): | |
parsed_line = url.parse( | |
line, | |
raw=raw, | |
quiet=quiet | |
) | |
raw_output.append(parsed_line) | |
raw_output = [ | |
url.parse(line, raw=raw, quiet=quiet) | |
for line in data.split(":") | |
if jc.utils.has_data(data) | |
] |
The more I consider it, the more it seems preferable to create a |
I agree. I'm also curious how this parser would/could work with |
I anticipate that the I'm uncertain whether a A workaround involves eliminating the nested array using echo "/abc/def/gh.txt:/xyz/uvw/ab.app\n/def/hij/klm.txt:/efe/app.txt" \
| jc --path-list -p -s | jq "[ .[] .[] ]" [
{
"path": "/abc/def/gh.txt",
"parent": "/abc/def",
"filename": "gh.txt",
"stem": "gh",
"extension": "txt",
"path_list": [
"abc",
"def",
"gh.txt"
]
},
{
"path": "/xyz/uvw/ab.app",
"parent": "/xyz/uvw",
"filename": "ab.app",
"stem": "ab",
"extension": "app",
"path_list": [
"xyz",
"uvw",
"ab.app"
]
},
{
"path": "/def/hij/klm.txt",
"parent": "/def/hij",
"filename": "klm.txt",
"stem": "klm",
"extension": "txt",
"path_list": [
"def",
"hij",
"klm.txt"
]
},
{
"path": "/efe/app.txt",
"parent": "/efe",
"filename": "app.txt",
"stem": "app",
"extension": "txt",
"path_list": [
"efe",
"app.txt"
]
}
] |
On Windows systems, paths are parsed using |
I did not know POSIX before - should it be named better |
Also, if a parser returns a
👍 |
I added some windows path checks in 66830e4 Note: On mac I need to use single quotes otherwise the by echo "C:\\\\Windows\\\\Program Files\\\\xfolder\\\\file.txt" | jc --path -p
echo 'C:\\Windows\\Program Files\\xfolder\\file.txt' | jc --path -p This are the drive and root values for windows:
|
Fun fact: |
fun fact after this PR find . -type f -name '*.json' | wc -l
1000 🎉 |
Will you be ready for me to merge this soon? |
yes it is ready to merge |
I expect update to the docs at |
Looks nice, thanks! |
* draft for path_list * updaate doc * add input check * fix types * fix schema: add missing properties * add _process * fix _process docs * refactor: extract path.py parser * swap order of names alphabetically * documentation and comments * path parser: add early return for nodata * path and path-list parser: add test and fixtures * typo in file name * add early return for nodata * add test and fixtures * typo in file name * rename fixtures * rename fixtures * refactor to pathlib.Path * failing on windows - use PurePosixPath * changed the way to strip dot from suffix * add POSIX to path * test commit to see results on windows is failing * test commit to see results on windows is failing * add windows path detection * somehow Path not like the newline from input line * add test with more items * remove debug print * wrap test loops into into subTest * remove print statements * add path and path-list to CHANGELOG --------- Co-authored-by: Kelly Brazil <[email protected]>
* draft for path_list * updaate doc * add input check * fix types * fix schema: add missing properties * add _process * fix _process docs * refactor: extract path.py parser * swap order of names alphabetically * documentation and comments * path parser: add early return for nodata * path and path-list parser: add test and fixtures * typo in file name * add early return for nodata * add test and fixtures * typo in file name * rename fixtures * rename fixtures * refactor to pathlib.Path * failing on windows - use PurePosixPath * changed the way to strip dot from suffix * add POSIX to path * test commit to see results on windows is failing * test commit to see results on windows is failing * add windows path detection * somehow Path not like the newline from input line * add test with more items * remove debug print * wrap test loops into into subTest * remove print statements * add path and path-list to CHANGELOG --------- Co-authored-by: Kelly Brazil <[email protected]>
just to play around how to implement
--path-list
TODO:
readmegen.py
)pathlib