how to create local own pypi repository index without mirror?
how to create local own pypi repository index without mirror?
We have several own python packages and want to create local pypi repository for them using simple interface like https://pypi.python.org/simple/
This repository I want to create for local only without any mirrors due to security reason, and it will be put under apache's control
The command pypimirror
looks has to be initialized once, which needs to mirror.
pypimirror
How can I generate PyPi Simple Index based on local python packages.
Any other simple scripts for this ?
possible duplicate of How to roll my own pypi?
– aquavitae
Jan 27 '14 at 10:53
5 Answers
5
Since you asked to answer here:
Take a look at pip2pi
, it seems to be exactly what you are looking for.
pip2pi
this is the most simple way to handle for my case
– Larry Cai
Aug 6 '13 at 4:46
It looks like
pip2pi
is intended for public packages that are already on PyPI, is that correct? I thought the original question was about creating a repository for packages developed in-house.– Ken Williams
Jan 20 '17 at 5:20
pip2pi
We had a similar need at my company. Basically how can we upload "closed source" packages to an index while being able to install them as if they were on PyPI?
We have sponsored a project called devpi which acts as a PyPI cache (packages you access from PyPI will be cached on your server) as well as a powerful and fast index server. The documentation is available at http://doc.devpi.net/latest/.
Next on the roadmap is mirroring for multi geos deployment. To kick the tires on your machine takes about 5 minutes (look at the quick start guides). Finally devpi is compatible with both pip and easy_install (i.e. you do not need the devpi client installed on your machine).
Hope this help.
Little overkill for my simple case, but i vote it since it looks quite stable and easy to use.
– Larry Cai
Aug 28 '13 at 4:46
devpi is exactly what I was looking for. It acts as a pypi server, and you can use the default
pip
command for managing packages. Easy to setup and easy in use. For use in a virtual environment, the daemon can be started/stopped in post(de)activate hooks.– bouke
Apr 30 '14 at 6:31
pip
There is nothing special about the mirror, and you can use mod_rewrite
to set it up yourself.
mod_rewrite
Dump your packages in a directory that is mapped to a URL. Here I am using /url/to/my/pypi/
an an example. The folder hierarchy should be /foo/bar/simple/[name of package]/[name of tarball]
/url/to/my/pypi/
/foo/bar/simple/[name of package]/[name of tarball]
Add the following to .htaccess
or the global configuration for that directory where you packages are. The last block of lines is a fall back to the global pypi index:
.htaccess
Options +Indexes
RewriteEngine On
RewriteRule ^/robots.txt - [L]
RewriteRule ^/icons/.* - [L]
RewriteRule ^/index..* - [L]
RewriteCond /foo/bar/simple/ !-f
RewriteCond /foo/bar/simple/ !-d
RewriteRule ^/(.*)/?$ http://pypi.python.org/ [R,L]
Update your ~/.pip/pip.conf
to point to the new repository:
~/.pip/pip.conf
[global]
index-url = http://localhost/url/to/my/pypi/
Or use the -i http://localhost/url/to/my/pypi/
option at the command line.
-i http://localhost/url/to/my/pypi/
You would only do the "Options +Indexes" part of step #2 for "local only" as the question requested. But transparently redirecting to pypi for things that aren't local is also useful. :)
– dannysauer
Aug 14 '15 at 15:01
If you are talking about running simplepypi then you will have your server for adding packages and serve them out.
To quote the documentation:
- Running this on the setup.py of your favorite package:
python setup.py sdist upload -r local
If you were to use either os.walk
or glob.glob
on your local site-packages directory you could quickly filter for setup.py
in each of the packages/directories and invoke the above on them.
os.walk
glob.glob
setup.py
If you just need to create a directory of tar.gz files complete with a .html list of them then you can use glob.glob on the top level of your site-packages directory - tar.gz each directory in turn and add the resulting filename to a list - you can then generate your index.html from that list.
You can use any of a large number of template engines for this or generate it yourself:
import glob
filelist = glob.glob("*.tar.gz")
tags = ['<A href="file:Where/%s">%s</A>' % (s,s) for s in tags]
head = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
<META NAME="Generator" CONTENT="Python Script">
<META NAME="Keywords" CONTENT="Cheeseshop">
<META NAME="Description" CONTENT="List of local python packages">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" VLINK="#800000" ALINK="#FF00FF" BACKGROUND="?">
"""
tail = """</BODY></HTML>"""
tags.insert(0,head)
tags.append(tail)
page = "n".join(tags)
Then save or serve you page.
this demands one local pypi server, which I want to avoid.
– Larry Cai
Aug 5 '13 at 7:43
The simplest way is to organize the package distfiles into package-named dirs and run a simple HTTP server. No extra packages needed, Python's stdlib is enough. Directory structure example:
└── repodir
├── setuptools
│ └── setuptools-38.1.0-py2.py3-none-any.whl
│ └── setuptools-38.1.0.zip
│ └── setuptools-39.2.0-py2.py3-none-any.whl
│ └── setuptools-39.2.0.zip
├── wheel
│ └── wheel-0.31.1-py2.py3-none-any.whl
...
Start the server:
$ cd repodir/
$ python3 -m http.server -p 9000
$ # or for Python 2:
$ python2 -m SimpleHTTPServer -p 9000
The local repo is up and running. Now you can pass the repo to pip
:
pip
$ pip install wheel --extra-index-url=http://127.0.0.1:9000
or even persist the repo URL in the pip.conf
to not to enter it each time:
pip.conf
# pip.conf
[global]
extra-index-url=http://127.0.0.1:9000
thank, could try wheel now ;-)
– Larry Cai
Jul 2 at 7:19
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
possible duplicate of Setting up a local PyPi server with custom set of packages
– Piotr Dobrogost
Jan 24 '14 at 15:22