(
prefix: Prefix,
version: str,
additional_dependencies: Sequence[str],
)
| 53 | |
| 54 | |
| 55 | def 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 | ) |
nothing calls this directly
no test coverage detected