While attempting to add nbdev functionality to an already existing github repo I ran into an error with the suggested approach of the nbdev_new command:
TypeError: memoryview: a bytes-like object is required, not 'str'
nbdev version - 1.1.6
python version - 3.7.7
According to stack overflow the problem was caused by a change from python 2 to 3.
I also found this post on git memory detailing a potential similar issue.
In the source code of nbdev the nbdev_new method from nbdev/cli.py calls a fastcore method urlsave from fastcore/net.py.
def urlsave(url, dest=None):
"Retrieve `url` and save based on its name"
res = urlread(urlwrap(url), decode=False)
if dest is None: dest = Path(url).name
name = urlclean(dest)
Path(name).write_bytes(res)
return dest
I believe the method is attempting pass a str to write_bytes, and failing as a result.
By editing the code in nbdev to overwrite fastcore’s urlsave to:
def urlsave(url, dest=None):
"Retrieve `url` and save based on its name"
res = urlread(urlwrap(url), decode=True)
if dest is None: dest = Path(url).name
name = urlclean(dest)
Path(name).write_text(res)
return dest
I was successfully able to get nbdev_new working.
I have two questions:
-
Is this a good solution to the problem, or could it be addressed in a better way?
-
If it is a good solution how should I go about submitting it to be implemented? (Should I focus on only nbdev, or is this a change that is necessary for fastcore?)