Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet: ignore nuget source during tool install #2642

Merged
merged 1 commit into from Dec 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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