generated from tweag/project
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Preliminary refactoring before --ignore
feature
#387
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mknorps
approved these changes
Nov 13, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The refactor looks good to me 🚀
I have some question for traversal implementation, but they are not blocking from merging this PR :)
Instead of having to call traversal.add(dir, ...) multiple times in order to attach multiple data items to the same 'dir', allow all data items to be passed as *args to the .add() method.
In preparation for adding functionality for ignoring files/dirs in the project.
We're about to introduce more functionality for ignoring files/dirs in a directory structure via .gitignore-style patterns. However, we're already using the term "ignore" to mean something slightly different in DirectoryTraversal: The .ignore() method is used to tell the traversal that some directory should _not_ be traversed. Rename this method to .skip_dir() (and adjust members and comments accordingly). This is more accurate to what this method actually does, and it frees up the "ignore" term to be used in future commits.
Introduce a TraversalStep class to hold the information that is being passed from the DirecotryTraversal object at each step in the traversal process. This is more self-documenting than yielding a os.walk() style tuple, and allows more easily for future extension.
Each DirectoryTraversalVector encapsulate a test case for DirectoryTraversal, and contains a list of steps that we expect DirectoryTraversal to perform for that test case, aka. an ExpectedTraverseStep. These were initialized by passing four positional arguments to the constructor (most of which are lists in their own right). The result was that it was hard to read an ExpectedTraverseStep initialization and immediate see what information was expected at this traversal step (without constantly cross-referencing with the ExpectedTraverseStep class definition). Instead, make all ExpectedTraverseStep members (except the mandatory .dir) optional (defaulting to empty lists), and use _named_ arguments when intializing them. This makes reading the test cases more straightforward: Instead of ExpectedTraverseStep("a/b/c", ["d"], [], [456, 123]) (meaning that we expect the traversal of "a/b/c" to list a single subdir "d", no filenames, and passing [456, 123] as the attached data) we now get ExpectedTraverseStep("a/b/c", subdirs=["d"], attached=[456, 123])
jherland
force-pushed
the
jherland/ignore-prefactor
branch
from
November 16, 2023 11:01
38de611
to
3862d93
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Preliminary changes to clean up the code in preparation for work on supporting gitignore-style patterns for ignoring parts of the project during traversal.
Commits:
tests/utils.py
: Better output whenassert_unordered_equivalence
failsDirectoryTraversal
: Allow attaching multiple data items in.add()
DirectoryTraversal
into its own moduledir_traversal
: Rename.ignore()
to.skip_dir()
dir_traversal
: Refactor data on each traversal step into its own classtest_dir_traversal
: Make use ofExpectedTraverseStep
self-documenting