Skip to content

Commit

Permalink
dotnet: ignore nuget source during tool install
Browse files Browse the repository at this point in the history
  • Loading branch information
rkm authored and asottile committed Dec 21, 2022
1 parent bce513f commit c38e0c7
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions pre_commit/languages/dotnet.py
Expand Up @@ -3,6 +3,7 @@
import contextlib
import os.path
import re
import tempfile
import xml.etree.ElementTree
import zipfile
from typing import Generator
Expand Down Expand Up @@ -38,6 +39,22 @@ def in_env(prefix: Prefix) -> Generator[None, None, None]:
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(
prefix: Prefix,
version: str,
Expand Down Expand Up @@ -85,15 +102,17 @@ def install_environment(
raise AssertionError('"id" element missing tool name')

# Install to bin dir
helpers.run_setup_cmd(
prefix,
(
'dotnet', 'tool', 'install',
'--tool-path', os.path.join(envdir, BIN_DIR),
'--add-source', build_dir,
tool_id,
),
)
with _nuget_config_no_sources() as nuget_config:
helpers.run_setup_cmd(
prefix,
(
'dotnet', 'tool', 'install',
'--configfile', nuget_config,
'--tool-path', os.path.join(envdir, BIN_DIR),
'--add-source', build_dir,
tool_id,
),
)

# Clean the git dir, ignoring the environment dir
clean_cmd = ('git', 'clean', '-ffxd', '-e', f'{ENVIRONMENT_DIR}-*')
Expand Down

0 comments on commit c38e0c7

Please sign in to comment.