Skip to content

Commit 6752fad

Browse files
committed
add initial types to remote.py
1 parent 2fd9f6e commit 6752fad

32 files changed

+453
-243
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: byron

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The following is a short step-by-step rundown of what one typically would do to
55
* [fork this project](https://github.com/gitpython-developers/GitPython/fork) on GitHub.
66
* For setting up the environment to run the self tests, please look at `.travis.yml`.
77
* Please try to **write a test that fails unless the contribution is present.**
8-
* Feel free to add yourself to AUTHORS file.
8+
* Try to avoid massive commits and prefer to take small steps, with one commit for each.
9+
* Feel free to add yourself to AUTHORS file.
910
* Create a pull request.
1011

MANIFEST.in

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
include VERSION
2-
include LICENSE
3-
include CHANGES
41
include AUTHORS
2+
include CHANGES
53
include CONTRIBUTING.md
4+
include LICENSE
65
include README.md
6+
include VERSION
77
include requirements.txt
8+
include test-requirements.txt
89

910
recursive-include doc *
1011
recursive-exclude test *

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ release: clean
1515
make force_release
1616

1717
force_release: clean
18-
git push --tags origin master
18+
git push --tags origin main
1919
python3 setup.py sdist bdist_wheel
2020
twine upload -s -i 27C50E7F590947D7273A741E85194C08421980C9 dist/*
2121

@@ -24,7 +24,7 @@ docker-build:
2424

2525
test: docker-build
2626
# NOTE!!!
27-
# NOTE!!! If you are not running from master or have local changes then tests will fail
27+
# NOTE!!! If you are not running from main or have local changes then tests will fail
2828
# NOTE!!!
2929
docker run --rm -v ${CURDIR}:/src -w /src -t gitpython:xenial tox
3030

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.13
1+
3.1.15

doc/source/changes.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@
22
Changelog
33
=========
44

5-
3.1.??
5+
3.1.15
6+
======
7+
8+
* add deprectation warning for python 3.5
9+
10+
See the following for details:
11+
https://github.com/gitpython-developers/gitpython/milestone/47?closed=1
12+
13+
3.1.14
614
======
715

816
* git.Commit objects now have a ``replace`` method that will return a
917
copy of the commit with modified attributes.
1018
* Add python 3.9 support
1119
* Drop python 3.4 support
1220

21+
See the following for details:
22+
https://github.com/gitpython-developers/gitpython/milestone/46?closed=1
23+
1324
3.1.13
1425
======
1526

git/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66
# flake8: noqa
77
#@PydevCodeAnalysisIgnore
8+
from git.exc import * # @NoMove @IgnorePep8
89
import inspect
910
import os
1011
import sys
@@ -16,8 +17,6 @@
1617
__version__ = 'git'
1718

1819

19-
20-
2120
#{ Initialization
2221
def _init_externals() -> None:
2322
"""Initialize external projects by putting them into the path"""
@@ -32,13 +31,13 @@ def _init_externals() -> None:
3231

3332
#} END initialization
3433

34+
3535
#################
3636
_init_externals()
3737
#################
3838

3939
#{ Imports
4040

41-
from git.exc import * # @NoMove @IgnorePep8
4241
try:
4342
from git.config import GitConfigParser # @NoMove @IgnorePep8
4443
from git.objects import * # @NoMove @IgnorePep8
@@ -68,7 +67,8 @@ def _init_externals() -> None:
6867
#{ Initialize git executable path
6968
GIT_OK = None
7069

71-
def refresh(path:Optional[PathLike]=None) -> None:
70+
71+
def refresh(path: Optional[PathLike] = None) -> None:
7272
"""Convenience method for setting the git executable path."""
7373
global GIT_OK
7474
GIT_OK = False
@@ -81,6 +81,7 @@ def refresh(path:Optional[PathLike]=None) -> None:
8181
GIT_OK = True
8282
#} END initialize git executable path
8383

84+
8485
#################
8586
try:
8687
refresh()

git/cmd.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import threading
2020
from collections import OrderedDict
2121
from textwrap import dedent
22-
from typing import Any, Dict, List, Optional
22+
import warnings
2323

2424
from git.compat import (
2525
defenc,
@@ -29,7 +29,7 @@
2929
is_win,
3030
)
3131
from git.exc import CommandError
32-
from git.util import is_cygwin_git, cygpath, expand_path
32+
from git.util import is_cygwin_git, cygpath, expand_path, remove_password_if_present
3333

3434
from .exc import (
3535
GitCommandError,
@@ -40,8 +40,6 @@
4040
stream_copy,
4141
)
4242

43-
from .types import PathLike
44-
4543
execute_kwargs = {'istream', 'with_extended_output',
4644
'with_exceptions', 'as_process', 'stdout_as_string',
4745
'output_stream', 'with_stdout', 'kill_after_timeout',
@@ -85,8 +83,8 @@ def pump_stream(cmdline, name, stream, is_decode, handler):
8583
line = line.decode(defenc)
8684
handler(line)
8785
except Exception as ex:
88-
log.error("Pumping %r of cmd(%s) failed due to: %r", name, cmdline, ex)
89-
raise CommandError(['<%s-pump>' % name] + cmdline, ex) from ex
86+
log.error("Pumping %r of cmd(%s) failed due to: %r", name, remove_password_if_present(cmdline), ex)
87+
raise CommandError(['<%s-pump>' % name] + remove_password_if_present(cmdline), ex) from ex
9088
finally:
9189
stream.close()
9290

@@ -105,7 +103,7 @@ def pump_stream(cmdline, name, stream, is_decode, handler):
105103
for name, stream, handler in pumps:
106104
t = threading.Thread(target=pump_stream,
107105
args=(cmdline, name, stream, decode_streams, handler))
108-
t.setDaemon(True)
106+
t.daemon = True
109107
t.start()
110108
threads.append(t)
111109

@@ -140,7 +138,7 @@ def dict_to_slots_and__excluded_are_none(self, d, excluded=()):
140138

141139
## CREATE_NEW_PROCESS_GROUP is needed to allow killing it afterwards,
142140
# see https://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal
143-
PROC_CREATIONFLAGS = (CREATE_NO_WINDOW | subprocess.CREATE_NEW_PROCESS_GROUP
141+
PROC_CREATIONFLAGS = (CREATE_NO_WINDOW | subprocess.CREATE_NEW_PROCESS_GROUP # type: ignore[attr-defined]
144142
if is_win else 0)
145143

146144

@@ -212,7 +210,7 @@ def refresh(cls, path=None):
212210
# - a GitCommandNotFound error is spawned by ourselves
213211
# - a PermissionError is spawned if the git executable provided
214212
# cannot be executed for whatever reason
215-
213+
216214
has_git = False
217215
try:
218216
cls().version()
@@ -408,7 +406,7 @@ def read_all_from_possibly_closed_stream(stream):
408406
if status != 0:
409407
errstr = read_all_from_possibly_closed_stream(self.proc.stderr)
410408
log.debug('AutoInterrupt wait stderr: %r' % (errstr,))
411-
raise GitCommandError(self.args, status, errstr)
409+
raise GitCommandError(remove_password_if_present(self.args), status, errstr)
412410
# END status handling
413411
return status
414412
# END auto interrupt
@@ -500,7 +498,7 @@ def readlines(self, size=-1):
500498
# skipcq: PYL-E0301
501499
def __iter__(self):
502500
return self
503-
501+
504502
def __next__(self):
505503
return self.next()
506504

@@ -519,7 +517,7 @@ def __del__(self):
519517
self._stream.read(bytes_left + 1)
520518
# END handle incomplete read
521519

522-
def __init__(self, working_dir: Optional[PathLike]=None) -> None:
520+
def __init__(self, working_dir=None):
523521
"""Initialize this instance with:
524522
525523
:param working_dir:
@@ -528,12 +526,12 @@ def __init__(self, working_dir: Optional[PathLike]=None) -> None:
528526
It is meant to be the working tree directory if available, or the
529527
.git directory in case of bare repositories."""
530528
super(Git, self).__init__()
531-
self._working_dir = expand_path(working_dir) if working_dir is not None else None
529+
self._working_dir = expand_path(working_dir)
532530
self._git_options = ()
533-
self._persistent_git_options = [] # type: List[str]
531+
self._persistent_git_options = []
534532

535533
# Extra environment variables to pass to git commands
536-
self._environment = {} # type: Dict[str, Any]
534+
self._environment = {}
537535

538536
# cached command slots
539537
self.cat_file_header = None
@@ -547,7 +545,7 @@ def __getattr__(self, name):
547545
return LazyMixin.__getattr__(self, name)
548546
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
549547

550-
def set_persistent_git_options(self, **kwargs) -> None:
548+
def set_persistent_git_options(self, **kwargs):
551549
"""Specify command line options to the git executable
552550
for subsequent subcommand calls
553551
@@ -641,7 +639,7 @@ def execute(self, command,
641639
642640
:param env:
643641
A dictionary of environment variables to be passed to `subprocess.Popen`.
644-
642+
645643
:param max_chunk_size:
646644
Maximum number of bytes in one chunk of data passed to the output_stream in
647645
one invocation of write() method. If the given number is not positive then
@@ -685,8 +683,10 @@ def execute(self, command,
685683
:note:
686684
If you add additional keyword arguments to the signature of this method,
687685
you must update the execute_kwargs tuple housed in this module."""
686+
# Remove password for the command if present
687+
redacted_command = remove_password_if_present(command)
688688
if self.GIT_PYTHON_TRACE and (self.GIT_PYTHON_TRACE != 'full' or as_process):
689-
log.info(' '.join(command))
689+
log.info(' '.join(redacted_command))
690690

691691
# Allow the user to have the command executed in their working dir.
692692
cwd = self._working_dir or os.getcwd()
@@ -707,7 +707,7 @@ def execute(self, command,
707707
if is_win:
708708
cmd_not_found_exception = OSError
709709
if kill_after_timeout:
710-
raise GitCommandError(command, '"kill_after_timeout" feature is not supported on Windows.')
710+
raise GitCommandError(redacted_command, '"kill_after_timeout" feature is not supported on Windows.')
711711
else:
712712
if sys.version_info[0] > 2:
713713
cmd_not_found_exception = FileNotFoundError # NOQA # exists, flake8 unknown @UndefinedVariable
@@ -722,7 +722,7 @@ def execute(self, command,
722722
if istream:
723723
istream_ok = "<valid stream>"
724724
log.debug("Popen(%s, cwd=%s, universal_newlines=%s, shell=%s, istream=%s)",
725-
command, cwd, universal_newlines, shell, istream_ok)
725+
redacted_command, cwd, universal_newlines, shell, istream_ok)
726726
try:
727727
proc = Popen(command,
728728
env=env,
@@ -738,7 +738,7 @@ def execute(self, command,
738738
**subprocess_kwargs
739739
)
740740
except cmd_not_found_exception as err:
741-
raise GitCommandNotFound(command, err) from err
741+
raise GitCommandNotFound(redacted_command, err) from err
742742

743743
if as_process:
744744
return self.AutoInterrupt(proc, command)
@@ -788,7 +788,7 @@ def _kill_process(pid):
788788
watchdog.cancel()
789789
if kill_check.isSet():
790790
stderr_value = ('Timeout: the command "%s" did not complete in %d '
791-
'secs.' % (" ".join(command), kill_after_timeout))
791+
'secs.' % (" ".join(redacted_command), kill_after_timeout))
792792
if not universal_newlines:
793793
stderr_value = stderr_value.encode(defenc)
794794
# strip trailing "\n"
@@ -812,7 +812,7 @@ def _kill_process(pid):
812812
proc.stderr.close()
813813

814814
if self.GIT_PYTHON_TRACE == 'full':
815-
cmdstr = " ".join(command)
815+
cmdstr = " ".join(redacted_command)
816816

817817
def as_text(stdout_value):
818818
return not output_stream and safe_decode(stdout_value) or '<OUTPUT_STREAM>'
@@ -828,7 +828,7 @@ def as_text(stdout_value):
828828
# END handle debug printing
829829

830830
if with_exceptions and status != 0:
831-
raise GitCommandError(command, status, stderr_value, stdout_value)
831+
raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
832832

833833
if isinstance(stdout_value, bytes) and stdout_as_string: # could also be output_stream
834834
stdout_value = safe_decode(stdout_value)
@@ -905,8 +905,14 @@ def transform_kwarg(self, name, value, split_single_char_options):
905905

906906
def transform_kwargs(self, split_single_char_options=True, **kwargs):
907907
"""Transforms Python style kwargs into git command line options."""
908+
# Python 3.6 preserves the order of kwargs and thus has a stable
909+
# order. For older versions sort the kwargs by the key to get a stable
910+
# order.
911+
if sys.version_info[:2] < (3, 6):
912+
kwargs = OrderedDict(sorted(kwargs.items(), key=lambda x: x[0]))
913+
warnings.warn("Python 3.5 support is deprecated and will be removed 2021-09-05.\n" +
914+
"It does not preserve the order for key-word arguments and enforce lexical sorting instead.")
908915
args = []
909-
kwargs = OrderedDict(sorted(kwargs.items(), key=lambda x: x[0]))
910916
for k, v in kwargs.items():
911917
if isinstance(v, (list, tuple)):
912918
for value in v:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy