Merge pull request #2642 from rkm/fix/dotnet-nuget-config

dotnet: ignore nuget source during tool install
This commit is contained in:
Anthony Sottile 2022-12-21 15:04:41 -05:00 committed by GitHub
commit bb27ea32cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,7 @@ from __future__ import annotations
import contextlib import contextlib
import os.path import os.path
import re import re
import tempfile
import xml.etree.ElementTree import xml.etree.ElementTree
import zipfile import zipfile
from typing import Generator from typing import Generator
@ -38,6 +39,22 @@ def in_env(prefix: Prefix) -> Generator[None, None, None]:
yield yield
@contextlib.contextmanager
def _nuget_config_no_sources() -> Generator[str, None, None]:
with tempfile.TemporaryDirectory() as tmpdir:
nuget_config = os.path.join(tmpdir, 'nuget.config')
with open(nuget_config, 'w') as f:
f.write(
'<?xml version="1.0" encoding="utf-8"?>'
'<configuration>'
' <packageSources>'
' <clear />'
' </packageSources>'
'</configuration>',
)
yield nuget_config
def install_environment( def install_environment(
prefix: Prefix, prefix: Prefix,
version: str, version: str,
@ -85,15 +102,17 @@ def install_environment(
raise AssertionError('"id" element missing tool name') raise AssertionError('"id" element missing tool name')
# Install to bin dir # Install to bin dir
helpers.run_setup_cmd( with _nuget_config_no_sources() as nuget_config:
prefix, helpers.run_setup_cmd(
( prefix,
'dotnet', 'tool', 'install', (
'--tool-path', os.path.join(envdir, BIN_DIR), 'dotnet', 'tool', 'install',
'--add-source', build_dir, '--configfile', nuget_config,
tool_id, '--tool-path', os.path.join(envdir, BIN_DIR),
), '--add-source', build_dir,
) tool_id,
),
)
# Clean the git dir, ignoring the environment dir # Clean the git dir, ignoring the environment dir
clean_cmd = ('git', 'clean', '-ffxd', '-e', f'{ENVIRONMENT_DIR}-*') clean_cmd = ('git', 'clean', '-ffxd', '-e', f'{ENVIRONMENT_DIR}-*')