Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 60a42e9

Browse files
taoufik07asottile
authored andcommitted
Remove GOPATH special build
1 parent c787efd commit 60a42e9

3 files changed

Lines changed: 10 additions & 64 deletions

File tree

pre_commit/git.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ def get_git_common_dir(git_root: str = '.') -> str:
9393
return get_git_dir(git_root)
9494

9595

96-
def get_remote_url(git_root: str) -> str:
97-
_, out, _ = cmd_output('git', 'config', 'remote.origin.url', cwd=git_root)
98-
return out.strip()
99-
100-
10196
def is_in_merge_conflict() -> bool:
10297
git_dir = get_git_dir('.')
10398
return (

pre_commit/languages/golang.py

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
from typing import Sequence
88

99
import pre_commit.constants as C
10-
from pre_commit import git
1110
from pre_commit.envcontext import envcontext
1211
from pre_commit.envcontext import PatchesT
1312
from pre_commit.envcontext import Var
1413
from pre_commit.hook import Hook
1514
from pre_commit.languages import helpers
1615
from pre_commit.prefix import Prefix
1716
from pre_commit.util import cmd_output
18-
from pre_commit.util import cmd_output_b
1917
from pre_commit.util import rmtree
2018

2119
ENVIRONMENT_DIR = 'golangenv'
@@ -36,53 +34,28 @@ def in_env(prefix: Prefix) -> Generator[None, None, None]:
3634
yield
3735

3836

39-
def guess_go_dir(remote_url: str) -> str:
40-
if remote_url.endswith('.git'):
41-
remote_url = remote_url[:-1 * len('.git')]
42-
looks_like_url = (
43-
not remote_url.startswith('file://') and
44-
('//' in remote_url or '@' in remote_url)
45-
)
46-
remote_url = remote_url.replace(':', '/')
47-
if looks_like_url:
48-
_, _, remote_url = remote_url.rpartition('//')
49-
_, _, remote_url = remote_url.rpartition('@')
50-
return remote_url
51-
else:
52-
return 'unknown_src_dir'
53-
54-
5537
def install_environment(
5638
prefix: Prefix,
5739
version: str,
5840
additional_dependencies: Sequence[str],
5941
) -> None:
6042
helpers.assert_version_default('golang', version)
61-
directory = helpers.environment_dir(prefix, ENVIRONMENT_DIR, C.DEFAULT)
62-
63-
remote = git.get_remote_url(prefix.prefix_dir)
64-
repo_src_dir = os.path.join(directory, 'src', guess_go_dir(remote))
65-
66-
# Clone into the goenv we'll create
67-
cmd = ('git', 'clone', '--recursive', '.', repo_src_dir)
68-
helpers.run_setup_cmd(prefix, cmd)
43+
env_dir = helpers.environment_dir(prefix, ENVIRONMENT_DIR, version)
6944

7045
if sys.platform == 'cygwin': # pragma: no cover
71-
_, gopath, _ = cmd_output('cygpath', '-w', directory)
72-
gopath = gopath.strip()
46+
gopath = cmd_output('cygpath', '-w', env_dir)[1].strip()
7347
else:
74-
gopath = directory
48+
gopath = env_dir
7549
env = dict(os.environ, GOPATH=gopath)
7650
env.pop('GOBIN', None)
77-
cmd_output_b('go', 'install', './...', cwd=repo_src_dir, env=env)
51+
52+
helpers.run_setup_cmd(prefix, ('go', 'install', './...'), env=env)
7853
for dependency in additional_dependencies:
79-
cmd_output_b(
80-
'go', 'install', dependency, cwd=repo_src_dir, env=env,
81-
)
82-
# Same some disk space, we don't need these after installation
83-
rmtree(prefix.path(directory, 'src'))
84-
pkgdir = prefix.path(directory, 'pkg')
85-
if os.path.exists(pkgdir): # pragma: no cover (go<1.10)
54+
helpers.run_setup_cmd(prefix, ('go', 'install', dependency), env=env)
55+
56+
# save some disk space -- we don't need this after installation
57+
pkgdir = os.path.join(env_dir, 'pkg')
58+
if os.path.exists(pkgdir): # pragma: no branch (always true on windows?)
8659
rmtree(pkgdir)
8760

8861

tests/languages/golang_test.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)