Giter Club home page Giter Club logo

Comments (5)

brandjon avatar brandjon commented on August 25, 2024 1

Regarding the Python behavior of adding the main script's directory to the import path, this is something we'd like to workaround to eliminate a class of hermeticity problems. See bazelbuild/bazel#7091.

from rules_python.

PranavSathy avatar PranavSathy commented on August 25, 2024

Ok, I figured it out, it seems that because the name of my py_binary is analysis as well as the name of the file analysis.py, the import statement in the file could not find the submodules (folders) within because it seems to have been interpretting the actual analysis.py file.

If I simple do import analysis in my analysis.py file, it actually executes twice.

Is there some rationale as to why py_binary/py_library do this? I can escalate this into the actual bazelbuild/bazel repo since this is behavior exhibited by the native rules.

from rules_python.

mattmoor avatar mattmoor commented on August 25, 2024

@ulfjack Who owns the native Python rules?

from rules_python.

ulfjack avatar ulfjack commented on August 25, 2024

lberki does, although we're planning on transitioning them to the python team this year. @duggelz

from rules_python.

duggelz avatar duggelz commented on August 25, 2024

This should be fixed once this change is released in Bazel: bazelbuild/bazel@e9c885a

You'll need to add legacy_create_init=false to your py_binary and py_library targets.

Meanwhile, my practical advice is to rename the directory or the file. You'll keep running into similar problems, even in non-Bazel contexts, because of how Python implicitly adds the main script directory to the start of the Python import path.

from rules_python.

Related Issues (20)

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.