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

Developer friendly: tell me which root path cannot be opened. #340

Closed
chfw opened this issue Aug 6, 2019 · 11 comments
Closed

Developer friendly: tell me which root path cannot be opened. #340

chfw opened this issue Aug 6, 2019 · 11 comments

Comments

@chfw
Copy link
Contributor

chfw commented Aug 6, 2019

Hi all

It would be very helpful to display the root path, for which osfs cannot open it. I knew you would argue, "please add break point or print it, dude". What I am facing here is: MacOS, Linux and Linux system path here. I do not have always three OS at the same time. If OSFS would be nicely to tell what is the root path, it will save me a lot time in taking the assumed advice: adding break point or print it.

I am sending a PR through.

https://dev.azure.com/moremoban/moban/_build/results?buildId=670

Traceback (most recent call last):
  File "c:\hostedtoolcache\windows\python\3.7.4\x64\lib\site-packages\nose\case.py", line 198, in runTest
    open_fs = opener.open_fs(fs_url, parse_result, writeable, create, cwd)
  File "D:\a\1\s\moban\fs_openers.py", line 68, in open_fs
    osfs = EnhancedOSFS(path, create=create)
  File "c:\hostedtoolcache\windows\python\3.7.4\x64\lib\site-packages\fs\osfs.py", line 140, in __init__
    raise errors.CreateFailed("root path does not exist")
@chfw
Copy link
Contributor Author

chfw commented Aug 6, 2019

Positive result is already showing here:

https://ci.appveyor.com/project/willmcgugan/pyfilesystem2/builds/26516343/job/oot4vwg0m48g3u97

=====================================================================
2079ERROR: test_consume_geturl (tests.test_tempfs.transplant_class.<locals>.C)
2080----------------------------------------------------------------------
2081Traceback (most recent call last):
2082  File "C:\projects\pyfilesystem2\tests\test_osfs.py", line 171, in test_consume_geturl
2083    open_fs(base_dir)
2091    raise errors.CreateFailed("{} does not exist".format(_root_path))
2092fs.errors.CreateFailed: C:\projects\pyfilesystem2\file: does not exist

Where I clearly know what's going on.

@lurch
Copy link
Contributor

lurch commented Aug 6, 2019

It would be very helpful to display the root path, for which osfs cannot open it.

Could you try to explain in more detail what you actually mean, please?

@chfw
Copy link
Contributor Author

chfw commented Aug 6, 2019

fs.errors.CreateFailed: "root path does not exist"

I would like to know what is 'root path' inside the error.

and With the root path printed as below,

fs.errors.CreateFailed: C:\projects\pyfilesystem2\file: does not exist

I know what's going wrong.

@lurch
Copy link
Contributor

lurch commented Aug 7, 2019

Ahhh, I see. But looking at where that error is coming from https://github.com/PyFilesystem/pyfilesystem2/blob/master/fs/osfs.py#L140 it seems that the root_path parameter gets passed directly into the __init__ method https://github.com/PyFilesystem/pyfilesystem2/blob/master/fs/osfs.py#L108 so how do you "not know" what root_path you passed in? Could you give some example code?

@chfw
Copy link
Contributor Author

chfw commented Aug 7, 2019

Example has been give above. From the message of the raised exception, I do not know.

@lurch
Copy link
Contributor

lurch commented Aug 7, 2019

You've given an example of the error message - I was asking for an example of the code leading up to the error message.
I'm not trying to be antagonistic, I'm just trying to understand your use-case better.

@chfw
Copy link
Contributor Author

chfw commented Aug 7, 2019

I will share something about pypifs a bit later.

Could I question why would not the message reveal which root path cannot be opened?

@chfw
Copy link
Contributor Author

chfw commented Aug 7, 2019

@lurch , for your information, pypifs try to make static files inside python package available to other packages to read via python filesystem 2. Here is the initial prototype.

I knew this is a bit extreme issue where there are alternatives, as I mentioned in the above texts, debug, print could have been applied. Or try... catch in our offspring packages can also be taken, so as to show what pyfilesystem2 complains about.

Now, if we count around the number of developers of fs2 derived systems, let's say N; And count the time T in doing: Step 1) to read the log and found CreateFailure message, Step 2) add print/debug/try..catch, Step 3) re-test. This issue could save S = N * T from the developers in your ecosystem. And this save S could be invested in:

a. make the pyfs2 derived package better
b. contribute more code back to pyfs2.

Taking one step back, if the wider perception of this issue is too trivial, I am happy to withdraw the changes. It is not the end of world without it, is it?

@willmcgugan
Copy link
Member

@chfw I don't fully grasp your use case either, but extending the error message is trivial. If it's useful to you, let's go with it. 👍

@chfw
Copy link
Contributor Author

chfw commented Aug 7, 2019

The detailed code is as follows, pypifs try to figure out where the python package is installed, meaning its physical file path. Then delegate OSFS to handle file read, write and other file/dir related operations.

Because, python is cross platform, the package path could be windows path, hence it is not straight forward..

class PypiFSOpener(Opener):
    protocols = ["pypi"]

    def open_fs(self, fs_url, parse_result, writeable, create, cwd):
        pypi_package_name, _, dir_path = parse_result.resource.partition("/")
        module_name = get_module_name(pypi_package_name)
        module_path = get_module_path(module_name)
        root_path = fs.path.join(module_path, dir_path)
        osfs = OSFS(root_path=root_path)
        return osfs

Surely, with hindsight, what I should have done is to print/try ... catch it and find out what's going wrong. Because you guys are very approachable, especially @althonos on jinja2-fsloader, I would like to bring up this trivial issue here.

@lurch
Copy link
Contributor

lurch commented Aug 7, 2019

I don't see why you couldn't have a try ... catch CreateFailed around your osfs = OSFS(root_path=root_path) (especially if you're not certain if root_path actually exists or not), but if @willmcgugan is happy to add what you're asking for, then I have no objections.
Although IMHO
fs.errors.CreateFailed: root path 'C:\projects\pyfilesystem2\file' does not exist
might be better than
fs.errors.CreateFailed: C:\projects\pyfilesystem2\file: does not exist
🤷‍♂️

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

3 participants