init: Use locals() in configure() to avoid explicitly listing **kwds.

+ Update CHANGES.
This commit is contained in:
ankostis on tokoti 2015-12-21 01:06:19 +02:00
parent 912d405a83
commit 011c79b8bf
5 changed files with 107 additions and 88 deletions

View File

@ -6,21 +6,39 @@ Changelog
"Ssss-elections" bug-fix & maintenance release.
- Upgrade bottle 1.11.6-->1.13-dev.
- Fixes `MAX_PARAM` limiting dependencies(#82)
- Rework main startup and standalone:
- New standalone generation based on ZIPed wheel archive.
- Replace all sys.module mechanics with relative imports.
- Fix gevent monkeypatching (#49).
- #53: Like PyPI, HREF-links contain package's md5-hashes in their fragment.
- #91: Attempt to fix register http failures (thanks to @ Tythos and @petri).
- Test actual clients (ie `pip`, `Twine`, `setuptools`).
- Test spurious `setuptools` failures.
- NOT FIXED! Still getting spurious failures.
- Various fixes:
- #96: Fix program's requirement (i.e. add passlib as extra-requirement).
provide requirements files also for developers.
- #95: Add missing loop-teminators in bottle-templates (thanks to @bmflynn).
- Fixes `MAX_PARAM` limiting dependencies(#82)
- Rework main startup and standalone:
- New standalone generation based on ZIPed wheel archive.
- Replace all sys.module mechanics with relative imports.
- Fix gevent monkeypatching (#49).
- Simplify definition of config-options on startup.
- Move startup-options validations out of `main()` and into `pypiserver.core`
package, to validate also start-up from API-clients.
- #97: Add `--auther` non cmd-line startup-option to allow for alternative
authentication methods (non HtPasswdFile-based one) to be defined by
API-clients (thanks @Tythos).
- #53: Like PyPI, HREF-links now contain package's md5-hashes in their fragment.
Add `--hash_algo` cmd-line option to turn-off or specify other *hashlib*
message-digest algorithms (e.g. `sha256` is a safer choice, set it to `off`
to avoid any performance penalty if hosting a lot of packages).
- #91: Attempt to fix register http failures (thanks to @ Tythos and @petri).
- Test actual clients (ie `pip`, `Twine`, `setuptools`).
- Test spurious `setuptools` failures.
- NOT FIXED! Still getting spurious failures.
- Various other fixes:
- #96: Fix program's requirement (i.e. add passlib as extra-requirement).
provide requirements files also for developers.
- #95: Add missing loop-terminators in bottle-templates (thanks to @bmflynn).
1.1.8 (2015-09-15)

View File

@ -26,14 +26,12 @@ class Configuration(object):
def update(self, props):
d = props if isinstance(props, dict) else vars(props)
vars(self).update(props)
vars(self).update(d)
DEFAULT_SERVER = "auto"
def default_config():
c = Configuration(
VERSION=version,
def default_config(
root=None,
host = "0.0.0.0",
port = 8080,
@ -52,18 +50,76 @@ def default_config():
log_err_frmt = "%(body)s: %(exception)s \n%(traceback)s",
welcome_file = None,
cache_control = None,
)
auther=None,
VERSION=__version__):
"""
Fetch default-opts with overridden kwds, capable of starting-up pypiserver.
Does not validate overridden options.
Example usage::
kwds = pypiserver.default_config(<override_kwds> ...)
## More modifications on kwds.
pypiserver.app(**kwds)``.
Kwds correspond to same-named cmd-line opts, with '-' --> '_' substitution.
Non standard args are described below:
:param return_defaults_only:
When `True`, returns defaults, otherwise,
configures "runtime" attributes and returns also the "packages"
found in the roots.
:param root:
A list of paths, derived from the packages specified on cmd-line.
:param redirect_to_fallback:
see :option:`--disable-fallback`
:param authenticated:
see :option:`--authenticate`
:param password_file:
see :option:`--passwords`
:param log_file:
see :option:`--log-file`
Not used, passed here for logging it.
:param log_frmt:
see :option:`--log-frmt`
Not used, passed here for logging it.
:param callable auther:
An API-only options that if it evaluates to a callable,
it is invoked to allow access to protected operations
(instead of htpaswd mechanism) like that::
auther(username, password): bool
When defined, `password_file` is ignored.
:param host:
see :option:`--interface`
Not used, passed here for logging it.
:param port:
see :option:`--port`
Not used, passed here for logging it.
:param server:
see :option:`--server`
Not used, passed here for logging it.
:param verbosity:
see :option:`-v`
Not used, passed here for logging it.
:param VERSION:
Not used, passed here for logging it.
:return: a dict of defaults
"""
return locals()
return c
def app(**kwds):
"""
:param dict kwds:
May use ``**vars(default_config())`.
Any overrides for defaults, as fetched by :func:`default_config()`.
"""
from . import core, _app, bottle
from . import core, _app
bottle.debug(True)
kwds = default_config(**kwds)
config, packages = core.configure(**kwds)
_app.config = config
_app.packages = packages

View File

@ -154,7 +154,7 @@ def main(argv=None):
command = "serve"
c = pypiserver.default_config()
c = pypiserver.Configuration(**pypiserver.default_config())
update_dry_run = True,
update_directory = None,
@ -191,7 +191,7 @@ def main(argv=None):
try:
c.port = int(v)
except Exception as ex:
sys.exit("Invalid port(%r)!" % v)
sys.exit("Invalid port(%r) due to: %s" % (v, ex))
elif k in ("-a", "--authenticate"):
c.authenticated = [a.lower()
for a in re.split("[, ]+", v.strip(" ,"))
@ -280,13 +280,14 @@ def main(argv=None):
import gevent.monkey # @UnresolvedImport
gevent.monkey.patch_all()
from pypiserver.bottle import server_names, run
if c.server not in server_names:
from pypiserver import bottle
if c.server not in bottle.server_names:
sys.exit("unknown server %r. choose one of %s" % (
c.server, ", ".join(server_names.keys())))
c.server, ", ".join(bottle.server_names.keys())))
bottle.debug(True)
app = pypiserver.app(**vars(c))
run(app=app, host=c.host, port=c.port, server=c.server)
bottle.run(app=app, host=c.host, port=c.port, server=c.server)
if __name__ == "__main__":

View File

@ -16,67 +16,11 @@ from . import Configuration
log = logging.getLogger(__file__)
def configure(root=None,
redirect_to_fallback=True,
fallback_url=None,
authenticated=None,
password_file=None,
overwrite=False,
hash_algo='md5',
log_file=None,
log_frmt=None,
log_req_frmt=None,
log_res_frmt=None,
log_err_frmt=None,
welcome_file=None,
cache_control=None,
auther=None,
host=None, port=None, server=None, verbosity=None, VERSION=None
):
def configure(**kwds):
"""
:param root:
A list of paths, derived from the packages specified on cmd-line.
:param redirect_to_fallback:
see :option:`--disable-fallback`
:param authenticated:
see :option:`--authenticate`
:param password_file:
see :option:`--passwords`
:param log_file:
see :option:`--log-file`
Not used, passed here for logging it.
:param log_frmt:
see :option:`--log-frmt`
Not used, passed here for logging it.
:param callable auther:
An API-only options that if it evaluates to a callable,
it is invoked to allow access to protected operations
(instead of htpaswd mechanism) like that::
auther(username, password): bool
When defined, `password_file` is ignored.
:param host:
see :option:`--interface`
Not used, passed here for logging it.
:param port:
see :option:`--port`
Not used, passed here for logging it.
:param server:
see :option:`--server`
Not used, passed here for logging it.
:param verbosity:
see :option:`-v`
Not used, passed here for logging it.
:param VERSION:
Not used, passed here for logging it.
:return: a 2-tuple (Configure, package-list)
"""
return _configure(**locals())
def _configure(**kwds):
c = Configuration(**kwds)
log.info("+++Pypiserver invoked with: %s", c)

View File

@ -25,7 +25,7 @@ def _app(app):
@pytest.fixture
def app(tmpdir):
from pypiserver import app
return app(root=tmpdir.strpath)
return app(root=tmpdir.strpath, authenticated=[])
@pytest.fixture