Giter Site home page Giter Site logo

Packages and Python built-in imports are not supported when the project has somewhere a folder with the same name about absolufy-imports HOT 7 CLOSED

marcogorelli avatar marcogorelli commented on July 20, 2024
Packages and Python built-in imports are not supported when the project has somewhere a folder with the same name

from absolufy-imports.

Comments (7)

AIGeneratedUsername avatar AIGeneratedUsername commented on July 20, 2024 1

Thank you for the update. Now all works correctly.

from absolufy-imports.

MarcoGorelli avatar MarcoGorelli commented on July 20, 2024

Thanks @AIGeneratedUsername for the report

TBH having a folder which has the same name as a package you're using feels like an anti-pattern

Check that import is a 3rd-party package. Do not make such imports relative.

currently the tool only performs static analysis, so this wouldn't be an option

Another possible solution is to allow to ignore manually specific names. For example, I will ignore names "collections" and "google".

I'd rather not add such complexity

IMO the simplest solution is to change your local file structure

I'd accept a PR to document this gotcha though

from absolufy-imports.

AIGeneratedUsername avatar AIGeneratedUsername commented on July 20, 2024

I agree that names shadowing is not nice, but there is a bug in this package.

Consider the following structure:

backend/
     src/
         __init__.py
         spameggs/
              __init__.py
              foo/
                    __init__.py
                    some_file.py
              bar/
                    __init__.py
                    another_file.py

Imagine that "some_file.py" has content:

from spameggs.abc import something

absolufy-imports thinks that this import is correct and that it is imported a folder above. absolufy-imports is wrong. It is easy to detect that it is wrong. No dynamic imports are required.

absolufy-imports will change it too

from ..abc import something

So, the bug is:

absolufy-imports changes to relative WRONG imports

New (fixed) logic:

  1. Iterating over directors and files. REMEMBER DIRECTORY DEPTH!
  2. Can from spameggs.abc import something be imported?
    YES: refactor the import to be absolute!
    NO: it is either a wrong import or external package. IGNORE! DO NOTHING!

I hope my idea explanation is not too cumbersome.

from absolufy-imports.

MarcoGorelli avatar MarcoGorelli commented on July 20, 2024

Thanks for your explanation - do you want to submit a pull request to fix this?

from absolufy-imports.

AIGeneratedUsername avatar AIGeneratedUsername commented on July 20, 2024

I need to force relative imports usage in the "src/" directory. I did a research over similar packages and there is no package that do exactly what is required for me. Since my use case is rare, this issue becomes low-priority for you. I did not look at your code, but probably the simplest way to achieve my goal is either to create a pull request or fork the package. I will do this, but I can not give any time estimations (when I will have some time).

from absolufy-imports.

MarcoGorelli avatar MarcoGorelli commented on July 20, 2024

Since my use case is rare, this issue becomes low-priority for you

It's more that I have a full time job and any work I do on this package in purely voluntary

If you submit a pull request I'll review it, else I'll get to this when I get a chance

Thanks anyway for your report!

from absolufy-imports.

MarcoGorelli avatar MarcoGorelli commented on July 20, 2024

I'd like to think this is fixed in version 0.3.1 - could you check please?

from absolufy-imports.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.