Comments (5)
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.
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.
@ulfjack Who owns the native Python rules?
from rules_python.
lberki does, although we're planning on transitioning them to the python team this year. @duggelz
from rules_python.
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)
- Silence download 404 errors when using bazel downloader (`experimental_index_url` and `experimental_extra_index_urls`) HOT 2
- ciruclar dep with markdown-it-py[linkify, plugins]==3.0.0 HOT 1
- Exec py_test targets in a way that would work with --run_under=lldb HOT 7
- Bazel@Head fails because bzlmod example test relies on tilde in repo names HOT 4
- Gazelle incorrectly ignores files called `setup.py`. HOT 5
- Unable to use whl dependency which is compiled from source due (arch not provided in pypi)
- Missing `@@_builtins` providers when using pinned toolchains HOT 2
- bzlmod example fails to build on pip install error when building whls from sdists HOT 9
- Track pip-compile USERPROFILE workaround
- Third-party transitive dependencies seem to be packaged into wheels incorrectly HOT 3
- Linker Error with Torch 2.4.0+cu124 (ImportError: libnccl.so.2: cannot open shared object file: No such file or directory) HOT 4
- gazelle_python_manifest regression in tag 0.35.0 HOT 1
- [Question] - How do you acess the "@rules_python//python/cc:current_py_cc_headers" when working with multiple versions? HOT 6
- `py_proto_library` `_virtual_imports` causing import name collisions HOT 2
- Runfiles API fails when code and output_user_root are on different Windows drives.
- When the wheel is patched, the `sdist` is included into the repackaged wheel.
- Adjust how `imports` is auto-generated by Gazelle
- getting error indicating that uname is not in path on WSL HOT 1
- Gazelle `python_ignore_files` directive incorrectly (?) ignores files with the same name in subpackages
- [Bazel CI] Fix: Update MODULE.bazel.lock file to support latest Bazel version HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rules_python.