MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / install_environment

Function install_environment

pre_commit/languages/dotnet.py:55–111  ·  view source on GitHub ↗
(
        prefix: Prefix,
        version: str,
        additional_dependencies: Sequence[str],
)

Source from the content-addressed store, hash-verified

53
54
55def install_environment(
56 prefix: Prefix,
57 version: str,
58 additional_dependencies: Sequence[str],
59) -> None:
60 lang_base.assert_version_default('dotnet', version)
61 lang_base.assert_no_additional_deps('dotnet', additional_dependencies)
62
63 envdir = lang_base.environment_dir(prefix, ENVIRONMENT_DIR, version)
64 build_dir = prefix.path('pre-commit-build')
65
66 # Build & pack nupkg file
67 lang_base.setup_cmd(
68 prefix,
69 (
70 'dotnet', 'pack',
71 '--configuration', 'Release',
72 '--property', f'PackageOutputPath={build_dir}',
73 ),
74 )
75
76 nupkg_dir = prefix.path(build_dir)
77 nupkgs = [x for x in os.listdir(nupkg_dir) if x.endswith('.nupkg')]
78
79 if not nupkgs:
80 raise AssertionError('could not find any build outputs to install')
81
82 for nupkg in nupkgs:
83 with zipfile.ZipFile(os.path.join(nupkg_dir, nupkg)) as f:
84 nuspec, = (x for x in f.namelist() if x.endswith('.nuspec'))
85 with f.open(nuspec) as spec:
86 tree = xml.etree.ElementTree.parse(spec)
87
88 namespace = re.match(r'{.*}', tree.getroot().tag)
89 if not namespace:
90 raise AssertionError('could not parse namespace from nuspec')
91
92 tool_id_element = tree.find(f'.//{namespace[0]}id')
93 if tool_id_element is None:
94 raise AssertionError('expected to find an "id" element')
95
96 tool_id = tool_id_element.text
97 if not tool_id:
98 raise AssertionError('"id" element missing tool name')
99
100 # Install to bin dir
101 with _nuget_config_no_sources() as nuget_config:
102 lang_base.setup_cmd(
103 prefix,
104 (
105 'dotnet', 'tool', 'install',
106 '--configfile', nuget_config,
107 '--tool-path', os.path.join(envdir, BIN_DIR),
108 '--add-source', build_dir,
109 tool_id,
110 ),
111 )

Callers

nothing calls this directly

Calls 3

_nuget_config_no_sourcesFunction · 0.85
pathMethod · 0.80
matchMethod · 0.45

Tested by

no test coverage detected