• Stars
    star
    750
  • Rank 60,494 (Top 2 %)
  • Language
    Python
  • License
    Other
  • Created almost 13 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

pip2pi builds a PyPI-compatible package repository from pip requirements

pip2pi builds a PyPI-compatible package repository from pip requirements

https://travis-ci.org/wolever/pip2pi.png?branch=master

PyPI can go down, package maintainers can remove old tarballs, and downloading tarballs can take a long time. pip2pi helps to alleviate these problems by making it blindingly simple to maintain a PyPI-compatible repository of packages your software depends on.

$ pip2pi --help
Usage: pip2pi TARGET [PIP_OPTIONS] PACKAGES ...

Adds packages PACKAGES to PyPI-compatible package index at TARGET.

If TARGET contains ':' it will be treated as a remote path. The
package index will be built locally and rsync will be used to copy
it to the remote host.

PIP_OPTIONS can be any options accepted by `pip install -d`, like
`--index-url` or `--no-use-wheel`.

For example, to create a remote index:

    $ pip2pi example.com:/var/www/packages/ -r requirements.txt

To create a local index:

    $ pip2pi ~/Sites/packages/ foo==1.2

To pass arguments to pip:

    $ pip2pi ~/Sites/packages/ \
        --index-url https://example.com/simple \
        --no-use-wheel \
        -r requirements-base.txt \
        -r requirements-dev.txt \
        bar==3.1

Requirements

  1. pip
  2. A requirements.txt file for your project (optional, but useful)
  3. An HTTP server (optional, but useful)

Setup

Install pip2pi:

$ pip install pip2pi

And create the directory which will contain the tarballs of required packages, preferably somewhere under your web server's document root:

$ mkdir /var/www/packages/

Mirroring Packages

To mirror a package and all of its requirements, use pip2tgz:

$ pip2tgz packages/ foo==1.2
...
$ ls packages/
foo-1.2.tar.gz
bar-0.8.tar.gz

Note that pip2tgz passes package arguments directly to pip, so packages can be specified in any format that pip recognizes:

$ cat requirements.txt
foo==1.2
http://example.com/baz-0.3.tar.gz
$ pip2tgz packages/ -r requirements.txt bam-2.3/
...
$ ls packages/
foo-1.2.tar.gz
bar-0.8.tar.gz
baz-0.3.tar.gz
bam-2.3.tar.gz

Building a Package Index

A directory full of .tar.gz files can be turned into PyPI-compatible "simple" package index using the dir2pi command:

$ ls packages/
bar-0.8.tar.gz
baz-0.3.tar.gz
foo-1.2.tar.gz
$ dir2pi packages/
$ find packages/
packages/
packages/bar-0.8.tar.gz
packages/baz-0.3.tar.gz
packages/foo-1.2.tar.gz
packages/simple
packages/simple/bar
packages/simple/bar/bar-0.8.tar.gz
packages/simple/baz
packages/simple/baz/baz-0.3.tar.gz
packages/simple/foo
packages/simple/foo/foo-1.2.tar.gz

But that's a lot of work...

If running two commands seems like too much work... Take heart! The pip2pi command will run both of them for you... And it will use rsync to copy the new packages and index to a remote host!

$ pip2pi example.com:/var/www/packages/ foo==1.2
...
$ curl -I http://example.com/packages/simple/foo/foo-1.2.tar.gz | head -n1
HTTP/1.1 200 OK

But that's still too much work...

Take heart! Your shell's alias command can help. Add an alias like this to your shell's runtime configuration file (hint: ~/.bashrc or similar):

alias pip2acmeco="pip2pi dev.acmeco.com:/var/www/packages/"

Now updating your package index will be as simple as:

$ pip2acmeco foo==1.2 -r bar/requirements.txt

Using Your New Package Index

To use the new package index, pass the --index-url= argument to pip:

$ pip install --index-url=http://example.com/packages/simple/ foo

Or, once it has been mirrored, prefix you requirements.txt with --index-url=...:

$ cat requirements.txt
--index-url=http://example.com/packages/simple/
foo==1.2

Without a web server

You can use your package index offline, too:

$ pip install --index-url=file:///var/www/packages/simple foo==1.2

Some Tips

When installing packages from source via python setup.py install or python setup.py install, you may need to create a setup.cfg, which points to your package index. Here are some examples for an offline package index in your Windows, Linux, or Mac file system:

[easy_install]
# Windows
# index_url = file:///C:/pip2pi/simple/

# Linux
# index_url = file:///home/myusername/.pip2pi/simple/

# Mac
index_url = file:///Users/myusername/.pip2pi/simple/

Note the triple /// after file: -- two for the protocol, the third for the root of the local file system.

Keywords

  • Mirror PyPI
  • Offline PyPI
  • Create offline PyPI mirror

More Repositories

1

parameterized

Parameterized testing with any Python test framework
Python
829
star
2

pprintpp

pprint++: a drop-in replacement for pprint that's actually pretty
Python
408
star
3

python-cffi-example

A simple example Python + CFFI package (including testing, development, and packaging)
Python
115
star
4

autorepr

Easily implement __repr__, __str__, and __unicode__ methods
Python
49
star
5

git-blast

git-blast: show git branches sorted by last commit date
Python
38
star
6

browsercast

An IPython notebook plugin which facilitates lecture recording and playback.
JavaScript
34
star
7

pg-histogram

PostgreSQL functions for generating text-based histograms
PLpgSQL
31
star
8

wayslack

The Wayslack Machine: incrementally archive Slack messages and files using Slack's team export format
Python
23
star
9

Protocol-Informatics

Patches to the Protocol Informatics project to make it work with a numpy.
C
20
star
10

django-switchuser

django-switchuser makes it easy for an administrator to switch to temporarily switch to another account by visiting /su.
Python
16
star
11

libzbar-cffi

Python cffi-based bindings for the zbar QR decoder (Py2, Py3, and PyPy)
C
13
star
12

remora

remora: less insane JavaScript templating
JavaScript
13
star
13

dwdj

A collection of useful Django utilities.
Python
9
star
14

libqrencode-cffi

Fast, robust, and less incomplete Python cffi-based bindings for libqrencode
C
7
star
15

vcslog

Logs interactions with version control systems
Python
7
star
16

monte-carlo-monopoly

A Monte Carlo Monopoly simulation
C
6
star
17

openssl-x509-scripts

Scripts for creating an x509 certificate authority and using it to create and sign certificates.
4
star
18

nfa2regex

Converts NFAs (and DFAs) to a regular expressions using the state removal method.
Go
4
star
19

gevent-helpers

A collection of utilities which are helpful while developing with gevent
Python
4
star
20

jquery-wakeful

A REST-aware RPC protocol and jQuery based client
Python
3
star
21

dupecert

Duplicates SSL certificates
Python
3
star
22

safesort

Safely sort heterogeneous collections on Python 2 and 3
Python
3
star
23

pycon-slides

App which handles uploading of PyCon speaker slides
Python
3
star
24

git-ibisect

git-ibisect: interactively run git-bisect
Python
3
star
25

facebook-archive-parser

A fast Python-based parser for Facebook's archive format
Jupyter Notebook
3
star
26

python-smart-imports.vim

(WORK IN PROGRESS) python-smart-imports.vim - intelligently adds imports to Python files
Python
2
star
27

logging-assertions

Easily make assertions about logged messages in tests
Python
2
star
28

randchk

Randomly checksum files to ensure the integrity of backups.
Python
2
star
29

react-use-async-result

Simple, Sound, Type-Safe Promises in React Components
TypeScript
2
star
30

backup-chk

(WORK IN PROGRESS) incrementally verify backup integrity, with specific support for Time Machine
Go
1
star
31

clog-ansible

Ansible playbook for clog configuration
1
star
32

onioncrypt

onioncrypt: encrypt a file with multiple levels of encryption to multiple people.
Python
1
star
33

djto-testing-micropatterns-talk

Notes from my Django Toronto Testing Micropatterns talk
1
star
34

python-safe_cmp

safe_cmp: safe comparisons (total ordering) for any object in Python 3
Python
1
star
35

homebrew-git-blast

Homebrew Tap for git-blast
Ruby
1
star
36

postgres-functions

A collection of useful PostgreSQL functions
PLpgSQL
1
star
37

pg-change-logs

Automatically manages audit logs for Postgres databases
PLpgSQL
1
star
38

python-test-helper

A modular, composable interface for libraries to expose testing tools
1
star
39

songdb

An improved song database for #LoserKaraoke
JavaScript
1
star
40

wsgi-cloudflare-proxy-fix

Sets REMOTE_ADDR to the correct value when behind Cloudflare, based on the X-Real-IP header, when requests originate from Cloudflare's IP range.
Python
1
star