Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 9 commits
  • 10 files changed
  • 0 commit comments
  • 3 contributors
Showing with 110 additions and 59 deletions.
  1. +10 −0 CHANGELOG.txt
  2. +22 −0 README.rst
  3. +0 −4 dir2pi
  4. +1 −1 libpip2pi/__init__.py
  5. +20 −17 libpip2pi/commands.py
  6. +0 −4 pip2pi
  7. +0 −4 pip2tgz
  8. +7 −1 setup.py
  9. +44 −28 tests/test.py
  10. +6 −0 tox.ini
View
10 CHANGELOG.txt
@@ -1,3 +1,13 @@
+0.4.0 (2013-11-23)
+
+ * Added preliminary Python 3 support
+ (https://github.com/wolever/pip2pi/pull/18; thanks @wogg).
+
+0.3.0 (2013-11-10)
+
+ * Added Windows support, use setup.py ``console_scripts``
+ (https://github.com/wolever/pip2pi/pull/17; thanks @georgevreilly).
+
0.2.1 (2013-06-08)
* dir2pi will now do sensible things when it encounters egg files
View
22 README.rst
@@ -138,6 +138,28 @@ 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
========
View
4 dir2pi
@@ -1,4 +0,0 @@
-#!/usr/bin/env python
-import sys
-from libpip2pi.commands import dir2pi
-sys.exit(dir2pi())
View
2 libpip2pi/__init__.py
@@ -1 +1 @@
-__version__ = (0, 2, 1)
+__version__ = (0, 4, 0)
View
37 libpip2pi/commands.py
@@ -57,16 +57,16 @@ def file_to_package(file, basedir=None):
def dir2pi(argv=sys.argv):
if len(argv) != 2:
- print dedent("""
+ print(dedent("""
usage: dir2pi PACKAGE_DIR
Creates the directory PACKAGE_DIR/simple/ and populates it with the
directory structure required to use with pip's --index-url.
-
+
Assumes that PACKAGE_DIR contains a bunch of archives named
'package-name-version.ext' (ex 'foo-2.1.tar.gz' or
'foo-bar-1.3rc1.bz2').
-
+
This makes the most sense if PACKAGE_DIR is somewhere inside a
webserver's inside htdocs directory.
@@ -82,7 +82,7 @@ def dir2pi(argv=sys.argv):
packages/simple/foo/
packages/simple/foo/index.html
packages/simple/foo/foo-1.2.tar.gz
- """)
+ """))
return 1
pkgdir = argv[1]
if not os.path.isdir(pkgdir):
@@ -108,7 +108,10 @@ def dir2pi(argv=sys.argv):
pkg_new_basename = "-".join([pkg_name, pkg_rest])
symlink_target = os.path.join(pkg_dir, pkg_new_basename)
symlink_source = os.path.join("../../", pkg_basename)
- os.symlink(symlink_source, symlink_target)
+ if hasattr(os, "symlink"):
+ os.symlink(symlink_source, symlink_target)
+ else:
+ shutil.copy2(pkg_filepath, symlink_target)
pkg_name_html = cgi.escape(pkg_name)
pkg_index += "<a href='{0}/'>{0}</a><br />\n".format(pkg_name_html)
with open(os.path.join(pkg_dir, "index.html"), "a") as fp:
@@ -123,19 +126,19 @@ def dir2pi(argv=sys.argv):
@maintain_cwd
def pip2tgz(argv=sys.argv):
if len(argv) < 3:
- print dedent("""
+ print(dedent("""
usage: pip2tgz OUTPUT_DIRECTORY PACKAGE_NAME ...
Where PACKAGE_NAMES are any names accepted by pip (ex, `foo`,
`foo==1.2`, `-r requirements.txt`).
-
+
pip2tgz will download all packages required to install PACKAGE_NAMES and
save them to sanely-named tarballs in OUTPUT_DIRECTORY.
For example:
-
+
$ pip2tgz /var/www/packages/ -r requirements.txt foo==1.2 baz/
- """)
+ """))
return 1
outdir = os.path.abspath(argv[1])
@@ -180,12 +183,12 @@ def pip2tgz(argv=sys.argv):
os.chdir(outdir)
shutil.rmtree(tempdir)
- print "%s .tar.gz saved to %r" %(num_pakages, argv[1])
+ print("%s .tar.gz saved to %r" %(num_pakages, argv[1]))
return 0
def pip2pi(argv=sys.argv):
if len(argv) < 3:
- print dedent("""
+ print(dedent("""
usage: pip2pi TARGET PACKAGE_NAME ...
Combines pip2tgz and dir2pi, adding PACKAGE_NAME to package index
@@ -194,39 +197,39 @@ def pip2pi(argv=sys.argv):
If TARGET contains ':' it will be treated as a remote path. The
package index will be built locally then rsync will be used to copy
it to the remote host.
-
+
For example, to create a remote index:
$ pip2pi example.com:/var/www/packages/ -r requirements.txt
Or to create a local index:
$ pip2pi ~/Sites/packages/ foo==1.2
- """)
+ """))
return 1
target = argv[1]
pip_packages = argv[2:]
if ":" in target:
is_remote = True
- working_dir = tempfile.mkdtemp(prefix="pip2pi-working-dir")
+ working_dir = tempfile.mkdtemp(prefix="pip2pi-working-dir")
atexit.register(lambda: shutil.rmtree(working_dir))
else:
is_remote = False
working_dir = os.path.abspath(target)
res = pip2tgz([argv[0], working_dir] + pip_packages)
if res:
- print "pip2tgz returned an error; aborting."
+ print("pip2tgz returned an error; aborting.")
return res
res = dir2pi([argv[0], working_dir])
if res:
- print "dir2pi returned an error; aborting."
+ print("dir2pi returned an error; aborting.")
return res
if is_remote:
- print "copying temporary index at %r to %r..." %(working_dir, target)
+ print("copying temporary index at %r to %r..." %(working_dir, target))
check_call([
"rsync",
"--recursive", "--progress", "--links",
View
4 pip2pi
@@ -1,4 +0,0 @@
-#!/usr/bin/env python
-import sys
-from libpip2pi.commands import pip2pi
-sys.exit(pip2pi())
View
4 pip2tgz
@@ -1,4 +0,0 @@
-#!/usr/bin/env python
-import sys
-from libpip2pi.commands import pip2tgz
-sys.exit(pip2tgz())
View
8 setup.py
@@ -27,7 +27,13 @@
""",
long_description=long_description,
packages=find_packages(),
- scripts=["pip2pi", "pip2tgz", "dir2pi"],
+ entry_points={
+ 'console_scripts': [
+ 'dir2pi = libpip2pi.commands:dir2pi',
+ 'pip2pi = libpip2pi.commands:pip2pi',
+ 'pip2tgz = libpip2pi.commands:pip2tgz',
+ ],
+ },
license="BSD",
classifiers=[ x.strip() for x in """
Development Status :: 4 - Beta
View
72 tests/test.py
@@ -1,27 +1,42 @@
#!/usr/bin/env python
import os
-import urllib
+import sys
+try:
+ from urllib import unquote
+except ImportError: # python3
+ from urllib.parse import unquote
+
import random
import shutil
-import thread
import tempfile
+import unittest
+import threading
import posixpath
-import unittest2
import subprocess
-import SocketServer
-import SimpleHTTPServer
-from libpip2pi import commands as pip2pi_commands
+try:
+ from SocketServer import ThreadingMixIn
+ from BaseHTTPServer import HTTPServer
+ from SimpleHTTPServer import SimpleHTTPRequestHandler
+except ImportError: # python 3
+ from socketserver import ThreadingMixIn
+ from http.server import HTTPServer
+ from http.server import SimpleHTTPRequestHandler
+
BASE_PATH = os.path.abspath(os.path.dirname(__file__))
+PKG_BASE_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), "../")
+sys.path.append(PKG_BASE_PATH)
+
+from libpip2pi import commands as pip2pi_commands
class chdir(object):
""" A drop-in replacement for ``os.chdir`` which also acts as a context
manager.
>>> old_cwd = os.getcwd()
>>> with chdir("/usr/"):
- ... print "current dir:", os.getcwd()
+ ... print("current dir:", os.getcwd())
...
current dir: /usr
>>> os.getcwd() == old_cwd
@@ -59,7 +74,7 @@ def __repr__(self):
)
-class Pip2PiRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
+class Pip2PiRequestHandler(SimpleHTTPRequestHandler):
base_path = os.path.join(BASE_PATH, "assets/")
def translate_path(self, path):
@@ -73,7 +88,7 @@ def translate_path(self, path):
# abandon query parameters
path = path.split('?',1)[0]
path = path.split('#',1)[0]
- path = posixpath.normpath(urllib.unquote(path))
+ path = posixpath.normpath(unquote(path))
words = path.split('/')
words = filter(None, words)
path = self.base_path
@@ -85,32 +100,33 @@ def translate_path(self, path):
return path
-class Pip2PiTests(unittest2.TestCase):
+class Pip2PiTests(unittest.TestCase):
SERVER_PORT = random.randint(10000, 40000)
+ class BackgroundIt(threading.Thread):
+ server = None
+ def run(self):
+ self.server.serve_forever()
+
+ class ThreadingServer(ThreadingMixIn, HTTPServer):
+ pass
+
@classmethod
def setUpClass(cls):
- server_ready = thread.allocate_lock()
- server_ready.acquire()
- cls._server_thread = thread.start_new_thread(cls.spawn_http_server,
- (server_ready, ))
- server_ready.acquire()
-
+ cls._server_thread = cls.BackgroundIt()
+ cls.server = cls.ThreadingServer(("127.0.0.1", cls.SERVER_PORT),
+ Pip2PiRequestHandler)
+ cls._server_thread.server = cls.server
+ cls._server_thread.start()
+
@classmethod
def tearDownClass(cls):
cls.server.shutdown()
- @classmethod
- def spawn_http_server(cls, ready_lock):
- cls.server = SocketServer.TCPServer(("127.0.0.1", cls.SERVER_PORT),
- Pip2PiRequestHandler)
- ready_lock.release()
- cls.server.serve_forever()
-
def setUp(self):
os.chdir(BASE_PATH)
self._temp_dir = None
- print "\n" + "-" * 70
+ print("\n" + "-" * 70)
def tearDown(self):
if self._temp_dir is not None:
@@ -120,10 +136,10 @@ def assertDirsEqual(self, a, b):
res = subprocess.call(["diff", "-x", "*.tar.gz", "-r", a, b])
if res:
with chdir(a):
- print "1st directory:", a
+ print("1st directory:", a)
subprocess.call(["find", "."])
with chdir(b):
- print "2nd directory:", b
+ print("2nd directory:", b)
subprocess.call(["find", "."])
raise AssertionError("Directories %r and %r differ! (see errors "
"printed to stdout)" %(a, b))
@@ -139,7 +155,7 @@ def index_url(self):
return "--index-url=http://127.0.0.1:%s/simple/" %(self.SERVER_PORT, )
def exc(self, cmd, args):
- print "Running %s with: %s" %(cmd, args)
+ print("Running %s with: %s" %(cmd, args))
return getattr(pip2pi_commands, cmd)([cmd] + args)
def test_requirements_txt(self):
@@ -157,4 +173,4 @@ def test_eggs_in_packages(self):
self.assertDirsEqual("test_eggs_in_packages/", self.temp_dir)
if __name__ == "__main__":
- unittest2.main()
+ unittest.main()
View
6 tox.ini
@@ -0,0 +1,6 @@
+[tox]
+envlist = py27,py33
+
+[testenv]
+commands =
+ ./run-tests

No commit comments for this range

Something went wrong with that request. Please try again.