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

pybuilder / pybuilder / 16613314016

30 Jul 2025 04:14AM UTC coverage: 84.008% (-0.1%) from 84.146%
16613314016

push

github

arcivanov
Release 0.13.16

2167 of 2671 branches covered (81.13%)

Branch coverage included in aggregate %.

5534 of 6496 relevant lines covered (85.19%)

36.25 hits per line

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

1.49
/src/main/python/pybuilder/plugins/python/_coverage_shim.py
1
#   -*- coding: utf-8 -*-
2
#
3
#   This file is part of PyBuilder
4
#
5
#   Copyright 2011-2020 PyBuilder Team
6
#
7
#   Licensed under the Apache License, Version 2.0 (the "License");
8
#   you may not use this file except in compliance with the License.
9
#   You may obtain a copy of the License at
10
#
11
#       http://www.apache.org/licenses/LICENSE-2.0
12
#
13
#   Unless required by applicable law or agreed to in writing, software
14
#   distributed under the License is distributed on an "AS IS" BASIS,
15
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
#   See the License for the specific language governing permissions and
17
#   limitations under the License.
18

19
import ast
×
20
import sys
×
21
from importlib.abc import Loader, MetaPathFinder
×
22
from importlib.util import spec_from_loader
×
23
from os.path import dirname
×
24

25

26
class CoverageImporter(Loader, MetaPathFinder):
×
27
    def __init__(self, coverage_parent_dir):
×
28
        self.coverage_parent_dir = coverage_parent_dir
×
29
        self._in_import = False
×
30

31
    def find_module(self, fullname, path=None):
×
32
        """
33
        Return self when fullname starts with `coverage`.
34
        """
35
        if self._in_import:
×
36
            return
×
37
        if fullname == "coverage":
×
38
            return self
×
39

40
    def load_module(self, fullname):
×
41
        """
42
        Load coverage only and remove coverage from path thereafter
43
        """
44
        sys.path.append(self.coverage_parent_dir)
×
45
        self._in_import = True
×
46
        try:
×
47
            return __import__(fullname)
×
48
        finally:
49
            self._in_import = False
×
50
            del sys.path[-1]
×
51

52
    def find_spec(self, fullname, path=None, target=None):
×
53
        """Return a module spec for vendored names."""
54
        return (
44✔
55
            spec_from_loader(fullname, self)
56
            if fullname == "coverage" else None
57
        )
58

59
    def install(self):
×
60
        """
61
        Install this importer into sys.meta_path if not already present.
62
        """
63
        if self not in sys.meta_path:
×
64
            sys.meta_path.append(self)
×
65

66

67
if __name__ == "__main__":
×
68
    # Need to preserve location for _coverage_util import
69
    main_file_dir = dirname(__import__("__main__").__file__)
×
70

71
    self = sys.argv[0]
×
72
    config_literal = sys.argv[1]
×
73
    del sys.argv[:2]
×
74
    del sys.path[0]
×
75

76
    config = ast.literal_eval(config_literal)
×
77

78
    # Make sure we can actually load coverage
79
    CoverageImporter(config["cov_parent_dir"]).install()
×
80

81
    sys.path.append(main_file_dir)
×
82

83
    from _coverage_util import save_normalized_coverage, patch_coverage
×
84

85
    del sys.path[-1]
×
86

87
    # Patch coverage
88
    patch_coverage()
×
89

90
    from coverage import coverage as coverage_factory
×
91
    from coverage.execfile import PyRunner
×
92

93
    coverage = coverage_factory(*(config.get("cov_args", ())), **(config.get("cov_kwargs", {})))
×
94
    source_path = config["cov_source_path"]
×
95
    omit_patterns = config["cov_omit_patterns"]
×
96

97
    args = sys.argv
×
98
    module = False
×
99
    if args and args[0] == "-m":
×
100
        module = True
×
101
        args = args[1:]
×
102

103
    runner = PyRunner(args, as_module=module)
×
104
    runner.prepare()
×
105

106
    coverage.start()
×
107
    try:
×
108
        runner.run()
×
109
    finally:
110
        coverage.stop()
×
111
        save_normalized_coverage(coverage, source_path, omit_patterns)
×
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