summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostis Anagnostopoulos <ankostis@gmail.com>2016-09-26 20:41:41 +0200
committerKostis Anagnostopoulos <ankostis@gmail.com>2016-09-27 12:37:16 +0200
commitf495e94028bfddc264727ffc464cd694ddd05ab8 (patch)
tree8c0bf309b08576f96c9344d9937344e1447d2237
parent29eb301700c41f0af7d57d923ad069cbdf636381 (diff)
downloadgitpython-f495e94028bfddc264727ffc464cd694ddd05ab8.tar.gz
src, #519: collect all is_<platform>() calls
-rw-r--r--git/cmd.py16
-rw-r--r--git/compat.py14
-rw-r--r--git/index/base.py7
-rw-r--r--git/index/fun.py5
-rw-r--r--git/index/util.py3
-rw-r--r--git/remote.py19
-rw-r--r--git/repo/base.py7
-rw-r--r--git/test/lib/helper.py8
-rw-r--r--git/test/test_base.py5
-rw-r--r--git/test/test_git.py4
-rw-r--r--git/test/test_index.py8
-rw-r--r--git/test/test_submodule.py4
-rw-r--r--git/test/test_util.py5
-rw-r--r--git/util.py8
14 files changed, 66 insertions, 47 deletions
diff --git a/git/cmd.py b/git/cmd.py
index f6cb0ce9..7b032d58 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -40,6 +40,8 @@ from git.compat import (
# just to satisfy flake8 on py3
unicode,
safe_decode,
+ is_posix,
+ is_win,
)
execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output',
@@ -50,9 +52,9 @@ execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output',
log = logging.getLogger('git.cmd')
log.addHandler(logging.NullHandler())
-__all__ = ('Git', )
+__all__ = ('Git',)
-if sys.platform != 'win32':
+if is_win():
WindowsError = OSError
if PY3:
@@ -236,7 +238,7 @@ CREATE_NO_WINDOW = 0x08000000
## CREATE_NEW_PROCESS_GROUP is needed to allow killing it afterwards,
# seehttps://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal
PROC_CREATIONFLAGS = (CREATE_NO_WINDOW | subprocess.CREATE_NEW_PROCESS_GROUP
- if sys.platform == 'win32'
+ if is_win()
else 0)
@@ -628,7 +630,7 @@ class Git(LazyMixin):
env["LC_ALL"] = "C"
env.update(self._environment)
- if sys.platform == 'win32':
+ if is_win():
cmd_not_found_exception = WindowsError
if kill_after_timeout:
raise GitCommandError('"kill_after_timeout" feature is not supported on Windows.')
@@ -648,7 +650,7 @@ class Git(LazyMixin):
stderr=PIPE,
stdout=PIPE if with_stdout else open(os.devnull, 'wb'),
shell=self.USE_SHELL,
- close_fds=(os.name == 'posix'), # unsupported on windows
+ close_fds=(is_posix()), # unsupported on windows
universal_newlines=universal_newlines,
creationflags=PROC_CREATIONFLAGS,
**subprocess_kwargs
@@ -688,7 +690,7 @@ class Git(LazyMixin):
if kill_after_timeout:
kill_check = threading.Event()
- watchdog = threading.Timer(kill_after_timeout, _kill_process, args=(proc.pid, ))
+ watchdog = threading.Timer(kill_after_timeout, _kill_process, args=(proc.pid,))
# Wait for the process to return
status = 0
@@ -932,7 +934,7 @@ class Git(LazyMixin):
return call
# END utility to recreate call after changes
- if sys.platform == 'win32':
+ if is_win():
try:
try:
return self.execute(make_call(), **_kwargs)
diff --git a/git/compat.py b/git/compat.py
index b3572474..ff382ce8 100644
--- a/git/compat.py
+++ b/git/compat.py
@@ -7,6 +7,7 @@
"""utilities to help provide compatibility with python 3"""
# flake8: noqa
+import os
import sys
from gitdb.utils.compat import (
@@ -79,3 +80,16 @@ def with_metaclass(meta, *bases):
# end metaclass
return metaclass(meta.__name__ + 'Helper', None, {})
# end handle py2
+
+
+def is_win():
+ return os.name == 'nt'
+
+
+def is_posix():
+ return os.name == 'posix'
+
+
+def is_darwin():
+ return os.name == 'darwin'
+
diff --git a/git/index/base.py b/git/index/base.py
index 86eda41e..82df361f 100644
--- a/git/index/base.py
+++ b/git/index/base.py
@@ -46,7 +46,8 @@ from git.compat import (
string_types,
force_bytes,
defenc,
- mviter
+ mviter,
+ is_win
)
from git.util import (
@@ -136,7 +137,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# which happens during read-tree.
# In this case, we will just read the memory in directly.
# Its insanely bad ... I am disappointed !
- allow_mmap = (os.name != 'nt' or sys.version_info[1] > 5)
+ allow_mmap = (is_win() or sys.version_info[1] > 5)
stream = file_contents_ro(fd, stream=True, allow_mmap=allow_mmap)
try:
@@ -1059,7 +1060,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# END for each possible ending
# END for each line
if unknown_lines:
- raise GitCommandError(("git-checkout-index", ), 128, stderr)
+ raise GitCommandError(("git-checkout-index",), 128, stderr)
if failed_files:
valid_files = list(set(iter_checked_out_files) - set(failed_files))
raise CheckoutError(
diff --git a/git/index/fun.py b/git/index/fun.py
index 818847a2..98e2d3a0 100644
--- a/git/index/fun.py
+++ b/git/index/fun.py
@@ -43,7 +43,8 @@ from gitdb.typ import str_tree_type
from git.compat import (
defenc,
force_text,
- force_bytes
+ force_bytes,
+ is_posix,
)
S_IFGITLINK = S_IFLNK | S_IFDIR # a submodule
@@ -75,7 +76,7 @@ def run_commit_hook(name, index):
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=index.repo.working_dir,
- close_fds=(os.name == 'posix'),
+ close_fds=(is_posix()),
universal_newlines=True,
creationflags=PROC_CREATIONFLAGS,)
stdout, stderr = cmd.communicate()
diff --git a/git/index/util.py b/git/index/util.py
index 171bd8fc..0340500c 100644
--- a/git/index/util.py
+++ b/git/index/util.py
@@ -2,6 +2,7 @@
import struct
import tempfile
import os
+from git.compat import is_win
__all__ = ('TemporaryFileSwap', 'post_clear_cache', 'default_index', 'git_working_dir')
@@ -29,7 +30,7 @@ class TemporaryFileSwap(object):
def __del__(self):
if os.path.isfile(self.tmp_file_path):
- if os.name == 'nt' and os.path.exists(self.file_path):
+ if is_win and os.path.exists(self.file_path):
os.remove(self.file_path)
os.rename(self.tmp_file_path, self.file_path)
# END temp file exists
diff --git a/git/remote.py b/git/remote.py
index 4a8a5ee9..19deefb7 100644
--- a/git/remote.py
+++ b/git/remote.py
@@ -6,7 +6,6 @@
# Module implementing a remote object allowing easy access to git remotes
import re
-import os
from .config import (
SectionConstraint,
@@ -32,7 +31,7 @@ from git.util import (
)
from git.cmd import handle_process_output
from gitdb.util import join
-from git.compat import (defenc, force_text)
+from git.compat import (defenc, force_text, is_win)
import logging
log = logging.getLogger('git.remote')
@@ -113,7 +112,7 @@ class PushInfo(object):
self._remote = remote
self._old_commit_sha = old_commit
self.summary = summary
-
+
@property
def old_commit(self):
return self._old_commit_sha and self._remote.repo.commit(self._old_commit_sha) or None
@@ -377,7 +376,7 @@ class Remote(LazyMixin, Iterable):
self.repo = repo
self.name = name
- if os.name == 'nt':
+ if is_win():
# some oddity: on windows, python 2.5, it for some reason does not realize
# that it has the config_writer property, but instead calls __getattr__
# which will not yield the expected results. 'pinging' the members
@@ -635,7 +634,7 @@ class Remote(LazyMixin, Iterable):
# end
if progress.error_lines():
stderr_text = '\n'.join(progress.error_lines())
-
+
finalize_process(proc, stderr=stderr_text)
# read head information
@@ -657,7 +656,7 @@ class Remote(LazyMixin, Iterable):
fetch_info_lines = fetch_info_lines[:l_fhi]
# end truncate correct list
# end sanity check + sanitization
-
+
output.extend(FetchInfo._from_line(self.repo, err_line, fetch_line)
for err_line, fetch_line in zip(fetch_info_lines, fetch_head_info))
return output
@@ -769,17 +768,17 @@ class Remote(LazyMixin, Iterable):
:param refspec: see 'fetch' method
:param progress:
Can take one of many value types:
-
+
* None to discard progress information
* A function (callable) that is called with the progress infomation.
-
+
Signature: ``progress(op_code, cur_count, max_count=None, message='')``.
-
+
`Click here <http://goo.gl/NPa7st>`_ for a description of all arguments
given to the function.
* An instance of a class derived from ``git.RemoteProgress`` that
overrides the ``update()`` function.
-
+
:note: No further progress information is returned after push returns.
:param kwargs: Additional arguments to be passed to git-push
:return:
diff --git a/git/repo/base.py b/git/repo/base.py
index 0e46ee67..d0f131bd 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -56,6 +56,7 @@ from git.compat import (
PY3,
safe_decode,
range,
+ is_win,
)
import os
@@ -71,7 +72,7 @@ if sys.version_info[:2] < (2, 5): # python 2.4 compatiblity
BlameEntry = namedtuple('BlameEntry', ['commit', 'linenos', 'orig_path', 'orig_linenos'])
-__all__ = ('Repo', )
+__all__ = ('Repo',)
def _expand_path(p):
@@ -369,7 +370,7 @@ class Repo(object):
def _get_config_path(self, config_level):
# we do not support an absolute path of the gitconfig on windows ,
# use the global config instead
- if sys.platform == "win32" and config_level == "system":
+ if is_win() and config_level == "system":
config_level = "global"
if config_level == "system":
@@ -883,7 +884,7 @@ class Repo(object):
prev_cwd = None
prev_path = None
odbt = kwargs.pop('odbt', odb_default_type)
- if os.name == 'nt':
+ if is_win():
if '~' in path:
raise OSError("Git cannot handle the ~ character in path %r correctly" % path)
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index 75d4e6fb..7cc1dcae 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -13,7 +13,7 @@ import io
import logging
from git import Repo, Remote, GitCommandError, Git
-from git.compat import string_types
+from git.compat import string_types, is_win
osp = os.path.dirname
@@ -73,7 +73,7 @@ def _mktemp(*args):
prefixing /private/ will lead to incorrect paths on OSX."""
tdir = tempfile.mktemp(*args)
# See :note: above to learn why this is comented out.
- # if sys.platform == 'darwin':
+ # if is_darwin():
# tdir = '/private' + tdir
return tdir
@@ -83,7 +83,7 @@ def _rmtree_onerror(osremove, fullpath, exec_info):
Handle the case on windows that read-only files cannot be deleted by
os.remove by setting it to mode 777, then retry deletion.
"""
- if os.name != 'nt' or osremove is not os.remove:
+ if is_win() or osremove is not os.remove:
raise
os.chmod(fullpath, 0o777)
@@ -221,7 +221,7 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
if gd is not None:
gd.proc.terminate()
log.warning('git-ls-remote failed due to: %s(%s)', type(e), e)
- if os.name == 'nt':
+ if is_win():
msg = "git-daemon needs to run this test, but windows does not have one. "
msg += 'Otherwise, run: git-daemon "%s"' % temp_dir
raise AssertionError(msg)
diff --git a/git/test/test_base.py b/git/test/test_base.py
index 22006470..cf92997f 100644
--- a/git/test/test_base.py
+++ b/git/test/test_base.py
@@ -24,6 +24,7 @@ from git import (
)
from git.objects.util import get_object_type_by_name
from gitdb.util import hex_to_bin
+from git.compat import is_win
class TestBase(TestBase):
@@ -117,7 +118,7 @@ class TestBase(TestBase):
assert rw_remote_repo.config_reader("repository").getboolean("core", "bare")
assert os.path.isdir(os.path.join(rw_repo.working_tree_dir, 'lib'))
- @skipIf(sys.version_info < (3, ) and os.name == 'nt',
+ @skipIf(sys.version_info < (3,) and is_win(),
"Unicode woes, see https://github.com/gitpython-developers/GitPython/pull/519")
@with_rw_repo('0.1.6')
def test_add_unicode(self, rw_repo):
@@ -134,7 +135,7 @@ class TestBase(TestBase):
open(file_path, "wb").write(b'something')
- if os.name == 'nt':
+ if is_win():
# on windows, there is no way this works, see images on
# https://github.com/gitpython-developers/GitPython/issues/147#issuecomment-68881897
# Therefore, it must be added using the python implementation
diff --git a/git/test/test_git.py b/git/test/test_git.py
index ea62de03..2ef15523 100644
--- a/git/test/test_git.py
+++ b/git/test/test_git.py
@@ -26,7 +26,7 @@ from git import (
)
from gitdb.test.lib import with_rw_directory
-from git.compat import PY3
+from git.compat import PY3, is_darwin
try:
from unittest import mock
@@ -214,7 +214,7 @@ class TestGit(TestBase):
try:
remote.fetch()
except GitCommandError as err:
- if sys.version_info[0] < 3 and sys.platform == 'darwin':
+ if sys.version_info[0] < 3 and is_darwin():
assert 'ssh-origin' in str(err)
assert err.status == 128
else:
diff --git a/git/test/test_index.py b/git/test/test_index.py
index 2ea787a4..b83201c9 100644
--- a/git/test/test_index.py
+++ b/git/test/test_index.py
@@ -27,7 +27,7 @@ from git import (
GitCommandError,
CheckoutError,
)
-from git.compat import string_types
+from git.compat import string_types, is_win
from gitdb.util import hex_to_bin
import os
import sys
@@ -577,7 +577,7 @@ class TestIndex(TestBase):
assert len(entries) == 1 and entries[0].hexsha != null_hex_sha
# add symlink
- if sys.platform != "win32":
+ if not is_win():
for target in ('/etc/nonexisting', '/etc/passwd', '/etc'):
basename = "my_real_symlink"
@@ -630,7 +630,7 @@ class TestIndex(TestBase):
index.checkout(fake_symlink_path)
# on windows we will never get symlinks
- if os.name == 'nt':
+ if is_win():
# simlinks should contain the link as text ( which is what a
# symlink actually is )
open(fake_symlink_path, 'rb').read() == link_target
@@ -711,7 +711,7 @@ class TestIndex(TestBase):
assert fkey not in index.entries
index.add(files, write=True)
- if os.name != 'nt':
+ if is_win():
hp = hook_path('pre-commit', index.repo.git_dir)
hpd = os.path.dirname(hp)
if not os.path.isdir(hpd):
diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py
index 881dd7e6..5906b06c 100644
--- a/git/test/test_submodule.py
+++ b/git/test/test_submodule.py
@@ -17,7 +17,7 @@ from git.exc import (
from git.objects.submodule.base import Submodule
from git.objects.submodule.root import RootModule, RootUpdateProgress
from git.util import to_native_path_linux, join_path_native
-from git.compat import string_types
+from git.compat import string_types, is_win
from git.repo.fun import (
find_git_dir,
touch
@@ -26,7 +26,7 @@ from git.repo.fun import (
# Change the configuration if possible to prevent the underlying memory manager
# to keep file handles open. On windows we get problems as they are not properly
# closed due to mmap bugs on windows (as it appears)
-if sys.platform == 'win32':
+if is_win():
try:
import smmap.util
smmap.util.MapRegion._test_read_into_memory = True
diff --git a/git/test/test_util.py b/git/test/test_util.py
index 2e53df50..76a5e0e9 100644
--- a/git/test/test_util.py
+++ b/git/test/test_util.py
@@ -24,10 +24,9 @@ from git.objects.util import (
parse_date,
)
from git.cmd import dashify
-from git.compat import string_types
+from git.compat import string_types, is_win
import time
-import sys
class TestIterableMember(object):
@@ -93,7 +92,7 @@ class TestUtils(TestBase):
elapsed = time.time() - start
# More extra time costs, but...
extra_time = 0.2
- if sys.platform == 'win32':
+ if is_win():
extra_time *= 4
self.assertLess(elapsed, wait_time + 0.02)
diff --git a/git/util.py b/git/util.py
index b56b96da..31ff94fa 100644
--- a/git/util.py
+++ b/git/util.py
@@ -6,7 +6,6 @@
import os
import re
-import sys
import time
import stat
import shutil
@@ -26,7 +25,7 @@ from .compat import (
# Most of these are unused here, but are for use by git-python modules so these
# don't see gitdb all the time. Flake of course doesn't like it.
-from gitdb.util import ( # NOQA
+from gitdb.util import (# NOQA
make_sha,
LockedFD,
file_contents_ro,
@@ -34,6 +33,7 @@ from gitdb.util import ( # NOQA
to_hex_sha,
to_bin_sha
)
+from git.compat import is_win
__all__ = ("stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux",
"join_path_native", "Stats", "IndexFileSHA1Writer", "Iterable", "IterableList",
@@ -106,7 +106,7 @@ def join_path(a, *p):
return path
-if sys.platform.startswith('win'):
+if is_win():
def to_native_path_windows(path):
return path.replace('/', '\\')
@@ -587,7 +587,7 @@ class LockFile(object):
try:
# on bloody windows, the file needs write permissions to be removable.
# Why ...
- if os.name == 'nt':
+ if is_win():
os.chmod(lfp, 0o777)
# END handle win32
os.remove(lfp)