@@ -40,6 +40,8 @@ | |||
| 40 | 40 | # just to satisfy flake8 on py3 | |
| 41 | 41 | unicode, | |
| 42 | 42 | safe_decode, | |
| 43 | + is_posix, | ||
| 44 | + is_win, | ||
| 43 | 45 | ) | |
| 44 | 46 | ||
| 45 | 47 | execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output', | |
@@ -50,9 +52,9 @@ | |||
| 50 | 52 | log = logging.getLogger('git.cmd') | |
| 51 | 53 | log.addHandler(logging.NullHandler()) | |
| 52 | 54 | ||
| 53 | - __all__ = ('Git', ) | ||
| 55 | + __all__ = ('Git',) | ||
| 54 | 56 | ||
| 55 | - if sys.platform != 'win32': | ||
| 57 | + if is_win(): | ||
| 56 | 58 | WindowsError = OSError | |
| 57 | 59 | ||
| 58 | 60 | if PY3: | |
@@ -236,7 +238,7 @@ def dict_to_slots_and__excluded_are_none(self, d, excluded=()): | |||
| 236 | 238 | ## CREATE_NEW_PROCESS_GROUP is needed to allow killing it afterwards, | |
| 237 | 239 | # seehttps://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal | |
| 238 | 240 | PROC_CREATIONFLAGS = (CREATE_NO_WINDOW | subprocess.CREATE_NEW_PROCESS_GROUP | |
| 239 | - if sys.platform == 'win32' | ||
| 241 | + if is_win() | ||
| 240 | 242 | else 0) | |
| 241 | 243 | ||
| 242 | 244 | ||
@@ -628,7 +630,7 @@ def execute(self, command, | |||
| 628 | 630 | env["LC_ALL"] = "C" | |
| 629 | 631 | env.update(self._environment) | |
| 630 | 632 | ||
| 631 | - if sys.platform == 'win32': | ||
| 633 | + if is_win(): | ||
| 632 | 634 | cmd_not_found_exception = WindowsError | |
| 633 | 635 | if kill_after_timeout: | |
| 634 | 636 | raise GitCommandError('"kill_after_timeout" feature is not supported on Windows.') | |
@@ -648,7 +650,7 @@ def execute(self, command, | |||
| 648 | 650 | stderr=PIPE, | |
| 649 | 651 | stdout=PIPE if with_stdout else open(os.devnull, 'wb'), | |
| 650 | 652 | shell=self.USE_SHELL, | |
| 651 | - close_fds=(os.name == 'posix'), # unsupported on windows | ||
| 653 | + close_fds=(is_posix()), # unsupported on windows | ||
| 652 | 654 | universal_newlines=universal_newlines, | |
| 653 | 655 | creationflags=PROC_CREATIONFLAGS, | |
| 654 | 656 | **subprocess_kwargs | |
@@ -688,7 +690,7 @@ def _kill_process(pid): | |||
| 688 | 690 | ||
| 689 | 691 | if kill_after_timeout: | |
| 690 | 692 | kill_check = threading.Event() | |
| 691 | - watchdog = threading.Timer(kill_after_timeout, _kill_process, args=(proc.pid, )) | ||
| 693 | + watchdog = threading.Timer(kill_after_timeout, _kill_process, args=(proc.pid,)) | ||
| 692 | 694 | ||
| 693 | 695 | # Wait for the process to return | |
| 694 | 696 | status = 0 | |
@@ -932,7 +934,7 @@ def make_call(): | |||
| 932 | 934 | return call | |
| 933 | 935 | # END utility to recreate call after changes | |
| 934 | 936 | ||
| 935 | - if sys.platform == 'win32': | ||
| 937 | + if is_win(): | ||
| 936 | 938 | try: | |
| 937 | 939 | try: | |
| 938 | 940 | return self.execute(make_call(), **_kwargs) | |
@@ -7,6 +7,7 @@ | |||
| 7 | 7 | """utilities to help provide compatibility with python 3""" | |
| 8 | 8 | # flake8: noqa | |
| 9 | 9 | ||
| 10 | + import os | ||
| 10 | 11 | import sys | |
| 11 | 12 | ||
| 12 | 13 | from gitdb.utils.compat import ( | |
@@ -79,3 +80,16 @@ def __new__(cls, name, nbases, d): | |||
| 79 | 80 | # end metaclass | |
| 80 | 81 | return metaclass(meta.__name__ + 'Helper', None, {}) | |
| 81 | 82 | # end handle py2 | |
| 83 | + | ||
| 84 | + | ||
| 85 | + def is_win(): | ||
| 86 | + return os.name == 'nt' | ||
| 87 | + | ||
| 88 | + | ||
| 89 | + def is_posix(): | ||
| 90 | + return os.name == 'posix' | ||
| 91 | + | ||
| 92 | + | ||
| 93 | + def is_darwin(): | ||
| 94 | + return os.name == 'darwin' | ||
| 95 | + | ||
@@ -46,7 +46,8 @@ | |||
| 46 | 46 | string_types, | |
| 47 | 47 | force_bytes, | |
| 48 | 48 | defenc, | |
| 49 | - mviter | ||
| 49 | + mviter, | ||
| 50 | + is_win | ||
| 50 | 51 | ) | |
| 51 | 52 | ||
| 52 | 53 | from git.util import ( | |
@@ -136,7 +137,7 @@ def _set_cache_(self, attr): | |||
| 136 | 137 | # which happens during read-tree. | |
| 137 | 138 | # In this case, we will just read the memory in directly. | |
| 138 | 139 | # Its insanely bad ... I am disappointed ! | |
| 139 | - allow_mmap = (os.name != 'nt' or sys.version_info[1] > 5) | ||
| 140 | + allow_mmap = (is_win() or sys.version_info[1] > 5) | ||
| 140 | 141 | stream = file_contents_ro(fd, stream=True, allow_mmap=allow_mmap) | |
| 141 | 142 | ||
| 142 | 143 | try: | |
@@ -1059,7 +1060,7 @@ def handle_stderr(proc, iter_checked_out_files): | |||
| 1059 | 1060 | # END for each possible ending | |
| 1060 | 1061 | # END for each line | |
| 1061 | 1062 | if unknown_lines: | |
| 1062 | - raise GitCommandError(("git-checkout-index", ), 128, stderr) | ||
| 1063 | + raise GitCommandError(("git-checkout-index",), 128, stderr) | ||
| 1063 | 1064 | if failed_files: | |
| 1064 | 1065 | valid_files = list(set(iter_checked_out_files) - set(failed_files)) | |
| 1065 | 1066 | raise CheckoutError( | |
@@ -43,7 +43,8 @@ | |||
| 43 | 43 | from git.compat import ( | |
| 44 | 44 | defenc, | |
| 45 | 45 | force_text, | |
| 46 | - force_bytes | ||
| 46 | + force_bytes, | ||
| 47 | + is_posix, | ||
| 47 | 48 | ) | |
| 48 | 49 | ||
| 49 | 50 | S_IFGITLINK = S_IFLNK | S_IFDIR # a submodule | |
@@ -75,7 +76,7 @@ def run_commit_hook(name, index): | |||
| 75 | 76 | stdout=subprocess.PIPE, | |
| 76 | 77 | stderr=subprocess.PIPE, | |
| 77 | 78 | cwd=index.repo.working_dir, | |
| 78 | - close_fds=(os.name == 'posix'), | ||
| 79 | + close_fds=(is_posix()), | ||
| 79 | 80 | universal_newlines=True, | |
| 80 | 81 | creationflags=PROC_CREATIONFLAGS,) | |
| 81 | 82 | stdout, stderr = cmd.communicate() | |
@@ -2,6 +2,7 @@ | |||
| 2 | 2 | import struct | |
| 3 | 3 | import tempfile | |
| 4 | 4 | import os | |
| 5 | + from git.compat import is_win | ||
| 5 | 6 | ||
| 6 | 7 | __all__ = ('TemporaryFileSwap', 'post_clear_cache', 'default_index', 'git_working_dir') | |
| 7 | 8 | ||
@@ -29,7 +30,7 @@ def __init__(self, file_path): | |||
| 29 | 30 | ||
| 30 | 31 | def __del__(self): | |
| 31 | 32 | if os.path.isfile(self.tmp_file_path): | |
| 32 | - if os.name == 'nt' and os.path.exists(self.file_path): | ||
| 33 | + if is_win and os.path.exists(self.file_path): | ||
| 33 | 34 | os.remove(self.file_path) | |
| 34 | 35 | os.rename(self.tmp_file_path, self.file_path) | |
| 35 | 36 | # END temp file exists | |
@@ -6,7 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | 7 | # Module implementing a remote object allowing easy access to git remotes | |
| 8 | 8 | import re | |
| 9 | - import os | ||
| 10 | 9 | ||
| 11 | 10 | from .config import ( | |
| 12 | 11 | SectionConstraint, | |
@@ -32,7 +31,7 @@ | |||
| 32 | 31 | ) | |
| 33 | 32 | from git.cmd import handle_process_output | |
| 34 | 33 | from gitdb.util import join | |
| 35 | - from git.compat import (defenc, force_text) | ||
| 34 | + from git.compat import (defenc, force_text, is_win) | ||
| 36 | 35 | import logging | |
| 37 | 36 | ||
| 38 | 37 | log = logging.getLogger('git.remote') | |
@@ -113,7 +112,7 @@ def __init__(self, flags, local_ref, remote_ref_string, remote, old_commit=None, | |||
| 113 | 112 | self._remote = remote | |
| 114 | 113 | self._old_commit_sha = old_commit | |
| 115 | 114 | self.summary = summary | |
| 116 | - | ||
| 115 | + | ||
| 117 | 116 | @property | |
| 118 | 117 | def old_commit(self): | |
| 119 | 118 | return self._old_commit_sha and self._remote.repo.commit(self._old_commit_sha) or None | |
@@ -377,7 +376,7 @@ def __init__(self, repo, name): | |||
| 377 | 376 | self.repo = repo | |
| 378 | 377 | self.name = name | |
| 379 | 378 | ||
| 380 | - if os.name == 'nt': | ||
| 379 | + if is_win(): | ||
| 381 | 380 | # some oddity: on windows, python 2.5, it for some reason does not realize | |
| 382 | 381 | # that it has the config_writer property, but instead calls __getattr__ | |
| 383 | 382 | # which will not yield the expected results. 'pinging' the members | |
@@ -635,7 +634,7 @@ def _get_fetch_info_from_stderr(self, proc, progress): | |||
| 635 | 634 | # end | |
| 636 | 635 | if progress.error_lines(): | |
| 637 | 636 | stderr_text = '\n'.join(progress.error_lines()) | |
| 638 | - | ||
| 637 | + | ||
| 639 | 638 | finalize_process(proc, stderr=stderr_text) | |
| 640 | 639 | ||
| 641 | 640 | # read head information | |
@@ -657,7 +656,7 @@ def _get_fetch_info_from_stderr(self, proc, progress): | |||
| 657 | 656 | fetch_info_lines = fetch_info_lines[:l_fhi] | |
| 658 | 657 | # end truncate correct list | |
| 659 | 658 | # end sanity check + sanitization | |
| 660 | - | ||
| 659 | + | ||
| 661 | 660 | output.extend(FetchInfo._from_line(self.repo, err_line, fetch_line) | |
| 662 | 661 | for err_line, fetch_line in zip(fetch_info_lines, fetch_head_info)) | |
| 663 | 662 | return output | |
@@ -769,17 +768,17 @@ def push(self, refspec=None, progress=None, **kwargs): | |||
| 769 | 768 | :param refspec: see 'fetch' method | |
| 770 | 769 | :param progress: | |
| 771 | 770 | Can take one of many value types: | |
| 772 | - | ||
| 771 | + | ||
| 773 | 772 | * None to discard progress information | |
| 774 | 773 | * A function (callable) that is called with the progress infomation. | |
| 775 | - | ||
| 774 | + | ||
| 776 | 775 | Signature: ``progress(op_code, cur_count, max_count=None, message='')``. | |
| 777 | - | ||
| 776 | + | ||
| 778 | 777 | `Click here <http://goo.gl/NPa7st>`_ for a description of all arguments | |
| 779 | 778 | given to the function. | |
| 780 | 779 | * An instance of a class derived from ``git.RemoteProgress`` that | |
| 781 | 780 | overrides the ``update()`` function. | |
| 782 | - | ||
| 781 | + | ||
| 783 | 782 | :note: No further progress information is returned after push returns. | |
| 784 | 783 | :param kwargs: Additional arguments to be passed to git-push | |
| 785 | 784 | :return: | |
@@ -56,6 +56,7 @@ | |||
| 56 | 56 | PY3, | |
| 57 | 57 | safe_decode, | |
| 58 | 58 | range, | |
| 59 | + is_win, | ||
| 59 | 60 | ) | |
| 60 | 61 | ||
| 61 | 62 | import os | |
@@ -71,7 +72,7 @@ | |||
| 71 | 72 | BlameEntry = namedtuple('BlameEntry', ['commit', 'linenos', 'orig_path', 'orig_linenos']) | |
| 72 | 73 | ||
| 73 | 74 | ||
| 74 | - __all__ = ('Repo', ) | ||
| 75 | + __all__ = ('Repo',) | ||
| 75 | 76 | ||
| 76 | 77 | ||
| 77 | 78 | def _expand_path(p): | |
@@ -369,7 +370,7 @@ def delete_remote(self, remote): | |||
| 369 | 370 | def _get_config_path(self, config_level): | |
| 370 | 371 | # we do not support an absolute path of the gitconfig on windows , | |
| 371 | 372 | # use the global config instead | |
| 372 | - if sys.platform == "win32" and config_level == "system": | ||
| 373 | + if is_win() and config_level == "system": | ||
| 373 | 374 | config_level = "global" | |
| 374 | 375 | ||
| 375 | 376 | if config_level == "system": | |
@@ -883,7 +884,7 @@ def _clone(cls, git, url, path, odb_default_type, progress, **kwargs): | |||
| 883 | 884 | prev_cwd = None | |
| 884 | 885 | prev_path = None | |
| 885 | 886 | odbt = kwargs.pop('odbt', odb_default_type) | |
| 886 | - if os.name == 'nt': | ||
| 887 | + if is_win(): | ||
| 887 | 888 | if '~' in path: | |
| 888 | 889 | raise OSError("Git cannot handle the ~ character in path %r correctly" % path) | |
| 889 | 890 | ||
@@ -13,7 +13,7 @@ | |||
| 13 | 13 | import logging | |
| 14 | 14 | ||
| 15 | 15 | from git import Repo, Remote, GitCommandError, Git | |
| 16 | - from git.compat import string_types | ||
| 16 | + from git.compat import string_types, is_win | ||
| 17 | 17 | ||
| 18 | 18 | osp = os.path.dirname | |
| 19 | 19 | ||
@@ -73,7 +73,7 @@ def _mktemp(*args): | |||
| 73 | 73 | prefixing /private/ will lead to incorrect paths on OSX.""" | |
| 74 | 74 | tdir = tempfile.mktemp(*args) | |
| 75 | 75 | # See :note: above to learn why this is comented out. | |
| 76 | - # if sys.platform == 'darwin': | ||
| 76 | + # if is_darwin(): | ||
| 77 | 77 | # tdir = '/private' + tdir | |
| 78 | 78 | return tdir | |
| 79 | 79 | ||
@@ -83,7 +83,7 @@ def _rmtree_onerror(osremove, fullpath, exec_info): | |||
| 83 | 83 | Handle the case on windows that read-only files cannot be deleted by | |
| 84 | 84 | os.remove by setting it to mode 777, then retry deletion. | |
| 85 | 85 | """ | |
| 86 | - if os.name != 'nt' or osremove is not os.remove: | ||
| 86 | + if is_win() or osremove is not os.remove: | ||
| 87 | 87 | raise | |
| 88 | 88 | ||
| 89 | 89 | os.chmod(fullpath, 0o777) | |
@@ -221,7 +221,7 @@ def remote_repo_creator(self): | |||
| 221 | 221 | if gd is not None: | |
| 222 | 222 | gd.proc.terminate() | |
| 223 | 223 | log.warning('git-ls-remote failed due to: %s(%s)', type(e), e) | |
| 224 | - if os.name == 'nt': | ||
| 224 | + if is_win(): | ||
| 225 | 225 | msg = "git-daemon needs to run this test, but windows does not have one. " | |
| 226 | 226 | msg += 'Otherwise, run: git-daemon "%s"' % temp_dir | |
| 227 | 227 | raise AssertionError(msg) | |
@@ -24,6 +24,7 @@ | |||
| 24 | 24 | ) | |
| 25 | 25 | from git.objects.util import get_object_type_by_name | |
| 26 | 26 | from gitdb.util import hex_to_bin | |
| 27 | + from git.compat import is_win | ||
| 27 | 28 | ||
| 28 | 29 | ||
| 29 | 30 | class TestBase(TestBase): | |
@@ -117,7 +118,7 @@ def test_with_rw_remote_and_rw_repo(self, rw_repo, rw_remote_repo): | |||
| 117 | 118 | assert rw_remote_repo.config_reader("repository").getboolean("core", "bare") | |
| 118 | 119 | assert os.path.isdir(os.path.join(rw_repo.working_tree_dir, 'lib')) | |
| 119 | 120 | ||
| 120 | - @skipIf(sys.version_info < (3, ) and os.name == 'nt', | ||
| 121 | + @skipIf(sys.version_info < (3,) and is_win(), | ||
| 121 | 122 | "Unicode woes, see https://github.com/gitpython-developers/GitPython/pull/519") | |
| 122 | 123 | @with_rw_repo('0.1.6') | |
| 123 | 124 | def test_add_unicode(self, rw_repo): | |
@@ -134,7 +135,7 @@ def test_add_unicode(self, rw_repo): | |||
| 134 | 135 | ||
| 135 | 136 | open(file_path, "wb").write(b'something') | |
| 136 | 137 | ||
| 137 | - if os.name == 'nt': | ||
| 138 | + if is_win(): | ||
| 138 | 139 | # on windows, there is no way this works, see images on | |
| 139 | 140 | # https://github.com/gitpython-developers/GitPython/issues/147#issuecomment-68881897 | |
| 140 | 141 | # Therefore, it must be added using the python implementation | |
@@ -26,7 +26,7 @@ | |||
| 26 | 26 | ) | |
| 27 | 27 | from gitdb.test.lib import with_rw_directory | |
| 28 | 28 | ||
| 29 | - from git.compat import PY3 | ||
| 29 | + from git.compat import PY3, is_darwin | ||
| 30 | 30 | ||
| 31 | 31 | try: | |
| 32 | 32 | from unittest import mock | |
@@ -214,7 +214,7 @@ def test_environment(self, rw_dir): | |||
| 214 | 214 | try: | |
| 215 | 215 | remote.fetch() | |
| 216 | 216 | except GitCommandError as err: | |
| 217 | - if sys.version_info[0] < 3 and sys.platform == 'darwin': | ||
| 217 | + if sys.version_info[0] < 3 and is_darwin(): | ||
| 218 | 218 | assert 'ssh-origin' in str(err) | |
| 219 | 219 | assert err.status == 128 | |
| 220 | 220 | else: | |
0 commit comments