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

save method respects base path for relative paths #254

Merged

Conversation

UnicodingUnicorn
Copy link
Contributor

Should resolve #205, at least partially. From the wording of the issue, I cannot tell if it's supposed to apply to everything. I suppose so, but it's best to play it safe.


Please preserve this line to notify @roll (lead of this repository)

@roll
Copy link
Member

roll commented Dec 17, 2019

@UnicodingUnicorn
Thanks!

Now I'm not sure that I fully understand the initial issue.
As a client, I would probably be surprised if it's changed the patch under the hood e.g.

package.save('to/my/path.json`) # I think I expect it to be in the exact path

And not sure how it will play with remote paths etc.

Could you please provide an example/test of new behaviour? And probably we need to add an option to make this change non-breaking (or my understanding is wrong)

@roll roll added the review label Dec 17, 2019
@UnicodingUnicorn
Copy link
Contributor Author

Yeah, the initial issue is a bit weird. But you added the labels to it so I kinda assumed it was good to go. It looked simple enough, and the fact there's a bounty on it is a plus.

Looking back now, this is more a documentation issue. Maybe it's simpler to revise the description of target. I think I'll close this pull request.

Copy link
Member

@roll roll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@UnicodingUnicorn
Sorry for the confusion it's my fault not properly checking the initial issue before posting it on Bountysource.

I've dove into it now. I think that the feature request #205 makes sense (I thought it was another bug).

Could you please:

  • add to_base_path (bool) (better idea for the name?) flag for the behavior you have implemented. So by default, there will be no changes
  • a few tests to validate new feature

@jdahlbaek
Copy link

jdahlbaek commented Dec 19, 2019

Since I authored the weird issue #205, let me try to explain.

What I should have written is probably

if target contains a relative path, I would expect it to be appended to base_path

I think the docs are quite clear, stating

base_path (str): base path for all relative paths

As such, I would find it very surprising if the call

package.save('to/my/path.json`)

did not respect base_path.

It is my understanding that the current behaviour is either a bug, or a case of misleading documentation for the target argument.

@UnicodingUnicorn It is my understanding that your patch fixes the bug.

To ensure backwards compatibility, one could introduce an ignore_base_path argument with default value None. In case the user passes a relative path, emit a warning if ignore_base_path is None, warning the user that the current default behaviour (ignore_base_path=True) will be changed in the future (to ignore_base_path=False), and instruct the user to set ignore_base_path explicitly to avoid compatibility problems.

Sorry for the imprecise statement in the original issue, I hope it is more clear now what I meant.

@UnicodingUnicorn
Copy link
Contributor Author

I think the issue here is that the docs describe or imply a behaviour that is not actually implemented, so adding this functionality as a new feature as @roll suggests does not help much.

I believe that either the docs need to be updated, or the feature implemented, which admittedly is a breaking change. Although I'm a bit wary of adding new arguments, @jdahlbaek's method seems to be a good way to perform the transition.

I'm working on the tests now.

@roll
Copy link
Member

roll commented Jan 6, 2020

@jdahlbaek
It seems a perception difference 😃

If I see the code like this:

package = Package(descriptor, base_path='input/datapackage.json')
...
package.save('output/datapackage.json')

I will never think about input/ouput/datapackage.json as a target because I'm used to thinking that all relative paths are relative to the CWD (current working directory). Out tests are written like this etc

So probably there is no a right answer for it.

But I still think that something like this:

package = Package(descriptor, base_path='input/datapackage.json')
...
package.save('output/datapackage.json', to_base_path=True)

is the least damaging considering the current state of art.

cc @akariv

@roll
Copy link
Member

roll commented Jan 6, 2020

I mean even if we consider that current behavior is a bug (which I don't think is correct) there can be some code relying on this behavior and we can't introduce breaking changes

@akariv
Copy link
Member

akariv commented Jan 6, 2020

I can imagine use cases in which each api seems more natural. However, from a backward compatibility point of view @roll 's suggestions makes sense to me.

@UnicodingUnicorn
Copy link
Contributor Author

Yeah, I see the point on backward compatibility now. I will implement stuff as per @roll's suggestion.

@UnicodingUnicorn
Copy link
Contributor Author

@roll may I request another review please?

Copy link
Member

@roll roll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. Thanks!

@roll roll merged commit 9ab2461 into frictionlessdata:master Feb 24, 2020
@UnicodingUnicorn UnicodingUnicorn deleted the save-method-respects-base-path branch February 25, 2020 00:51
@lwinfree
Copy link
Member

hi @UnicodingUnicorn! Thanks for this! Please claim the bounty 😃

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

Successfully merging this pull request may close these issues.

save method does not respect base_path
5 participants