Git Product home page Git Product logo

zpy's Introduction

zpy

Manage Python Environments in Zsh, with pip-tools

Build GitHub Pages Bump PyPI requirements - GitHub Actions Demo containers - GitHub Actions

Demo container - Alpine Linux Demo container - Fedora Demo container - Ubuntu

Plugin file size in bytes Documentation Status Contact developer on Telegram

zpy is a set of Zsh functions wrapping pip-tools and Python's venv module, for the simple and interactive management of Python virtual environments, dependency specifications, and isolated Python app installations.

None of them should get in your way. All have thorough tab completion.

They can generally replace pipenv, poetry, pipx, pipsi, virtualenvwrapper, etc.

zpy supercommand completions

Getting It

The short version of installation:

  • Install Python, Zsh, fzf
  • Source this repo's zpy.plugin.zsh in your .zshrc, or use a Zsh plugin manager to add andydecleyre/zpy

Check out zpy.rtfd.io for installation, explanation, and usage docs!

Examples

  • Install tools from PyPI or git, each with its own isolated venv:

    % pipz install tldr jello rich-cli yt-dlp 'visidata @ git+https://github.com/saulpw/visidata@develop'
  • Create a venv for the current folder (if necessary), activate it, and sync installed pkgs to match all requirements.txt lockfiles:

    % envin

    . . . or sync packages to particular lockfiles:

    % envin dev-requirements.txt
  • Add a pkg to requirements.in, compile a locked dep tree as requirements.txt, and sync installed packages:

    % pipacs beautifulsoup4
  • Compile all (*-)requirements.in files, upgrading versions where possible, then sync to match:

    % pipcs -U
  • Inject "loose" requirements (as written in requirements.in) into pyproject.toml:

    % pypc

There are about 25 user-facing functions in total. For details, see the reference and the short guide.

They are also available as subcommands to the "supercommand" zpy; envin is equivalent to zpy envin, etc.

Basic usage of envin and pipacs:

Animated envin and pipacs demo

Basic usage of pipz:

Animated pipz demo

Guiding Ideas

Information flow diagram

  • You should not have to manually specify the dependencies anywhere other than *requirements.in files
  • Folks who want to use your code shouldn't have to install any new-fangled less-standard tools (pipenv, poetry, pip-tools, zpy, etc.); pip install -r *requirements.txt ought to be sufficient
  • It's nice to keep the venv folder outside of the project itself
  • Not every manageable project needs a pyproject.toml or to be packaged
  • Lockfiles are good
  • Tab completion is wonderful
  • These functions don't:
    • need to be used exclusively
    • need to be used by everyone on the same project
    • do what pyenv/asdf-vm or flit do best (but do work with them if you choose)
    • conflict with anything else your team cares to do with your code; If they can be a friendlier neighbor to your workflows, file an issue

Try it in a Container

Try it in isolation with docker or podman with one of these commands:

$ docker run --net=host -it --rm quay.io/andykluger/zpy-ubuntu:master
$ podman run --net=host -it --rm quay.io/andykluger/zpy-ubuntu:master

Replace "ubuntu" with "alpine" or "fedora" if you prefer.

zpy's People

Contributors

actions-user avatar andydecleyre 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

Watchers

 avatar  avatar

zpy's Issues

More parallelization

Use zargs to parallelize all pip-compile operations, and any project-isolated pip-sync operations. Maybe some other things like pipcheckold, if the output is or can be made human friendly.

conda

Hi, and thanks for the great project- the guiding ideas really resonate with me.

In a better world, I would be able to only use pip to manage dependencies in Python projects, however sometimes conda is useful, either because it can handle stuff pip can't (notably different python versions per env), or because the conda packaging has better support from from the package's author (if the pip's package has exists at all).

In practice, for my projects I usually use a minimal environment.yml file:

name: myenv
channels:
  - conda-forge
  - defaults
dependencies:
  - python=3.8
  - pip
  - pip:
    - -r requirements.txt
    - -r requirements-dev.txt

If all the dependencies I need are available from pip (the best situation), they can all be managed with pip-compile. If not, I can add more dependencies to the conda file.

Is there a way to use zpy so that it integrates well with conda?
For example, in my setup conda stores envs in ~/.local/pkg/conda/envs, so zpy would need to use that, and with the name of the env, not the current hash (AFAIK conda finds myenv by checking ~/.local/pkg/conda/envs/myenv).

Completions for everything

May be able to use the zpy function to add documentation messages to the completion functions as well.

Create demo container

Create with buildah, base on alpine, include python, zsh, pcregrep, fzf, micro, git, highlight, and a friendly zsh environment (maybe zulu for the simplicity/size; need to compare to prezto or others). Ensure completions and decent prompt info.

Push to dockerhub.

Consider default volume mounting.

Will allow users to quickly try the project out, either totally inside or interacting with their local system. Also will be used for better demo videos/screenshots/asciicasts.

Maybe use same container for tests.

subcommands instead of separate commands

Would it make sense to make the different commands subcommands of zpy, while making the separate commands opt-out/opt-in?
My reasons are:

  1. zpy <subcmd> improves discoverability of the different commands. Right now zpy subcmd has good autocomplete but prints the docs, so these will need to be moved to a new help subcommand or something (so zpy help pypc instead of zpy pypc).
  2. I don't like polluting the global commands namespace, and prefer to define my own aliases for what I use most often. The current implementation forces these commands into the global namespace.

Thanks!

Add support for ugrep backend for doc parsing

Currently supported backends for documentation functions:

  • zsh built with --enable-pcre
  • rg (ripgrep)
  • pcre2grep (pcre2/pcre2-tools)
  • pcregrep (pcre/pcre-tools)

ugrep is probably good enough to work as well, so I'll have a look.

Should vpypyright set pythonVersion?

I just saw this update notice for the Sublime Text LSP package:

For developers working on LSP-* packages and using LSP-pyright for type-checking, it's now necessary
to tell pyright explicitly which version of Python to check against.
Do that by adding a pyrightconfig.json configuration file in the root of the LSP-* package:

{
    "pythonVersion": "3.11"
}

So it may be appropriate to set the corresponding version when calling vpypyright

Add some benchmarks

Create table with comparable commands, timed, for zpy, pipenv, poetry, pipx. Pipx may need its own table.

Use data to target performance improvements.

Improve packaging

Create:

  • arch pkgbuild
  • brew formula

Maybe:

  • alpine abuild
  • zsh plugin
  • pypi distribution
  • one of those awful curl-pipe options that some people actually like

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.