These are chat archives for cherrypy/cherrypy

28th
Dec 2017
Andrew Schamp
@schamp
Dec 28 2017 01:49

hi everyone. I'm looking into the covercp stuff, as described here: http://docs.cherrypy.org/en/latest/pkg/cherrypy.lib.html#module-cherrypy.lib.covercp

it's not working, when I try to call serve() as described I get:

cherrypy/lib/covercp.py", line 377, in serve
    if coverage is None:
UnboundLocalError: local variable 'coverage' referenced before assignment

The relevant source snippit is this:

def serve(path=localFile, port=8080, root=None):
    if coverage is None:
        raise ImportError('The coverage module could not be imported.')
    from coverage import coverage
    cov = coverage(data_file=path)
    cov.load()

it seems to me like the from coverage import coverage should come before if converage is None. but perhaps not -- am I missing something about how this should work?

Sviatoslav Sydorenko
@webknjaz
Dec 28 2017 23:44
@ingoogni I think not, you may use different callables for that, but move common code into another helper function
Sviatoslav Sydorenko
@webknjaz
Dec 28 2017 23:52

@schamp Hi, it's an ancient code nobody looked at for decade, so it's probably outdated. PRs are welcome anyway :)

From code I see that there's a try/except importing required module at the top. Also, the docstring there explains that there should be additional requirement from 2001 found and downloaded.

So it's a good field for refactoring/improvements.