Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding bin paths to imported python-modules #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

costrouc
Copy link

@costrouc costrouc commented Apr 10, 2019

Many python packages come with binaries. Some examples are flask, numpy, pytest, and graphviz to name a few. Without this PR the command provided by the libraries are not in the interpreter path.

[nix-shell:~/p/nixpkgs-python-importer]$ ipython
Python 3.7.2 (default, Dec 24 2018, 03:41:55) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from nixpkgs.flask import flask                                                                                                                                                 

In [2]: ! flask                                                                                                                                                                         
Traceback (most recent call last):
  File "/nix/store/qdff2m02bl44raxfrgsxskvwkcl08095-python3.7-Flask-1.0.2/lib/python3.7/site-packages/flask/cli.py", line 529, in list_commands
    rv.update(info.load_app().cli.list_commands(ctx))
  File "/nix/store/qdff2m02bl44raxfrgsxskvwkcl08095-python3.7-Flask-1.0.2/lib/python3.7/site-packages/flask/cli.py", line 384, in load_app
    'Could not locate a Flask application. You did not provide '
flask.cli.NoAppException: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
Usage: flask [OPTIONS] COMMAND [ARGS]...

  A general utility script for Flask applications.

  Provides commands from Flask, extensions, and the application. Loads the
  application defined in the FLASK_APP environment variable, or from a
  wsgi.py file. Setting the FLASK_ENV environment variable to 'development'
  will enable debug mode.

    $ export FLASK_APP=hello.py
    $ export FLASK_ENV=development
    $ flask run

Options:
  --version  Show the flask version
  --help     Show this message and exit.

Commands:
  routes  Show the routes for the app.
  run     Runs a development server.
  shell   Runs a shell in the app context.

@costrouc costrouc changed the title [WIP] Adding bin paths to python-modules Adding bin paths to imported python-modules Apr 10, 2019
@t184256
Copy link
Owner

t184256 commented Apr 12, 2019

I have noticed that you've dropped the 'do not merge' clause.

Personally, I prefer nix-shell-wrapping trickery for obtaining shells with extra binaries in $PATH, as it's the supported method. But I can see the appeal in your desire to modify $PATH on import as well.

I've thought over it and my position is that while modifying $PATH violates the principle of least surprise. I'm OK with merging that functionality as long as it's off by default and requires some toggle to switch it on or whatever else suits you. You could, idk, put import nixpkgs; nixpkgs.modify_path_on_imports(True) in your ipythonrc and use it the way you want to.

Does that seem fine by you? Could you make it optional?

@costrouc
Copy link
Author

Yes I could work on making it optional. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants