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

Add support for Path from pathlib. #114

Closed
wants to merge 7 commits into from
Closed

Conversation

Hinidu
Copy link
Contributor

@Hinidu Hinidu commented Nov 12, 2015

Adding support for Path in file_dep is quite easy. But clearly this is only the part of the problem: if someone (like me) uses Path then he want to use them all other the place. It would be quite strange to pass them to file_dep as is but convert to str before passing in targets for example. I think at least targets should support them too and perhaps it would be not very bad idea to support them in CmdAction.
@schettino72 what do you think about it?

@schettino72
Copy link
Member

Yes. Support it everywhere...

I was even thinking about actually storing the PosixPath instead of converting it to string.
I would need to try implementing the code to see exactly what would be the consequences of that change...

@Hinidu
Copy link
Contributor Author

Hinidu commented Nov 12, 2015

I was even thinking about actually storing the PosixPath instead of converting it to string.
I would need to try implementing the code to see exactly what would be the consequences of that change...

What's the benefit? I can imagine only two implementations:

  1. Store in file_dep both strs and Paths and don't forget to cast items in file_dep when needed - cumbersome and error-prone.
  2. Use Paths internally and convert strs provided by the user to them - pointless as I can see because I think doit doesn't use many operations on the file paths besides path comparison, though rich set of handy operations is the main feature of pathlib in my point of view.

But maybe I miss something important.

@schettino72
Copy link
Member

What's the benefit?

I was thinking about supporting passing a glob as a file_dep so the glob could be lazily evaluated.
But the glob result is not even an instance of PosixPath, it is just a generator.
So not really much relation to what you are doing...

Another reason would be to have a more robust file comparison. See #109, but I guess that is not worth the problem.

Conclusion: you are right 😄 , just convert to string.

@schettino72
Copy link
Member

  • You need to add a dependency to pathlib on setup.py because doit still supports python3.3.
  • Note some test failures on windows, check appveyor

@Hinidu
Copy link
Contributor Author

Hinidu commented Nov 13, 2015

I was thinking about supporting passing a glob as a file_dep so the glob could be lazily evaluated.
But the glob result is not even an instance of PosixPath, it is just a generator.
So not really much relation to what you are doing...

It also can be a good thing to do, but I agree that not in this PR.

Another reason would be to have a more robust file comparison. See #109, but I guess that is not worth the problem.

Hmm, I didn't think about some_file and ./some_file. I thought only about case-insensitive file systems.
Now it looks more benefitial. I will try to investigate the converting of all user strings to Paths - maybe it can be done as the next step after accepting Paths from the user.

Conclusion: you are right 😄 , just convert to string.

Yeah, I think it would be a good first step :-)

You need to add a dependency to pathlib on setup.py because doit still supports python3.3.
Note some test failures on windows, check appveyor

Ok.

@Hinidu
Copy link
Contributor Author

Hinidu commented Nov 18, 2015

Note some test failures on windows, check appveyor

It looks like these failed tests didn't run before this PR on Windows. I assumed it by the number of tests:

  • PR: ============== 4 failed, 702 passed, 15 skipped in 13.44 seconds ==============
  • master: =================== 699 passed, 21 skipped in 13.94 seconds ===================

I have added only one test.
These failed tests have a decorator: @pytest.mark.skipif("os.system('strace -V') != 0")
Do you have any ideas why strace -V could change its behaviour on AppVeyor?

@Hinidu
Copy link
Contributor Author

Hinidu commented Nov 18, 2015

@schettino72 I've commited support for Path in targets and CmdAction. Waiting for your comments on implementation. Could you point to the specific parts of the documentation which I should update to reflect these changes?

@Hinidu
Copy link
Contributor Author

Hinidu commented Nov 19, 2015

Perhaps it would be reasonable to do type checking for targets and CmdAction similar to existing for file_dep to provide more meaningful error message to the user.
Current approach will convert to str anything user will provide. I can imagine that some users want from time to time put some ints in CmdAction, but I think that other types in these places much rather would be a mistake.
What do you think about it?

@schettino72
Copy link
Member

Do you have any ideas why strace -V could change its behaviour on AppVeyor?

Sorry. No idea.

Could you point to the specific parts of the documentation which I should update to reflect these changes?

When it introduces file_dep add an example using pathlib. Then in other places (targets, ...) just mention that it also supports pathlib too.

Perhaps it would be reasonable to do type checking for targets and CmdAction similar to existing for file_dep to provide more meaningful error message to the user.

go ahead 😄

Sorry I didnt review the code yet... and probably wont do that next week also 😓

@schettino72
Copy link
Member

Do you have any ideas why strace -V could change its behaviour on AppVeyor?

I re-run the tests in an old commit just to double check.
Now AppVeyor provides a strace (from cygwin).
https://ci.appveyor.com/project/schettino72/doit/build/1.0.97/job/qlx1air685fiaxvs#L223

I dont want to debug that... lets just disable the test if strace not available OR it is on windows.
If you dont want to do this change yourself, it is fine... but please create another issue to track this. thanks.

@schettino72
Copy link
Member

thanks. one more thing. add your name in the AUTHORS file 😀

@schettino72
Copy link
Member

and an entry on CHANGES file

file_dep=["123", Path("456"), PurePath("789")])
assert {"123","456", "789"} == my_task.file_dep

def test_file_dep_must_be_string_or_path(self):
Copy link
Member

Choose a reason for hiding this comment

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

test_file_dep_str()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@schettino72
Copy link
Member

looks good. thanks. just need docs now.

@Hinidu
Copy link
Contributor Author

Hinidu commented Nov 22, 2015

thanks. one more thing. add your name in the AUTHORS file 😀

I'm already there 😉

I'll add info to CHANGES and docs.

@Hinidu
Copy link
Contributor Author

Hinidu commented Nov 22, 2015

@schettino72 thank you for review.
I've pushed requested changes, type checking in targets and CmdAction and docs update.
PR looks ready to me now.

@schettino72
Copy link
Member

thanks. squashed and merged.

There was a typo in the docs, already fixed.
Next time you can check for typos using doit spell.

def task_checker():
return {'actions': ["pyflakes sample.py"],
'file_dep': ["sample.py"]}

def task_checker_pathlib():
Copy link
Member

Choose a reason for hiding this comment

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

actually I would prefer to have a separate example... to keep examples really simple.
But I merged anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree - it is a good thing to concentrate reader on one feature at a time. I can remove this example here and add a new section like pathlib support with example which uses pathlib both in file_dep, targets and CmdAction.

Copy link
Member

Choose a reason for hiding this comment

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

PR with whatever improvements are always welcome.

@Hinidu
Copy link
Contributor Author

Hinidu commented Nov 23, 2015

@schettino72 thank you for merging!
By the way this PR can help partially solve the problem from #109 if user will provide Path instances instead of strings. str(Path('./afile')) == str(Path('afile')) == 'afile'. But it doesn't resolve symbolic links and .. though.

@Hinidu Hinidu deleted the pathlib branch November 23, 2015 08:50
@schettino72
Copy link
Member

By the way this PR can help partially solve the problem from #109 if user will provide Path instances instead of strings. str(Path('./afile')) == str(Path('afile')) == 'afile'. But it doesn't resolve symbolic links and .. though.

To tell you the truth I dont care about this feature. I am worried it could have a negative effect on performance. And I dont know how I would implement that. Anyway if you want to give a try, go ahead :)

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

Successfully merging this pull request may close these issues.

None yet

2 participants