From 9883120adb58ebd779d95126c0ed7415445f5ce4 Mon Sep 17 00:00:00 2001 From: stephanep Date: Wed, 10 Sep 2014 10:59:07 +0200 Subject: [PATCH 1/2] Fix some PEP8 conventions --- pypiserver/_app.py | 24 ++++++++++++++++-------- pypiserver/core.py | 26 +++++++++++++++++++------- pypiserver/manage.py | 13 ++++++++----- 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/pypiserver/_app.py b/pypiserver/_app.py index 0335cce..7cb645e 100644 --- a/pypiserver/_app.py +++ b/pypiserver/_app.py @@ -1,4 +1,11 @@ -import sys, os, io, itertools, zipfile, mimetypes, logging, pkg_resources +import sys +import os +import io +import itertools +import zipfile +import mimetypes +import logging +import pkg_resources try: from io import BytesIO @@ -18,7 +25,7 @@ log = logging.getLogger('pypiserver.http') packages = None -class configuration(object): +class Configuration(object): def __init__(self): self.fallback_url = "http://pypi.python.org/simple" self.redirect_to_fallback = True @@ -26,7 +33,7 @@ class configuration(object): self.welcome_file = None self.welcome_msg = None -config = configuration() +config = Configuration() def validate_user(username, password): @@ -97,7 +104,7 @@ def configure(root=None, for r in roots: try: os.listdir(r) - except Exception: + except OSError: err = sys.exc_info()[1] sys.exit("Error: while trying to list %r: %s" % (r, err)) @@ -215,7 +222,7 @@ def update(): zip_data = content.file.read() try: zf = zipfile.ZipFile(BytesIO(zip_data)) - info = zf.getinfo('index.html') + zf.getinfo('index.html') except Exception: raise HTTPError(400, output="not a zip file") return "" @@ -283,8 +290,8 @@ def simple(prefix=""): if config.redirect_to_fallback: return redirect("%s/%s/" % (config.fallback_url.rstrip("/"), prefix)) return HTTPError(404) - res = ["Links for %s\n" % prefix] - res.append("

Links for %s

\n" % prefix) + res = ["Links for %s\n" % prefix, + "

Links for %s

\n" % prefix] for x in files: abspath = urljoin(fp, "../../packages/%s" % x.replace("\\", "/")) @@ -301,7 +308,8 @@ def list_packages(): if not fp.endswith("/"): fp += "/" - files = [x.relfn for x in sorted(find_packages(packages()), key=lambda x: (os.path.dirname(x.relfn), x.pkgname, x.parsed_version))] + files = [x.relfn for x in sorted(find_packages(packages()), + key=lambda x: (os.path.dirname(x.relfn), x.pkgname, x.parsed_version))] res = ["Index of packages\n"] for x in files: diff --git a/pypiserver/core.py b/pypiserver/core.py index a0a2288..d6f4f75 100755 --- a/pypiserver/core.py +++ b/pypiserver/core.py @@ -1,10 +1,18 @@ #! /usr/bin/env python """minimal PyPI like server for use with pip/easy_install""" -import os, sys, getopt, re, mimetypes, warnings, itertools, logging +import os +import sys +import getopt +import re +import mimetypes +import warnings +import itertools +import logging warnings.filterwarnings("ignore", "Python 2.5 support may be dropped in future versions of Bottle") from pypiserver import bottle, __version__, app + sys.modules["bottle"] = bottle from bottle import run, server_names @@ -32,7 +40,7 @@ def _parse_version_parts(s): if part in ['', '.']: continue if part[:1] in '0123456789': - yield part.zfill(8) # pad for numeric comparison + yield part.zfill(8) # pad for numeric comparison else: yield '*' + part @@ -51,7 +59,9 @@ def parse_version(s): # -- end of distribute's code -_archive_suffix_rx = re.compile(r"(\.zip|\.tar\.gz|\.tgz|\.tar\.bz2|-py[23]\.\d-.*|\.win-amd64-py[23]\.\d\..*|\.win32-py[23]\.\d\..*|\.egg)$", re.IGNORECASE) +_archive_suffix_rx = re.compile( + r"(\.zip|\.tar\.gz|\.tgz|\.tar\.bz2|-py[23]\.\d-.*|\.win-amd64-py[23]\.\d\..*|\.win32-py[23]\.\d\..*|\.egg)$", + re.IGNORECASE) wheel_file_re = re.compile( r"""^(?P(?P.+?)-(?P\d.*?)) @@ -102,7 +112,7 @@ def is_allowed_path(path_part): return not (p.startswith(".") or "/." in p) -class pkgfile(object): +class PkgFile(object): def __init__(self, **kw): self.__dict__.update(kw) @@ -122,11 +132,11 @@ def listdir(root): continue res = guess_pkgname_and_version(x) if not res: - ##Seems the current file isn't a proper package + # #Seems the current file isn't a proper package continue pkgname, version = res if pkgname: - yield pkgfile(fn=fn, root=root, relfn=fn[len(root) + 1:], + yield PkgFile(fn=fn, root=root, relfn=fn[len(root) + 1:], pkgname=pkgname, version=version, parsed_version=parse_version(version)) @@ -409,6 +419,7 @@ def main(argv=None): if command == "update": packages = frozenset(itertools.chain(*[listdir(r) for r in roots])) from pypiserver import manage + manage.update(packages, update_directory, update_dry_run, stable_only=update_stable_only) return @@ -424,7 +435,8 @@ def main(argv=None): cache_control=cache_control, ) server = server or "auto" - sys.stdout.write("This is pypiserver %s serving %r on http://%s:%s\n\n" % (__version__, ", ".join(roots), host, port)) + sys.stdout.write( + "This is pypiserver %s serving %r on http://%s:%s\n\n" % (__version__, ", ".join(roots), host, port)) sys.stdout.flush() run(app=a, host=host, port=port, server=server) diff --git a/pypiserver/manage.py b/pypiserver/manage.py index 6609888..eaa52bc 100644 --- a/pypiserver/manage.py +++ b/pypiserver/manage.py @@ -1,8 +1,10 @@ - -import sys, os -from pypiserver import core +import sys +import os from subprocess import call +from pypiserver import core + + if sys.version_info >= (3, 0): from xmlrpc.client import Server @@ -10,7 +12,8 @@ if sys.version_info >= (3, 0): return Server(url) else: from xmlrpclib import Server, Transport - import httplib, urllib + import httplib + import urllib class ProxiedTransport(Transport): @@ -79,7 +82,7 @@ def build_releases(pkg, versions): for x in versions: parsed_version = core.parse_version(x) if parsed_version > pkg.parsed_version: - yield core.pkgfile(version=x, + yield core.PkgFile(version=x, parsed_version=parsed_version, pkgname=pkg.pkgname, replaces=pkg) From c6a79ef9c27a44088f833c449fa3ee6197854a22 Mon Sep 17 00:00:00 2001 From: "Kostis Anagnostopoulos, Yoga-2" Date: Mon, 16 Feb 2015 23:16:21 +0100 Subject: [PATCH 2/2] FIX test with PEP8-PkgFile class. --- tests/test_manage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_manage.py b/tests/test_manage.py index e1dc4ef..f741d19 100755 --- a/tests/test_manage.py +++ b/tests/test_manage.py @@ -1,7 +1,7 @@ #! /usr/bin/env py.test import pytest, py -from pypiserver.core import parse_version, pkgfile, guess_pkgname_and_version +from pypiserver.core import parse_version, PkgFile, guess_pkgname_and_version from pypiserver.manage import is_stable_version, build_releases, filter_stable_releases, filter_latest_pkgs @@ -13,7 +13,7 @@ def touch_files(root, files): def pkgfile_from_path(fn): pkgname, version = guess_pkgname_and_version(fn) - return pkgfile(root=py.path.local(fn).parts()[1].strpath, + return PkgFile(root=py.path.local(fn).parts()[1].strpath, fn=fn, pkgname=pkgname, version=version, parsed_version=parse_version(version))