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

DRAFT: Order based on filenames or partial path #52

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Joacchim
Copy link

@Joacchim Joacchim commented Aug 6, 2021

As discussed in #51, I've been fiddling with the module to try and see how I could fit my needs.

This is rough on the edges, and may not follow the project's development philosophy, but aims to be a first shot to be discussed and reflected upon.

@codecov-commenter
Copy link

codecov-commenter commented Aug 7, 2021

Codecov Report

Merging #52 (e125278) into main (1e873d5) will decrease coverage by 2.20%.
The diff coverage is 69.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #52      +/-   ##
==========================================
- Coverage   97.79%   95.59%   -2.21%     
==========================================
  Files           5        5              
  Lines         545      567      +22     
  Branches      121      129       +8     
==========================================
+ Hits          533      542       +9     
- Misses          8       17       +9     
- Partials        4        8       +4     
Impacted Files Coverage Δ
pytest_order/sorter.py 93.27% <69.23%> (-3.44%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e873d5...e125278. Read the comment docs.

@mrbean-bremen
Copy link
Member

Thanks for that! I didn't get to this today, will probably have a closer look tomorrow (bit tired today, brain not working...), but at a first glance, this looks good to me. There is not much development philosophy to this project, other than keep it maintainable, don't add unneeded bloat, and have a test coverage close to 100% - after all, it's only a small project. If you want, you can add a couple of tests, or I can do that later.
Actually the change to use node ids as labels that I made recently makes this kind of change easier. I think it is a reasonable improvement, though we have to check that it behaves as expected with different options (like order-scope and order-group-scope).

@Joacchim
Copy link
Author

Joacchim commented Aug 7, 2021

I haven't tried cleaning-up the patch or even running the tests so far, I mostly wanted to push that out for you to read first before doing anything else.

Given your feedback, I guess I'll go a bit further on the next iteration, since it seems to be a 🆗 :)

for node_id in self.node_ids:
if node_id.count("::") == 2:
path_index = node_id.index("::")
if label.endswith('/') and label in node_id: # directory ordering
Copy link
Member

Choose a reason for hiding this comment

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

The in check here could be ambiguous - maybe node_id.startswith(label)? Or we need more checks here...

Copy link
Author

@Joacchim Joacchim Aug 12, 2021

Choose a reason for hiding this comment

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

I took the approach of checking endswith() "in" in order to match any part of a directory's path, even if not fully specified (as it allows shorter and more concise specification in the decorator parameters).

Copy link
Member

Choose a reason for hiding this comment

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

Yes, actually I did the same with endswith, which wouldn't work in your case, of course... given that it needs to end with a slash this may be ok (it would theoretically allow ambiguities, but the user would be responsible to avoid them).

path_index = node_id.index("::")
if label.endswith('/') and label in node_id: # directory ordering
items.append(self.node_ids[node_id])
elif node_id[:path_index].endswith(label): # end-of-filename ordering
Copy link
Member

Choose a reason for hiding this comment

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

This implies that there is only one directory ending with label, though it could be documented that label has to be unambiguous in that respect.

Copy link
Author

Choose a reason for hiding this comment

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

I thought it would be easier to require ending the label with a / to refer to a directory, which would incidentally avoid confusing a directory and any other kind of path/entity.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, makes sense.

@mrbean-bremen
Copy link
Member

@Joacchim - are you still working on this? Or are you waiting for more feedback?

@Joacchim
Copy link
Author

Joacchim commented Nov 2, 2021

Ah, sorry, I've slacked-off on this so far. If you want to take it up, please do.

@mrbean-bremen
Copy link
Member

mrbean-bremen commented Nov 2, 2021

Ok, thanks. This is currently not a priority for me, so it may take some time before I get to it, but I guess it isn't that important for you either.

@Joacchim
Copy link
Author

Joacchim commented Nov 3, 2021

No, indeed.
I wanted to make progress on my own project first and foremost, so I chose to work with the existing limitations

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

3 participants