MCPcopy Create free account
hub / github.com/DataDog/datadog-agent / GoModule

Class GoModule

tasks/modules.py:10–129  ·  view source on GitHub ↗

A Go module abstraction. independent specifies whether this modules is supposed to exist independently of the datadog-agent module. If True, a check will run to ensure this is true.

Source from the content-addressed store, hash-verified

8
9
10class GoModule:
11 """
12 A Go module abstraction.
13 independent specifies whether this modules is supposed to exist independently of the datadog-agent module.
14 If True, a check will run to ensure this is true.
15 """
16
17 def __init__(
18 self,
19 path,
20 targets=None,
21 condition=lambda: True,
22 should_tag=True,
23 importable=True,
24 independent=False,
25 lint_targets=None,
26 ):
27 self.path = path
28 self.targets = targets if targets else ["."]
29 self.lint_targets = lint_targets if lint_targets else self.targets
30 self.condition = condition
31 self.should_tag = should_tag
32 # HACK: Workaround for modules that can be tested, but not imported (eg. gohai), because
33 # they define a main package
34 # A better solution would be to automatically detect if a module contains a main package,
35 # at the cost of spending some time parsing the module.
36 self.importable = importable
37 self.independent = independent
38
39 self._dependencies = None
40
41 def __version(self, agent_version):
42 """Return the module version for a given Agent version.
43 >>> mods = [GoModule("."), GoModule("pkg/util/log")]
44 >>> [mod.__version("7.27.0") for mod in mods]
45 ["v7.27.0", "v0.27.0"]
46 """
47 if self.path == ".":
48 return "v" + agent_version
49
50 return "v0" + agent_version[1:]
51
52 def __compute_dependencies(self):
53 """
54 Computes the list of github.com/DataDog/datadog-agent/ dependencies of the module.
55 """
56 prefix = "github.com/DataDog/datadog-agent/"
57 base_path = os.getcwd()
58 mod_parser_path = os.path.join(base_path, "internal", "tools", "modparser")
59
60 if not os.path.isdir(mod_parser_path):
61 raise Exception(f"Cannot find go.mod parser in {mod_parser_path}")
62
63 try:
64 output = subprocess.check_output(
65 ["go", "run", ".", "-path", os.path.join(base_path, self.path), "-prefix", prefix],
66 cwd=mod_parser_path,
67 ).decode("utf-8")

Callers 3

process_input_argsFunction · 0.85
get_modified_packagesFunction · 0.85
modules.pyFile · 0.85

Calls

no outgoing calls

Tested by 2

process_input_argsFunction · 0.68
get_modified_packagesFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…