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

feat!: add location to error reports #357

Merged

Conversation

mkniewallner
Copy link
Collaborator

@mkniewallner mkniewallner commented May 5, 2023

Resolves #349.

Note: This PR is based on #354, so it includes commits from it. See mkniewallner/deptry@refactor/introduce-violation...feat/add-error-locations-to-reporters for the diff based on the other PR.

PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • Documentation in docs is updated

Description of changes

Add error locations in both text and JSON error reports. In order to display those changes, this PR reworks both outputs, so they end up being closer to what flake8 or ruff have.

Text output

Before:

[...]
There were 4 dependency issues found.

-----------------------------------------------------

The project contains obsolete dependencies:

	chardet

Consider removing them from your project's dependencies. If a package is used for development purposes, you should add it to your development dependencies instead.

-----------------------------------------------------

There are dependencies missing from the project's list of dependencies:

	an_import
	another_import

Consider adding them to your project's dependencies.

-----------------------------------------------------

There are transitive dependencies that should be explicitly defined as dependencies:

	cfgv

They are currently imported but not specified directly as your project's dependencies.

-----------------------------------------------------
[...]

After:

deptry/dependency_getter/base.py:9:4: DEP001 an_import imported but missing from the dependency definitions
deptry/dependency_getter/base.py:10:4: DEP001 another_import imported but missing from the dependency definitions
deptry/dependency_getter/base.py:11:4: DEP003 cfgv imported but it is a transitive dependency
deptry/dependency_getter/pdm.py:12:4: DEP001 an_import imported but missing from the dependency definitions
pyproject.toml: DEP002 chardet defined as a dependency but not used in the codebase
Found 5 dependency issues.

For more information, see the documentation: https://fpgmaas.github.io/deptry/

JSON output

Before:

{
    "obsolete": [
        "chardet"
    ],
    "missing": [
        "an_import",
        "another_import"
    ],
    "transitive": [
        "cfgv"
    ],
    "misplaced_dev": []
}

After:

[
    {
        "error": {
            "code": "DEP001",
            "message": "an_import imported but missing from the dependency definitions"
        },
        "module": "an_import",
        "location": {
            "file": "deptry/dependency_getter/base.py",
            "line": 9,
            "column": 4
        }
    },
    {
        "error": {
            "code": "DEP001",
            "message": "another_import imported but missing from the dependency definitions"
        },
        "module": "another_import",
        "location": {
            "file": "deptry/dependency_getter/base.py",
            "line": 10,
            "column": 4
        }
    },
    {
        "error": {
            "code": "DEP003",
            "message": "cfgv imported but it is a transitive dependency"
        },
        "module": "cfgv",
        "location": {
            "file": "deptry/dependency_getter/base.py",
            "line": 11,
            "column": 4
        }
    },
    {
        "error": {
            "code": "DEP001",
            "message": "an_import imported but missing from the dependency definitions"
        },
        "module": "an_import",
        "location": {
            "file": "deptry/dependency_getter/pdm.py",
            "line": 12,
            "column": 4
        }
    },
    {
        "error": {
            "code": "DEP002",
            "message": "chardet defined as a dependency but not used in the codebase"
        },
        "module": "chardet",
        "location": {
            "file": "pyproject.toml",
            "line": null,
            "column": null
        }
    }
]

@mkniewallner mkniewallner force-pushed the feat/add-error-locations-to-reporters branch 5 times, most recently from eef1d99 to a420116 Compare May 6, 2023 20:50
@codecov
Copy link

codecov bot commented May 6, 2023

Codecov Report

Merging #357 (90b5801) into main (fe84fc5) will increase coverage by 0.0%.
The diff coverage is 99.1%.

@@          Coverage Diff          @@
##            main    #357   +/-   ##
=====================================
  Coverage   96.8%   96.8%           
=====================================
  Files         36      37    +1     
  Lines       1003    1029   +26     
  Branches     207     206    -1     
=====================================
+ Hits         971     997   +26     
  Misses        20      20           
  Partials      12      12           
Impacted Files Coverage Δ
...ry/imports/extractors/notebook_import_extractor.py 87.8% <50.0%> (ø)
deptry/core.py 98.0% <100.0%> (+<0.1%) ⬆️
deptry/imports/extract.py 100.0% <100.0%> (ø)
deptry/imports/extractors/base.py 100.0% <100.0%> (ø)
...ptry/imports/extractors/python_import_extractor.py 100.0% <100.0%> (ø)
deptry/imports/location.py 100.0% <100.0%> (ø)
deptry/issues_finder/base.py 100.0% <100.0%> (ø)
deptry/issues_finder/misplaced_dev.py 89.1% <100.0%> (+0.6%) ⬆️
deptry/issues_finder/missing.py 100.0% <100.0%> (ø)
deptry/issues_finder/obsolete.py 93.5% <100.0%> (+0.2%) ⬆️
... and 10 more

@mkniewallner mkniewallner force-pushed the feat/add-error-locations-to-reporters branch 3 times, most recently from 61cf744 to e5476aa Compare May 6, 2023 22:55
@mkniewallner mkniewallner marked this pull request as ready for review May 6, 2023 23:16
@mkniewallner mkniewallner requested a review from fpgmaas May 6, 2023 23:16
@mkniewallner mkniewallner force-pushed the feat/add-error-locations-to-reporters branch from 1cee383 to 90b5801 Compare May 7, 2023 14:55
@mkniewallner mkniewallner merged commit eaf9546 into fpgmaas:main May 7, 2023
16 checks passed
@mkniewallner mkniewallner deleted the feat/add-error-locations-to-reporters branch May 7, 2023 15:00
@mkniewallner mkniewallner mentioned this pull request May 7, 2023
4 tasks
@fpgmaas fpgmaas mentioned this pull request May 8, 2023
@mkniewallner mkniewallner added the breaking Change that introduces a breaking change label May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Change that introduces a breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Report locations of violations
2 participants