Comments (11)
Looks like std::path::Path.ancestors
will give an iterator that walks up. Use of std::path::Path.join
should make it easy to join the relative path to .venv/bin/python
to each portion. Then using std::iter::Iterator.find
should make it easy to use std::path::Path.is_file
to search appropriately.
let relative_venv_path = Pathbuf::from(".venv/bin/python"); // Not sure if this is platform-agnostic.
let containing_path = std::env::current_dir().as_path().ancestors().find(|dir| dir.join(relative_venv_path).is_file());
from python-launcher.
Hi @brettcannon Very cool, thank you for thinking of us. What a neat feature.
from python-launcher.
@mikeckennedy @okken This change is in 0.15.0, so please give it a try and let me know how it goes!
from python-launcher.
Will do! And I'll share it on Python Bytes as an update.
from python-launcher.
Oh, can't get it to install on macOS for some reason:
error[E0658]: use of unstable library feature 'bool_to_option'
--> /Users/michaelkennedy/.cargo/registry/src/github.com-1ecc6299db9ec823/python-launcher-0.15.0/src/cli.rs:164:29
|
164 | venv_path.is_file().then(|| venv_path)
| ^^^^
|
= note: see issue #64260 <https://github.com/rust-lang/rust/issues/64260> for more information
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.
error: could not compile `python-launcher`
To learn more, run the command again with --verbose.
No complaints. Just FYI. :)
from python-launcher.
@mikeckennedy upgrade your version of Rust to 1.50.0 or newer.
Duplicate of #82 .
from python-launcher.
Thanks Brett. Crazy, I had installed Rust from Homebrew just when I posted this. But it was 1.49. It updated to 1.50 today and the install worked. :)
I tested the feature out on my system but couldn't get it to work. Maybe I'm doing it wrong but it could be not using the default .venv
name. Is this a real problem or did I get my system into a wonky state?
In shell profile: export VIRTUAL_ENV="venv"
In terminal:
Venv Dir: /Users/me/github/repo_name/src/package_name/venv
CWD: /Users/me/github/repo_name/src/package_name/package_name/bin/reporting
Command: py summary.py
Error message: venv/bin/python: No such file
from python-launcher.
So your VIRTUAL_ENV
export cheat broke expectations. 😄 That environment variable is set by the virtual environment activate
script. So by setting it to venv
it causes the launcher to simply look in the venv
directory for venv/bin/python
. Since you don't have that in your reporting/
directory it's failing due to it not actually existing (you can run with logging turned on to get a bit more detail about how the search is going). That's why the docs at https://github.com/brettcannon/python-launcher#py-any-version say "Use ${VIRTUAL_ENV}/bin/python immediately if available" and doesn't mention traversal.
So you have two options. One is to set VIRTUAL_ENV
to an absolute path (either via activate
or manually). The other option is to put your virtual environment in a directory named .venv
, not venv
like you have in your example (I wasn't kidding on the podcast that it wasn't configurable for the directory name 😁 ), then the traversal semantics you asked for will work.
But my question to you is what would the docs need to say to make it clearer that what you tried isn't what is intended?
from python-launcher.
Ahhh, sorry about that. I thought the purpose of VIRTUAL_ENV
was to allow me to specify a name other than .venv
, such as venv
or .env
for example.
I'm not sure the docs were unclear. I honestly skimmed them with my preconceived notion. :)
from python-launcher.
BTW if you want a way to specify the directory name like that then I would encourage you to open an issue on bugs.python.org to let venv
default to using an environment variable when set (e.g. PYTHONVENVDIR
or somthing). Then the Launcher could read that to determine what directory name to check under. And the reason I'm suggesting solving this upstream is all of it solves potential typo problems.
from python-launcher.
Interesting, that's a good idea. Thanks Brett.
from python-launcher.
Related Issues (20)
- Document the release process
- Add a FAQ entry about how to turn off `.venv` usage HOT 1
- No configurations support (or undocumentd) aka py.ini
- Manpage wording around `--list` and virtual environments confusing HOT 6
- Manpage typos HOT 3
- Local virtualenv not found on WSL2 HOT 2
- Support PEP 723 HOT 1
- Update `docs/requirements.txt`
- Add Repology badge to website
- Update installation instructions for NixOS package HOT 1
- Docs point to mousebender HOT 1
- Clarify how interpreters are found on PATH HOT 1
- Fix Clippy warning about dead code
- tag a new release? HOT 6
- Add a justfile recipe for running cog on `docs/install.md`
- Update `docs-venv` justfile recipe to delete any preexisting virtual environment
- Drop use of `actions-rs` actions
- Typo in FAQ
- Check cargo-wizard for optimizations
- Add artifact attestation to release process
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 python-launcher.