fredrikaverpil / creosote

Identify unused dependencies and avoid a bloated virtual environment.
MIT License
326 stars 8 forks source link

Capitalization of SQLAlchemy can result in it being flagged as a false positive in older versions #220

Closed mgd722 closed 5 days ago

mgd722 commented 2 weeks ago

What happened?

SQLAlchemy was flagged as an unused dependency despite being imported in the code.

Reproduction steps

My requirements.in:

SQLAlchemy==1.4.41

The import in the code:

from sqlalchemy.orm.attributes import flag_modified

Compiled requirements.txt:

sqlalchemy==1.4.41
    # via
    #   -r requirements.in

Note the capitalization difference between requirements.in and requirements.txt! When running cerosote, I'd get:

Oh no, bloated venv! 🤢 🪣
Unused dependencies found: SQLAlchemy

If I change my requirements.in to:

sqlalchemy==1.4.41

then run pip-compile requirements.in, pip-sync requirements.txt, and cerosote a second time, SQLAlchemy is correctly marked as used.

I tried to create a standalone example to submit with this issue, but was unable to reproduce it on its own. That said, I did switch it back and forth in my codebase and watched it break/fix depending on capitalization, so something is happening here...

I don't expect this is worth the time to fix, but I wanted to document it so that someone else doesn't spend an hour going down the same rabbit hole I did.

Relevant log output

3.1.0
github-actions[bot] commented 1 week ago

This issue has been open for 7 days with no activity. Remove the stale label or add a comment or it will be closed in 3 days.

fredrikaverpil commented 5 days ago

@mgd722 I can't reproduce this here, so not really sure what to do about it without more information, unfortunately. I'm closing this for now and we can re-open if you can provide more information.