GithubHelp home page GithubHelp logo

Comments (11)

brettcannon avatar brettcannon commented on September 26, 2024

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.

mikeckennedy avatar mikeckennedy commented on September 26, 2024

Hi @brettcannon Very cool, thank you for thinking of us. What a neat feature.

from python-launcher.

brettcannon avatar brettcannon commented on September 26, 2024

@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.

mikeckennedy avatar mikeckennedy commented on September 26, 2024

Will do! And I'll share it on Python Bytes as an update.

from python-launcher.

mikeckennedy avatar mikeckennedy commented on September 26, 2024

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.

brettcannon avatar brettcannon commented on September 26, 2024

@mikeckennedy upgrade your version of Rust to 1.50.0 or newer.

Duplicate of #82 .

from python-launcher.

mikeckennedy avatar mikeckennedy commented on September 26, 2024

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.

brettcannon avatar brettcannon commented on September 26, 2024

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.

mikeckennedy avatar mikeckennedy commented on September 26, 2024

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.

brettcannon avatar brettcannon commented on September 26, 2024

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.

mikeckennedy avatar mikeckennedy commented on September 26, 2024

Interesting, that's a good idea. Thanks Brett.

from python-launcher.

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.