diff options
author | Shubham Saini <shubham6405@gmail.com> | 2018-12-11 10:01:23 +0000 |
---|---|---|
committer | Shubham Saini <shubham6405@gmail.com> | 2018-12-11 10:01:23 +0000 |
commit | 68df54d6629ec019142eb149dd037774f2d11e7c (patch) | |
tree | 345bc22d46b4e01a4ba8303b94278952a4ed2b9e /venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/vcs/mercurial.py |
First commit
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/vcs/mercurial.py')
-rw-r--r-- | venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/vcs/mercurial.py | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/vcs/mercurial.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/vcs/mercurial.py new file mode 100644 index 0000000..3936473 --- /dev/null +++ b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/vcs/mercurial.py | |||
@@ -0,0 +1,105 @@ | |||
1 | from __future__ import absolute_import | ||
2 | |||
3 | import logging | ||
4 | import os | ||
5 | |||
6 | from pip._vendor.six.moves import configparser | ||
7 | |||
8 | from pip._internal.download import path_to_url | ||
9 | from pip._internal.utils.misc import display_path | ||
10 | from pip._internal.utils.temp_dir import TempDirectory | ||
11 | from pip._internal.vcs import VersionControl, vcs | ||
12 | |||
13 | logger = logging.getLogger(__name__) | ||
14 | |||
15 | |||
16 | class Mercurial(VersionControl): | ||
17 | name = 'hg' | ||
18 | dirname = '.hg' | ||
19 | repo_name = 'clone' | ||
20 | schemes = ('hg', 'hg+http', 'hg+https', 'hg+ssh', 'hg+static-http') | ||
21 | |||
22 | def get_base_rev_args(self, rev): | ||
23 | return [rev] | ||
24 | |||
25 | def export(self, location): | ||
26 | """Export the Hg repository at the url to the destination location""" | ||
27 | with TempDirectory(kind="export") as temp_dir: | ||
28 | self.unpack(temp_dir.path) | ||
29 | |||
30 | self.run_command( | ||
31 | ['archive', location], show_stdout=False, cwd=temp_dir.path | ||
32 | ) | ||
33 | |||
34 | def switch(self, dest, url, rev_options): | ||
35 | repo_config = os.path.join(dest, self.dirname, 'hgrc') | ||
36 | config = configparser.SafeConfigParser() | ||
37 | try: | ||
38 | config.read(repo_config) | ||
39 | config.set('paths', 'default', url) | ||
40 | with open(repo_config, 'w') as config_file: | ||
41 | config.write(config_file) | ||
42 | except (OSError, configparser.NoSectionError) as exc: | ||
43 | logger.warning( | ||
44 | 'Could not switch Mercurial repository to %s: %s', url, exc, | ||
45 | ) | ||
46 | else: | ||
47 | cmd_args = ['update', '-q'] + rev_options.to_args() | ||
48 | self.run_command(cmd_args, cwd=dest) | ||
49 | |||
50 | def update(self, dest, rev_options): | ||
51 | self.run_command(['pull', '-q'], cwd=dest) | ||
52 | cmd_args = ['update', '-q'] + rev_options.to_args() | ||
53 | self.run_command(cmd_args, cwd=dest) | ||
54 | |||
55 | def obtain(self, dest): | ||
56 | url, rev = self.get_url_rev() | ||
57 | rev_options = self.make_rev_options(rev) | ||
58 | if self.check_destination(dest, url, rev_options): | ||
59 | rev_display = rev_options.to_display() | ||
60 | logger.info( | ||
61 | 'Cloning hg %s%s to %s', | ||
62 | url, | ||
63 | rev_display, | ||
64 | display_path(dest), | ||
65 | ) | ||
66 | self.run_command(['clone', '--noupdate', '-q', url, dest]) | ||
67 | cmd_args = ['update', '-q'] + rev_options.to_args() | ||
68 | self.run_command(cmd_args, cwd=dest) | ||
69 | |||
70 | def get_url(self, location): | ||
71 | url = self.run_command( | ||
72 | ['showconfig', 'paths.default'], | ||
73 | show_stdout=False, cwd=location).strip() | ||
74 | if self._is_local_repository(url): | ||
75 | url = path_to_url(url) | ||
76 | return url.strip() | ||
77 | |||
78 | def get_revision(self, location): | ||
79 | current_revision = self.run_command( | ||
80 | ['parents', '--template={rev}'], | ||
81 | show_stdout=False, cwd=location).strip() | ||
82 | return current_revision | ||
83 | |||
84 | def get_revision_hash(self, location): | ||
85 | current_rev_hash = self.run_command( | ||
86 | ['parents', '--template={node}'], | ||
87 | show_stdout=False, cwd=location).strip() | ||
88 | return current_rev_hash | ||
89 | |||
90 | def get_src_requirement(self, dist, location): | ||
91 | repo = self.get_url(location) | ||
92 | if not repo.lower().startswith('hg:'): | ||
93 | repo = 'hg+' + repo | ||
94 | egg_project_name = dist.egg_name().split('-', 1)[0] | ||
95 | if not repo: | ||
96 | return None | ||
97 | current_rev_hash = self.get_revision_hash(location) | ||
98 | return '%s@%s#egg=%s' % (repo, current_rev_hash, egg_project_name) | ||
99 | |||
100 | def is_commit_id_equal(self, dest, name): | ||
101 | """Always assume the versions don't match""" | ||
102 | return False | ||
103 | |||
104 | |||
105 | vcs.register(Mercurial) | ||