Giter Site home page Giter Site logo

timofurrer / try Goto Github PK

View Code? Open in Web Editor NEW
705.0 12.0 36.0 1.36 MB

Dead simple CLI tool to try Python packages - It's never been easier! :package:

License: MIT License

Python 99.61% Makefile 0.39%
python pip virtualenv try pypi package module install fast simple

try's Introduction

try - It's never been easier to try Python packages

Latest version released on PyPi Package license Package is available as wheel

try is an easy-to-use cli tool to try out Python packages.

Demo

Features

  • Install specific package version from PyPI
  • Install package from GitHub
  • Install in virtualenv using specific version of python
  • Specify alternative python package import name
  • Keep try environment after interactive session
  • Launch interactive python console with already imported package
  • Launch editor instead of interpreter
  • Launch arbitrary python shell instead of default python shell

Usage

try requests
try requests --ipython
try requests --shell ptipython
try requests -p 3.5
try requests -p /usr/bin/python3.4.1
try requests==2.8.1
try kennethreitz/requests --ipython
try click-didyoumean:click_didyoumean  # if python package name is different then pip package name
try requests --editor

Usage examples

Note: most of the following cli options can also be configured in the configuration file!

Try single python package:

try requests
try flask

Try multiple python packages in one session:

try requests flask

Try specific version of a package:

try requests==2.8.1  # tries version 2.8.1 of requests instead of latest

Try package from GitHub repository:

try <user>/<repo>  # syntax example
try kennethreitz/requests  # installs master branch of Kenneth's requests package from GitHub

Try package but import with different name than package name:

try <package_name>:<import_name>  # syntax example
try click-didyoumean:click_didyoumean  # install click-didyoumean but import click_didyoumean

Try package in already existing virtualenv:

try requests --virtualenv ~/.try/sandbox  # use virtualenv at ~/.try/sandbox

⇢ see virtualenv config value in env section in configuration file.

Try package with specific python version:

try requests --python 3.5  # use python3.5 in virtualenv
try requests -p 2.7  # use python2.7 in virtualenv
try requests -p ~/work/cpython/bin/python  # use python binary from specific location

⇢ see python config value in env section in configuration file.

Try package with specific shell/repl:

try requests --shell python  # use python repl (default value)
try requests --shell ipython  # use ipython
try requests --shell ptpython  # use ptpython
try requests --shell ptipython  # use ptipython
try requests --shell bpython  # use bpython
try requests --ipython  # use ipython - an alias for --shell ipython

⇢ see shell config value in env section in configuration file.

Try package writing a little script instead of opening shell:

try requests --editor  # opens $EDITOR or editor instead of shell

⇢ see always_use_editor config value in env section in configuration file.

Keep virtualenv files after try run:

try requests --keep

⇢ see keep config value in env section in configuration file.

Use a specific location for the virtualenv files:

try requests --tmpdir ~/.try

⇢ see tmpdir config value in env section in configuration file.

Configuration

try can be configured to your preferences - like always use ipython as a shell or always use python3.5. The configuration file is located in your users application configuration directory in a file called config.ini. This location is OS dependent and is specified here: http://click.pocoo.org/5/api/#click.get_app_dir

The following config.ini file shows all available configuration options:

[env]
virtualenv=~/.try/sandbox
python=3.5
shell=ipython
keep=false
always_use_editor=false
tmpdir=~/.try

Installation

Use pip to install try:

pip3 install trypackage

Help

try comes with an awesome CLI interface thanks to click.

Usage: try [OPTIONS] [PACKAGES]...

  Easily try out python packages.

Options:
  --virtualenv TEXT  Use already existing virtualenv.
  -p, --python TEXT  The python version to use.
  --ipython          Use ipython instead of python.
  --shell TEXT       Specify the python shell to use. (This will override
                     --ipython
  -k, --keep         Keep try environment files.
  -e, --editor       Try with editor instead of interpreter.
  --tmpdir TEXT      Specify location for temporary directory.
  --version          Show the version and exit.
  --help             Show this message and exit.

try was inspired by https://github.com/VictorBjelkholm/trymodule.

try's People

Contributors

brookskindle avatar deejangir avatar timgates42 avatar timofurrer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

try's Issues

tmpdir could be created in a noexec location

If you have /tmp mounted with the safe option noexec, try will fail to activate virtualenv:

$ LANG= try requests
==> Use python python2.7
[*] Downloading packages: requests
/bin/sh: env/bin/activate: No such file or directory
[*] Command 'python -m pip install requests >> logs' exited with error code: 1. See /tmp/try-x05IFY/logs

If I remount /tmp with exec right it works:

$ LANG= try requests
==> Use python python2.7
[*] Downloading packages: requests
/tmp/try-cRSmIg/env/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
You are using pip version 7.1.2, however version 8.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Python 2.7.5 (default, May 29 2013, 02:28:51) 
[GCC 4.8.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

The SSLContext and pip version warnings are not related to this issue.

Package don't run :| Error: from try.__main__ import main error syntax

I create a virtualenv in Python 3 and install trypackage, but when I try run the application, raise an error saying:

(try)☁ try pip freeze click==6.4 trypackage==0.1.4

(try)☁ try try requests File "/home/erichideki/projects/try/bin/try", line 7 from try.__main__ import main ^ SyntaxError: invalid syntax
This problem is inside the try archive on /bin paste.

Any thoughts?

Use expected pip binary

try seems to use the system-provided pip binary. (I got the out-of-date warning, which I don't get usually because my user-level pip is up to date.)

This is not what I'd have expected: When I try python packages myself, I of course just type pip install whatever.

bpython? Anyone?

Hi there,

thanks for awesome package.

Do you tink it's possible to add support for bpython? It's much better then ipython and I think many people would appreciate this.

Thanks in advance.

no PS1 prefix with bash shell

I tried try out, and I am pleasantly surprised how easy it works. But I noticed that when I use bash as shell, there is no common venv prefix you usually get after running activate shell script. If I use as shell fish all is fine.

Arbitrary Shells?

Any reason not to allow arbitrary shells, instead of the ipython on/off switch? Personally, I'm using iptpython (a mix between ptpython and ipython). Would be lovely to be able to say:

try requests --shell ipython
try requests --shell iptpython

or whatever shell someone is using.

Awesome project btw. :)

Install error

The idea of try is awesome, thanks! Unfortunately I was trying to try try but I couldn't install it:

$ python -V
Python 3.5.1
$ pip -V
pip 8.1.0 from /usr/local/var/pyenv/versions/3.5.1/lib/python3.5/site-packages (python 3.5)
$ pip install trypackage
Collecting trypackage
  Using cached trypackage-0.1.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/lr/gd0yq9m90rv_gz682gqt7ylc0000gn/T/pip-build-ftxztokx/trypackage/setup.py", line 44, in <module>
        install_requires=list(x.name for x in parse_requirements("./requirements.txt")),
      File "/private/var/folders/lr/gd0yq9m90rv_gz682gqt7ylc0000gn/T/pip-build-ftxztokx/trypackage/setup.py", line 44, in <genexpr>
        install_requires=list(x.name for x in parse_requirements("./requirements.txt")),
      File "/usr/local/var/pyenv/versions/3.5.1/lib/python3.5/site-packages/pip/req/req_file.py", line 79, in parse_requirements
        "parse_requirements() missing 1 required keyword argument: "
    TypeError: parse_requirements() missing 1 required keyword argument: 'session'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/lr/gd0yq9m90rv_gz682gqt7ylc0000gn/T/pip-build-ftxztokx/trypackage/
------------------------------------------------------------
$

Basically my setup is Mac OS X 11 (El Captain), using Python via pyenv.

'.' is not recognized as an internal or external command, operable program or batch file.

Hi,
When I run try I get this error:

λ try requests
==> Use python python3.6
[*] Downloading packages: requests
'.' is not recognized as an internal or external command,
operable program or batch file.
[*] Command 'python -m pip install  requests >> C:\Users\dkter\AppData\Local\Temp\try-on_npjrs\logs' exited with error code: 1. See C:\Users\dkter\AppData\Local\Temp\try-on_npjrs\logs

The given log file contains the text:

The path python3.6 (from --python=python3.6) does not exist

I'm using Windows 10 and Python 3.6.

[Feature Request] Add automatic import `from rich import inspect`

Suggested feature:

>>> inspect(pytz.timezone)
╭────────────── <function timezone at 0x10f396ac0> ──────────────╮
│ def timezone(zone):                                            │
│                                                                │
│ Return a datetime.tzinfo implementation for the given timezone │
│                                                                │
│ 37 attribute(s) not shown. Run inspect(inspect) for options.   │
╰────────────────────────────────────────────────────────────────╯

I really like this tool by the way! It is super convenient!

The executable python3.5 (from --python=python3.5) does not exist

Hey,

I'm trying to run this on Windows 10. After installing via pip I'm running into a couple separate issues

  1. try is masked by Windows PowerShell's try syntax
  2. Running as a python m (python -m try requests) results in the error:
    The executable python3.5 (from --python=python3.5) does not exist

I'm using Python 3.5 installed to C:\Python35\python.exe

Any help would be great!

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.