Skip to content

Commit 0210e39

Browse files
committed
src: import os.path as osp
1 parent a2d248b commit 0210e39

24 files changed

+361
-332
lines changed

Diff for: git/__init__.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66
# flake8: noqa
77
#@PydevCodeAnalysisIgnore
8+
import inspect
89
import os
910
import sys
10-
import inspect
11+
12+
import os.path as osp
13+
1114

1215
__version__ = 'git'
1316

@@ -16,7 +19,7 @@
1619
def _init_externals():
1720
"""Initialize external projects by putting them into the path"""
1821
if __version__ == 'git':
19-
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'ext', 'gitdb'))
22+
sys.path.insert(0, osp.join(osp.dirname(__file__), 'ext', 'gitdb'))
2023

2124
try:
2225
import gitdb

Diff for: git/config.py

+20-16
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,13 @@
66
"""Module containing module parser implementation able to properly read and write
77
configuration files"""
88

9-
import re
10-
try:
11-
import ConfigParser as cp
12-
except ImportError:
13-
# PY3
14-
import configparser as cp
9+
import abc
10+
from functools import wraps
1511
import inspect
1612
import logging
17-
import abc
1813
import os
14+
import re
1915

20-
from functools import wraps
21-
22-
from git.odict import OrderedDict
23-
from git.util import LockFile
2416
from git.compat import (
2517
string_types,
2618
FileType,
@@ -29,6 +21,18 @@
2921
with_metaclass,
3022
PY3
3123
)
24+
from git.odict import OrderedDict
25+
from git.util import LockFile
26+
27+
import os.path as osp
28+
29+
30+
try:
31+
import ConfigParser as cp
32+
except ImportError:
33+
# PY3
34+
import configparser as cp
35+
3236

3337
__all__ = ('GitConfigParser', 'SectionConstraint')
3438

@@ -408,15 +412,15 @@ def read(self):
408412
if self._has_includes():
409413
for _, include_path in self.items('include'):
410414
if include_path.startswith('~'):
411-
include_path = os.path.expanduser(include_path)
412-
if not os.path.isabs(include_path):
415+
include_path = osp.expanduser(include_path)
416+
if not osp.isabs(include_path):
413417
if not file_ok:
414418
continue
415419
# end ignore relative paths if we don't know the configuration file path
416-
assert os.path.isabs(file_path), "Need absolute paths to be sure our cycle checks will work"
417-
include_path = os.path.join(os.path.dirname(file_path), include_path)
420+
assert osp.isabs(file_path), "Need absolute paths to be sure our cycle checks will work"
421+
include_path = osp.join(osp.dirname(file_path), include_path)
418422
# end make include path absolute
419-
include_path = os.path.normpath(include_path)
423+
include_path = osp.normpath(include_path)
420424
if include_path in seen or not os.access(include_path, os.R_OK):
421425
continue
422426
seen.add(include_path)

Diff for: git/index/base.py

+35-39
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,36 @@
33
#
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
6-
import tempfile
7-
import os
8-
import sys
9-
import subprocess
106
import glob
117
from io import BytesIO
12-
8+
import os
139
from stat import S_ISLNK
10+
import subprocess
11+
import sys
12+
import tempfile
1413

15-
from .typ import (
16-
BaseIndexEntry,
17-
IndexEntry,
18-
)
19-
20-
from .util import (
21-
TemporaryFileSwap,
22-
post_clear_cache,
23-
default_index,
24-
git_working_dir
14+
from git.compat import (
15+
izip,
16+
xrange,
17+
string_types,
18+
force_bytes,
19+
defenc,
20+
mviter,
21+
is_win
2522
)
26-
27-
import git.diff as diff
2823
from git.exc import (
2924
GitCommandError,
3025
CheckoutError,
3126
InvalidGitRepositoryError
3227
)
33-
3428
from git.objects import (
3529
Blob,
3630
Submodule,
3731
Tree,
3832
Object,
3933
Commit,
4034
)
41-
4235
from git.objects.util import Serializable
43-
from git.compat import (
44-
izip,
45-
xrange,
46-
string_types,
47-
force_bytes,
48-
defenc,
49-
mviter,
50-
is_win
51-
)
52-
5336
from git.util import (
5437
LazyMixin,
5538
LockedFD,
@@ -58,6 +41,12 @@
5841
to_native_path_linux,
5942
unbare_repo
6043
)
44+
from gitdb.base import IStream
45+
from gitdb.db import MemoryDB
46+
from gitdb.util import to_bin_sha
47+
48+
import git.diff as diff
49+
import os.path as osp
6150

6251
from .fun import (
6352
entry_key,
@@ -69,10 +58,17 @@
6958
S_IFGITLINK,
7059
run_commit_hook
7160
)
61+
from .typ import (
62+
BaseIndexEntry,
63+
IndexEntry,
64+
)
65+
from .util import (
66+
TemporaryFileSwap,
67+
post_clear_cache,
68+
default_index,
69+
git_working_dir
70+
)
7271

73-
from gitdb.base import IStream
74-
from gitdb.db import MemoryDB
75-
from gitdb.util import to_bin_sha
7672

7773
__all__ = ('IndexFile', 'CheckoutError')
7874

@@ -354,7 +350,7 @@ def from_tree(cls, repo, *treeish, **kwargs):
354350
index.entries # force it to read the file as we will delete the temp-file
355351
del(index_handler) # release as soon as possible
356352
finally:
357-
if os.path.exists(tmp_index):
353+
if osp.exists(tmp_index):
358354
os.remove(tmp_index)
359355
# END index merge handling
360356

@@ -374,8 +370,8 @@ def raise_exc(e):
374370
rs = r + os.sep
375371
for path in paths:
376372
abs_path = path
377-
if not os.path.isabs(abs_path):
378-
abs_path = os.path.join(r, path)
373+
if not osp.isabs(abs_path):
374+
abs_path = osp.join(r, path)
379375
# END make absolute path
380376

381377
try:
@@ -407,7 +403,7 @@ def raise_exc(e):
407403
for root, dirs, files in os.walk(abs_path, onerror=raise_exc): # @UnusedVariable
408404
for rela_file in files:
409405
# add relative paths only
410-
yield os.path.join(root.replace(rs, ''), rela_file)
406+
yield osp.join(root.replace(rs, ''), rela_file)
411407
# END for each file in subdir
412408
# END for each subdirectory
413409
except OSError:
@@ -569,7 +565,7 @@ def _process_diff_args(self, args):
569565
def _to_relative_path(self, path):
570566
""":return: Version of path relative to our git directory or raise ValueError
571567
if it is not within our git direcotory"""
572-
if not os.path.isabs(path):
568+
if not osp.isabs(path):
573569
return path
574570
if self.repo.bare:
575571
raise InvalidGitRepositoryError("require non-bare repository")
@@ -617,12 +613,12 @@ def _entries_for_paths(self, paths, path_rewriter, fprogress, entries):
617613
entries_added = list()
618614
if path_rewriter:
619615
for path in paths:
620-
if os.path.isabs(path):
616+
if osp.isabs(path):
621617
abspath = path
622618
gitrelative_path = path[len(self.repo.working_tree_dir) + 1:]
623619
else:
624620
gitrelative_path = path
625-
abspath = os.path.join(self.repo.working_tree_dir, gitrelative_path)
621+
abspath = osp.join(self.repo.working_tree_dir, gitrelative_path)
626622
# end obtain relative and absolute paths
627623

628624
blob = Blob(self.repo, Blob.NULL_BIN_SHA,

Diff for: git/index/fun.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Contains standalone functions to accompany the index implementation and make it
22
# more versatile
33
# NOTE: Autodoc hates it if this is a docstring
4+
from io import BytesIO
5+
import os
46
from stat import (
57
S_IFDIR,
68
S_IFLNK,
@@ -9,13 +11,18 @@
911
S_IFMT,
1012
S_IFREG,
1113
)
12-
13-
from io import BytesIO
14-
import os
1514
import subprocess
1615

17-
from git.util import IndexFileSHA1Writer, finalize_process
1816
from git.cmd import PROC_CREATIONFLAGS, handle_process_output
17+
from git.compat import (
18+
PY3,
19+
defenc,
20+
force_text,
21+
force_bytes,
22+
is_posix,
23+
safe_encode,
24+
safe_decode,
25+
)
1926
from git.exc import (
2027
UnmergedEntriesError,
2128
HookExecutionError
@@ -25,30 +32,23 @@
2532
traverse_tree_recursive,
2633
traverse_trees_recursive
2734
)
35+
from git.util import IndexFileSHA1Writer, finalize_process
36+
from gitdb.base import IStream
37+
from gitdb.typ import str_tree_type
38+
39+
import os.path as osp
2840

2941
from .typ import (
3042
BaseIndexEntry,
3143
IndexEntry,
3244
CE_NAMEMASK,
3345
CE_STAGESHIFT
3446
)
35-
3647
from .util import (
3748
pack,
3849
unpack
3950
)
4051

41-
from gitdb.base import IStream
42-
from gitdb.typ import str_tree_type
43-
from git.compat import (
44-
PY3,
45-
defenc,
46-
force_text,
47-
force_bytes,
48-
is_posix,
49-
safe_encode,
50-
safe_decode,
51-
)
5252

5353
S_IFGITLINK = S_IFLNK | S_IFDIR # a submodule
5454
CE_NAMEMASK_INV = ~CE_NAMEMASK
@@ -59,7 +59,7 @@
5959

6060
def hook_path(name, git_dir):
6161
""":return: path to the given named hook in the given git repository directory"""
62-
return os.path.join(git_dir, 'hooks', name)
62+
return osp.join(git_dir, 'hooks', name)
6363

6464

6565
def run_commit_hook(name, index):

Diff for: git/index/util.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
"""Module containing index utilities"""
2+
from functools import wraps
3+
import os
24
import struct
35
import tempfile
4-
import os
5-
6-
from functools import wraps
76

87
from git.compat import is_win
98

9+
import os.path as osp
10+
11+
1012
__all__ = ('TemporaryFileSwap', 'post_clear_cache', 'default_index', 'git_working_dir')
1113

1214
#{ Aliases
@@ -32,8 +34,8 @@ def __init__(self, file_path):
3234
pass
3335

3436
def __del__(self):
35-
if os.path.isfile(self.tmp_file_path):
36-
if is_win and os.path.exists(self.file_path):
37+
if osp.isfile(self.tmp_file_path):
38+
if is_win and osp.exists(self.file_path):
3739
os.remove(self.file_path)
3840
os.rename(self.tmp_file_path, self.file_path)
3941
# END temp file exists

0 commit comments

Comments
 (0)