Skip to content
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

Automatic expanduser for path #915

Closed
BoPeng opened this issue Mar 7, 2018 · 4 comments
Closed

Automatic expanduser for path #915

BoPeng opened this issue Mar 7, 2018 · 4 comments

Comments

@BoPeng
Copy link
Contributor

BoPeng commented Mar 7, 2018

Our path type is derived from pathlib.Path with additional format operators, and like Path, we will have to use expanduser() to expand ~:

>>> path(os.path.expanduser('~/.bashrc')).exists()
True
>>> path('~/.bashrc').exists()
False
>>> path('~/.bashrc').expanduser().exists()
True

Since path is a SoS type and SoS automatically expand ~, I believe we should treat

path('~/.bashrc').exists()

as

path('~/.bashrc').expanduser().exists()

The problem is that we will have to redefine many functions such as exists, is_dir, is_file, ..., and it does not look right if we automatically change the string representation of input path

>>> str(path('~/.bashrc').expanduser())
'/Users/bpeng1/.bashrc'
>>> str(path('~/.bashrc'))
'~/.bashrc'
@BoPeng
Copy link
Contributor Author

BoPeng commented Mar 7, 2018

>>> file_target('~/.bashrc').exists()
True
>>> path('~/.bashrc').exists()
True
>>> paths('~/.bashrc').exists()
True

However, this makes the paths() trick no longer safe to use in case the passed string starts with ~,

BoPeng pushed a commit that referenced this issue Mar 7, 2018
@BoPeng BoPeng closed this as completed Mar 8, 2018
BoPeng pushed a commit that referenced this issue Mar 15, 2018
BoPeng pushed a commit to vatlab/sos-docs that referenced this issue Mar 15, 2018
@ericchansen
Copy link

ericchansen commented Mar 25, 2022

How does this work now? Is there a way to automatically do this?

@BoPeng
Copy link
Contributor Author

BoPeng commented Mar 29, 2022

This is already the case. With the following code,

print(path('~/Download'))
sos run test.sos -v1

prints the expanded path.

@ericchansen
Copy link

I'm sorry, I should be in the pathlib GitHub. Thanks @BoPeng.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants