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 --list-sources to CLI #346

Merged
merged 3 commits into from
Aug 11, 2023
Merged

Add --list-sources to CLI #346

merged 3 commits into from
Aug 11, 2023

Conversation

jherland
Copy link
Member

Make the traversal logic in FawltyDeps more visible/debuggable to the end user:

  • Add the *Source objects to the JSON output
  • Add the --list-sources CLI action with a human-readable version of the same

Commits:

  • main: Add Analysis.sources to JSON output
  • Add --list-sources CLI argument
  • main: Reformat print_human_readable() to fix pylint's 'Too many branches'

Copy link
Collaborator

@Nour-Mws Nour-Mws left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for the hard work.

fawltydeps/main.py Show resolved Hide resolved
fawltydeps/types.py Show resolved Hide resolved
tests/test_cmdline.py Show resolved Hide resolved
Increase transparency and debug-friendliness by including our Source
objects in the --json output.

In order to more easily differentiate the various types of Source
objects in this output, we want to include the Source subclass name in
its JSON representation. This is accomplished by making a proper Source
base class that automatically injects a .source_type member which
records the subclass. This is then included in the JSON representation.

Without this, a CodeSource, DepsSource, and PyEnvSource would be
represented like this, and differentiating them would have to be done by
looking at incidental members:

        "sources": [
            {
                "path": "/some/path/code.py",
                "base_dir": "/some/path",
            },
            {
                "path": "/some/path/requirements.txt",
                "parser_choice": "requirements.txt",
            },
	    {
	        "path": "/some/path/.venv",
	    },
        ]

Instead, we make the entries self-documenting, by including the subclass
name:

        "sources": [
            {
                "source_type": "CodeSource",
                "path": "/some/path/code.py",
                "base_dir": "/some/path",
            },
            {
                "source_type": "DepsSource",
                "path": "/some/path/requirements.txt",
                "parser_choice": "requirements.txt",
            },
	    {
	        "source_type": "PyEnvSource",
		"path": "/some/path/.venv",
	    },
        ],
This allows FawltyDeps to stop early and print the sources that would be
used for finding imports and declared dependencies in the project.

This can be used to help find the appropriate options to pass to
FawltyDeps in order to have it analyze the desired files.

The (default) --summary view lists all file paths that are used as
sources. The --detailed view also categorizes sources by type, and adds
extra information relevant to the type (for CodeSource, which base path
is used to recognize 1st-party imports, and for DepsSource, which parser
is used to parse declared dependencies).
@jherland jherland merged commit 86d07b2 into main Aug 11, 2023
23 checks passed
@jherland jherland deleted the jherland/list-sources branch August 11, 2023 07:34
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.

2 participants