1
+ import java.nio.file.Paths
2
+
1
3
subprojects {
2
4
repositories {
3
5
google()
@@ -9,7 +11,7 @@ subprojects {
9
11
val installVenv = tasks.register(" installVenv" , Exec ::class .java) {
10
12
description = " Install a new virtualenv in ./venv"
11
13
12
- outputs.dir(" ./ venv" )
14
+ outputs.dir(Paths .get( " . " , " venv" ) )
13
15
14
16
commandLine(" virtualenv" , " venv" )
15
17
}
@@ -19,28 +21,28 @@ val installPreCommit = tasks.register("installPreCommit", Exec::class.java) {
19
21
20
22
dependsOn(installVenv)
21
23
22
- outputs.file(" ./ venv/ bin/ pre-commit" )
24
+ outputs.file(Paths .get( " . " , " venv" , " bin" , " pre-commit" ) )
23
25
24
- commandLine(" ./ venv/bin/ pip" , " install" , " pre-commit" )
26
+ commandLine(Paths .get( " . " , " venv" , binFolder, " pip" ) , " install" , " pre-commit" )
25
27
}
26
28
27
29
val installHooks = tasks.register(" installHooks" , Exec ::class .java) {
28
30
description = " Run pre-commit hooks without installing them"
29
31
30
32
dependsOn(installPreCommit)
31
33
32
- outputs.file(" .git/hooks/ pre-commit" )
34
+ outputs.file(Paths .get( " . " , " venv " , binFolder, " pre-commit" ) )
33
35
inputs.file(" .pre-commit-config.yaml" )
34
36
35
- commandLine(" ./ venv/bin/ pre-commit" , " install" , " --install-hooks" )
37
+ commandLine(Paths .get( " . " , " venv" , binFolder, " pre-commit" ) , " install" , " --install-hooks" )
36
38
}
37
39
38
40
val runHooks = tasks.register(" runHooks" , Exec ::class .java) {
39
41
description = " Run pre-commit hooks"
40
42
41
43
dependsOn(installPreCommit)
42
44
43
- commandLine(" ./ venv/bin/ pre-commit" , " run" , " --all-files" )
45
+ commandLine(Paths .get( " . " , " venv" , binFolder, " pre-commit" ) , " run" , " --all-files" )
44
46
}
45
47
46
48
val preMerge = tasks.register(" preMerge" ) {
@@ -69,3 +71,13 @@ subprojects {
69
71
}
70
72
}
71
73
}
74
+
75
+ /* *
76
+ * Python `venv/bin` folder is different based on OS.
77
+ * On Windows it's inside the `venv/Scripts` folder.
78
+ */
79
+ val binFolder : String get() = if (System .getProperty(" os.name" ).toLowerCase().contains(" windows" )) {
80
+ " Scripts"
81
+ } else {
82
+ " bin"
83
+ }
0 commit comments