interrogate icon indicating copy to clipboard operation
interrogate copied to clipboard

File inspections truncating early causing failures

Open nateinaction opened this issue 7 months ago • 3 comments

Hey there, thanks for developing interrogate! I'm hoping that we can use it to improve doc coverage on our satellite flight software repo. I'm having some trouble getting it running though and the error doesn't feel descriptive enough for me to investigate. We're using uv so you should be able to reproduce with an identical env by cloning, checking out the branch and running make fmt or uvx -p 3.9 interrogate --config=pyproject.toml.

Let me know if there's anything more I can do on our end to help debug what's going on here!

Environment

  • interrogate version(s) (interrogate --version: 1.7.0
  • Operating System(s): MacOS 15.5
  • Python version(s): 3.9
  • Codebase: https://github.com/proveskit/pysquared/pull/232
  • Command to reproduce: make fmt

Description of the bug

Seeing an error when trying to run interrogate against codebase:

uvx interrogate --config=pyproject.toml
Installed 7 packages in 8ms
Traceback (most recent call last):
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/bin/interrogate", line 10, in <module>
    sys.exit(main())
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/interrogate/cli.py", line 400, in main
    results = interrogate_coverage.get_coverage()
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/interrogate/coverage.py", line 286, in get_coverage
    return self._get_coverage(filenames)
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/interrogate/coverage.py", line 268, in _get_coverage
    result = self._get_file_coverage(f)
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/interrogate/coverage.py", line 237, in _get_file_coverage
    parsed_tree = ast.parse(source_tree)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 86
    f"{sensor_name}_{
                     ^
SyntaxError: EOL while scanning string literal

What you expected to happen

How to reproduce (as minimally and precisely as possible)

# clone
git clone [email protected]:proveskit/pysquared.git

# checkout the branch
git checkout add-interrogate

# if you have uv installed you can run
uvx -p 3.9 interrogate --config=pyproject.toml

# otherwise just run
make fmt

Anthing else we need to know?

Trying with different python versions changes the failure slightly. Here's what it looks like on 3.12

uvx -p 3.12 interrogate --config=pyproject.toml
Installed 6 packages in 8ms
Traceback (most recent call last):
  File "/Users/nate/.cache/uv/archive-v0/JGriK8izZszrYxjeTE-oW/bin/interrogate", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/nate/.cache/uv/archive-v0/JGriK8izZszrYxjeTE-oW/lib/python3.12/site-packages/click/core.py", line 1442, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/.cache/uv/archive-v0/JGriK8izZszrYxjeTE-oW/lib/python3.12/site-packages/click/core.py", line 1363, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/nate/.cache/uv/archive-v0/JGriK8izZszrYxjeTE-oW/lib/python3.12/site-packages/click/core.py", line 1226, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/.cache/uv/archive-v0/JGriK8izZszrYxjeTE-oW/lib/python3.12/site-packages/click/core.py", line 794, in invoke
    return callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/.cache/uv/archive-v0/JGriK8izZszrYxjeTE-oW/lib/python3.12/site-packages/click/decorators.py", line 34, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/.cache/uv/archive-v0/JGriK8izZszrYxjeTE-oW/lib/python3.12/site-packages/interrogate/cli.py", line 400, in main
    results = interrogate_coverage.get_coverage()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/.cache/uv/archive-v0/JGriK8izZszrYxjeTE-oW/lib/python3.12/site-packages/interrogate/coverage.py", line 286, in get_coverage
    return self._get_coverage(filenames)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/.cache/uv/archive-v0/JGriK8izZszrYxjeTE-oW/lib/python3.12/site-packages/interrogate/coverage.py", line 268, in _get_coverage
    result = self._get_file_coverage(f)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/.cache/uv/archive-v0/JGriK8izZszrYxjeTE-oW/lib/python3.12/site-packages/interrogate/coverage.py", line 237, in _get_file_coverage
    parsed_tree = ast.parse(source_tree)
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.11/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ast.py", line 52, in parse
    return compile(source, filename, mode, flags,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<unknown>", line 71
    moment = self._scalar_gain * (pre
                                 ^
SyntaxError: '(' was never closed

Similarly, commenting out all the code in the file where f"{sensor_name}_{ exists changes the error.

uvx -p 3.9 interrogate --config=pyproject.toml
Traceback (most recent call last):
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/bin/interrogate", line 10, in <module>
    sys.exit(main())
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/interrogate/cli.py", line 400, in main
    results = interrogate_coverage.get_coverage()
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/interrogate/coverage.py", line 286, in get_coverage
    return self._get_coverage(filenames)
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/interrogate/coverage.py", line 268, in _get_coverage
    result = self._get_file_coverage(f)
  File "/Users/nate/.cache/uv/archive-v0/x1EkT-3TJZbse_j4ZgvIs/lib/python3.9/site-packages/interrogate/coverage.py", line 237, in _get_file_coverage
    parsed_tree = ast.parse(source_tree)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 76
    if not mag_field or not ang_vel:
                                   ^
SyntaxError: invalid syntax

Ultimately it looks like parts of the codebase/file gets cut off when running interrogate?

nateinaction avatar Jun 27 '25 00:06 nateinaction

Everything appears to be working in the linux based CI pipeline and I didn't have any issues running interrogate on the mentioned branch when I first built it in April. A lot of the codebase has changed since April so I checked out the last commit that I probably ran locally ba4affc ~and found the same error~. It worked on that commit.

Edit: I actually did have an incomplete file during this test, it was not checked into git. Parsing worked once it was removed. It would be great if error handling told you the file/line (I'll try to add this). Preview of showing the failing file while allowing interrogate to continue:

Failed to parse /Users/nate/code/github.com/proveskit/pysquared/pysquared/attitude_control/detumble.py: '(' was never closed (<unknown>, line 71)
= Coverage for /Users/nate/code/github.com/proveskit/pysquared/ =
------------ Detailed Coverage ------------
| Name                                                                      |  Status |
|---------------------------------------------------------------------------|---------|

nateinaction avatar Jul 01 '25 00:07 nateinaction

Ok just like the CI pipeline, running against the pysquared main branch in the debugger submitted in #188 does not show any syntax errors.

And again running in uv from my interrogate branch from #188 shows no issues

# in interrogate repo
uv run -m interrogate --config=/Users/nate/code/github.com/proveskit/pysquared/pyproject.toml /Users/nate/code/github.com/proveskit/pysquared/
================================================= Coverage for /Users/nate/code/github.com/proveskit/pysquared/ ==================================================
----------------------------------------------------------------------- Detailed Coverage ------------------------------------------------------------------------
| Name                                                                                                            |                                       Status |
|-----------------------------------------------------------------------------------------------------------------|----------------------------------------------|

And success again using interrogate master pulling over only the pyproject.yaml changes from #188. I wonder if there's an issue with one of the packaged dependencies? Still not discounting the possibility of it being something on my end...

nateinaction avatar Jul 01 '25 01:07 nateinaction

Ok, I think this must be a dependency issue since it is entirely resolved by replacing the pre-commit repo with the latest commit from #188.

  - repo: https://github.com/nateinaction/interrogate/
    rev: b2ccace
    hooks:
      - id: interrogate
        args: [--config=pyproject.toml]
        pass_filenames: false  # needed if excluding files with pyproject.toml or setup.cfg

  # - repo: https://github.com/econchick/interrogate
  #   rev: 1.7.0
  #   hooks:
  #     - id: interrogate
  #       args: [--config=pyproject.toml]
  #       pass_filenames: false  # needed if excluding files with pyproject.toml or setup.cfg

I think this is solved by #188

nateinaction avatar Jul 01 '25 01:07 nateinaction