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

Preliminary refactoring before --ignore feature #387

Merged
merged 8 commits into from
Nov 16, 2023

Conversation

jherland
Copy link
Member

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 when assert_unordered_equivalence fails
  • DirectoryTraversal: Allow attaching multiple data items in .add()
  • Move DirectoryTraversal into its own module
  • dir_traversal: Rename .ignore() to .skip_dir()
  • dir_traversal: Refactor data on each traversal step into its own class
  • test_dir_traversal: Make use of ExpectedTraverseStep self-documenting

@jherland jherland self-assigned this Oct 31, 2023
@zz1874 zz1874 self-assigned this Nov 2, 2023
Copy link
Collaborator

@mknorps mknorps left a 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 :)

tests/utils.py Show resolved Hide resolved
tests/test_dir_traversal.py Outdated Show resolved Hide resolved
tests/test_dir_traversal.py Show resolved Hide resolved
fawltydeps/traverse_project.py Outdated Show resolved Hide resolved
jherland and others added 8 commits November 16, 2023 11:59
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 jherland force-pushed the jherland/ignore-prefactor branch from 38de611 to 3862d93 Compare November 16, 2023 11:01
@jherland jherland merged commit 5377983 into main Nov 16, 2023
37 checks passed
@jherland jherland deleted the jherland/ignore-prefactor branch November 16, 2023 11:06
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.

3 participants