• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / grokcore.startup / 14821073685

15 Jan 2025 07:31AM UTC coverage: 31.667% (+0.1%) from 31.551%
14821073685

push

github

web-flow
Update Python version support. (#15)

* Drop support for Python 3.7, 3.8.
* Add support for Python 3.13.

7 of 30 branches covered (23.33%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 2 files covered. (0.0%)

1 existing line in 1 file now uncovered.

50 of 150 relevant lines covered (33.33%)

0.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.25
/src/grokcore/startup/startup.py
1
import code
1✔
2
import os.path
1✔
3
import sys
1✔
4

5
import zope.app.debug
1✔
6
import zope.app.wsgi
1✔
7
from zope.component import provideAdapter
1✔
8
from zope.dottedname.resolve import resolve
1✔
9
from zope.publisher.interfaces import IReRaiseException
1✔
10

11

12
def application_factory(global_conf, **local_conf):
1✔
13
    zope_conf = local_conf.get(
1✔
14
        'zope_conf',
15
        global_conf.get('zope_conf',
16
                        os.path.join('parts', 'etc', 'zope.conf')))
17
    return zope.app.wsgi.getWSGIApplication(zope_conf)
1✔
18

19

20
def debug_application_factory(global_conf, **local_conf):
1✔
21
    # First create the application itself
22
    app = application_factory(global_conf, **local_conf)
1✔
23
    # Then register the IReRaiseException adaptation for
24
    # various types of exceptions that are exempt from being
25
    # raised by the publisher.
26

27
    def do_not_reraise_exception(context):
1✔
28
        return lambda: False
1✔
29
    iface_names = local_conf.get('exempt-exceptions', '').split(',')
1✔
30
    for name in iface_names:
1✔
31
        name = name.strip()
1✔
32
        if not name:
1✔
33
            continue
1✔
34
        iface = resolve(name)
1✔
35
        provideAdapter(do_not_reraise_exception, (iface, ), IReRaiseException)
1✔
36
    # Return the created application
37
    return app
1✔
38

39

40
def _classic_debug_prompt(debugger):
1✔
41
    globals_ = {
×
42
        'debugger': debugger,
43
        'app': debugger,
44
        'root': debugger.root()}
45
    # Invoke an interactive interpreter prompt
46
    banner = (
×
47
        "Welcome to the interactive debug prompt.\n"
48
        "The 'root' variable contains the ZODB root folder.\n"
49
        "The 'app' variable contains the Debugger, 'app.publish(path)' "
50
        "simulates a request.")
51
    code.interact(banner=banner, local=globals_)
×
52

53

54
def _ipython_debug_prompt(debugger):
1✔
55
    from grokcore.startup.debug import ipython_debug_prompt
×
56
    return ipython_debug_prompt(debugger)
×
57

58

59
def interactive_debug_prompt(zope_conf):
1✔
60
    db = zope.app.wsgi.config(zope_conf)
1✔
61
    debugger = zope.app.debug.Debugger.fromDatabase(db)
1✔
62
    if len(sys.argv) > 1:
1!
63
        # There're arguments passed to the command. We replicate the
64
        # "old" zopectl run command behaviour that would execfile()
65
        # the second argument.
66
        globals_ = {
1✔
67
            'debugger': debugger,
68
            'app': debugger,
69
            'root': debugger.root()}
70
        # The current first argument is the interactive_debugger command
71
        # itself. Pop it from the args list and as a result, the script
72
        # to run is the first argument.
73
        del sys.argv[0]
1✔
74
        globals_['__name__'] = '__main__'
1✔
75
        globals_['__file__'] = sys.argv[0]
1✔
76
        with open(sys.argv[0]) as f:
1✔
77
            exec(f.read(), globals_)
1✔
78
        # Housekeeping.
79
        db.close()
1✔
80
        sys.exit()
1✔
81
    # Start the interpreter.
82
    try:
×
83
        import IPython  # noqa: F401 imported but unused
×
NEW
84
    except ModuleNotFoundError:
×
UNCOV
85
        return _classic_debug_prompt(debugger)
×
86
    return _ipython_debug_prompt(debugger)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc