-
-
Notifications
You must be signed in to change notification settings - Fork 801
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
203 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
/.tox | ||
/dist | ||
/venv* | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import contextlib | ||
import os.path | ||
from typing import Generator | ||
from typing import Sequence | ||
from typing import Tuple | ||
|
||
import pre_commit.constants as C | ||
from pre_commit.envcontext import envcontext | ||
from pre_commit.envcontext import PatchesT | ||
from pre_commit.envcontext import Var | ||
from pre_commit.hook import Hook | ||
from pre_commit.languages import helpers | ||
from pre_commit.prefix import Prefix | ||
from pre_commit.util import clean_path_on_failure | ||
from pre_commit.util import rmtree | ||
|
||
ENVIRONMENT_DIR = 'dotnetenv' | ||
BIN_DIR = 'bin' | ||
|
||
get_default_version = helpers.basic_get_default_version | ||
healthy = helpers.basic_healthy | ||
|
||
|
||
def get_env_patch(venv: str) -> PatchesT: | ||
return ( | ||
('PATH', (os.path.join(venv, BIN_DIR), os.pathsep, Var('PATH'))), | ||
) | ||
|
||
|
||
@contextlib.contextmanager | ||
def in_env(prefix: Prefix) -> Generator[None, None, None]: | ||
directory = helpers.environment_dir(ENVIRONMENT_DIR, C.DEFAULT) | ||
envdir = prefix.path(directory) | ||
with envcontext(get_env_patch(envdir)): | ||
yield | ||
|
||
|
||
def install_environment( | ||
prefix: Prefix, | ||
version: str, | ||
additional_dependencies: Sequence[str], | ||
) -> None: | ||
helpers.assert_version_default('dotnet', version) | ||
helpers.assert_no_additional_deps('dotnet', additional_dependencies) | ||
|
||
envdir = prefix.path(helpers.environment_dir(ENVIRONMENT_DIR, version)) | ||
with clean_path_on_failure(envdir): | ||
build_dir = 'pre-commit-build' | ||
|
||
# Build & pack nupkg file | ||
helpers.run_setup_cmd( | ||
prefix, | ||
( | ||
'dotnet', 'pack', | ||
'--configuration', 'Release', | ||
'--output', build_dir, | ||
), | ||
) | ||
|
||
# Determine tool from the packaged file <tool_name>.<version>.nupkg | ||
build_outputs = os.listdir(os.path.join(prefix.prefix_dir, build_dir)) | ||
if len(build_outputs) != 1: | ||
raise NotImplementedError( | ||
f"Can't handle multiple build outputs. Got {build_outputs}", | ||
) | ||
tool_name = build_outputs[0].split('.')[0] | ||
|
||
# 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_name, | ||
), | ||
) | ||
|
||
# Cleanup build output | ||
for d in ('bin', 'obj', build_dir): | ||
rmtree(prefix.path(d)) | ||
|
||
|
||
def run_hook( | ||
hook: Hook, | ||
file_args: Sequence[str], | ||
color: bool, | ||
) -> Tuple[int, bytes]: | ||
with in_env(hook.prefix): | ||
return helpers.run_xargs(hook, hook.cmd, file_args, color=color) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
bin/ | ||
obj/ | ||
nupkg/ |
5 changes: 5 additions & 0 deletions
5
testing/resources/dotnet_hooks_csproj_repo/.pre-commit-hooks.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- id: dotnet example hook | ||
name: dotnet example hook | ||
entry: testeroni | ||
language: dotnet | ||
files: '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace dotnet_hooks_repo | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Hello from dotnet!"); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
testing/resources/dotnet_hooks_csproj_repo/dotnet_hooks_csproj_repo.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<PackAsTool>true</PackAsTool> | ||
<ToolCommandName>testeroni</ToolCommandName> | ||
<PackageOutputPath>./nupkg</PackageOutputPath> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
bin/ | ||
obj/ | ||
nupkg/ |
5 changes: 5 additions & 0 deletions
5
testing/resources/dotnet_hooks_sln_repo/.pre-commit-hooks.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- id: dotnet example hook | ||
name: dotnet example hook | ||
entry: testeroni | ||
language: dotnet | ||
files: '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace dotnet_hooks_sln_repo | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Hello from dotnet!"); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
testing/resources/dotnet_hooks_sln_repo/dotnet_hooks_sln_repo.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<PackAsTool>true</PackAsTool> | ||
<ToolCommandName>testeroni</ToolCommandName> | ||
<PackageOutputPath>./nupkg</PackageOutputPath> | ||
</PropertyGroup> | ||
</Project> |
34 changes: 34 additions & 0 deletions
34
testing/resources/dotnet_hooks_sln_repo/dotnet_hooks_sln_repo.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26124.0 | ||
MinimumVisualStudioVersion = 15.0.26124.0 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnet_hooks_sln_repo", "dotnet_hooks_sln_repo.csproj", "{6568CFDB-6F6F-45A9-932C-8C7DAABC8E56}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{6568CFDB-6F6F-45A9-932C-8C7DAABC8E56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{6568CFDB-6F6F-45A9-932C-8C7DAABC8E56}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{6568CFDB-6F6F-45A9-932C-8C7DAABC8E56}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{6568CFDB-6F6F-45A9-932C-8C7DAABC8E56}.Debug|x64.Build.0 = Debug|Any CPU | ||
{6568CFDB-6F6F-45A9-932C-8C7DAABC8E56}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{6568CFDB-6F6F-45A9-932C-8C7DAABC8E56}.Debug|x86.Build.0 = Debug|Any CPU | ||
{6568CFDB-6F6F-45A9-932C-8C7DAABC8E56}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{6568CFDB-6F6F-45A9-932C-8C7DAABC8E56}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{6568CFDB-6F6F-45A9-932C-8C7DAABC8E56}.Release|x64.ActiveCfg = Release|Any CPU | ||
{6568CFDB-6F6F-45A9-932C-8C7DAABC8E56}.Release|x64.Build.0 = Release|Any CPU | ||
{6568CFDB-6F6F-45A9-932C-8C7DAABC8E56}.Release|x86.ActiveCfg = Release|Any CPU | ||
{6568CFDB-6F6F-45A9-932C-8C7DAABC8E56}.Release|x86.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters