From 913d806f02cf50250d230f88b897350581f80f6b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 29 Jul 2019 07:57:46 +0800 Subject: [PATCH 01/12] Revert "Drop python 2.7 support and help with encodings" This reverts commit dac619e4917b0ad43d836a534633d68a871aecca. --- .travis.yml | 1 + README.md | 2 +- doc/source/intro.rst | 2 +- git/compat.py | 5 +---- git/repo/base.py | 1 - requirements.txt | 2 -- setup.py | 4 +++- 7 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 206c133e4..56c86d1b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: python python: + - "2.7" - "3.4" - "3.5" - "3.6" diff --git a/README.md b/README.md index 3734019ec..e252c34c9 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ If it is not in your `PATH`, you can help GitPython find it by setting the `GIT_PYTHON_GIT_EXECUTABLE=` environment variable. * Git (1.7.x or newer) -* Python 3 to 3.7. +* Python 2.7 to 3.7. The list of dependencies are listed in `./requirements.txt` and `./test-requirements.txt`. The installer takes care of installing them for you. diff --git a/doc/source/intro.rst b/doc/source/intro.rst index e2cd196b8..d68e5eb22 100644 --- a/doc/source/intro.rst +++ b/doc/source/intro.rst @@ -13,7 +13,7 @@ The object database implementation is optimized for handling large quantities of Requirements ============ -* `Python`_ 3.0 or newer +* `Python`_ 2.7 or newer * `Git`_ 1.7.0 or newer It should also work with older versions, but it may be that some operations involving remotes will not work as expected. diff --git a/git/compat.py b/git/compat.py index 02dc69de8..b63768f3d 100644 --- a/git/compat.py +++ b/git/compat.py @@ -30,10 +30,7 @@ is_win = (os.name == 'nt') is_posix = (os.name == 'posix') is_darwin = (os.name == 'darwin') -if hasattr(sys, 'getfilesystemencoding'): - defenc = sys.getfilesystemencoding() -if defenc is None: - defenc = sys.getdefaultencoding() +defenc = sys.getdefaultencoding() if PY3: import io diff --git a/git/repo/base.py b/git/repo/base.py index 911494ad6..f35870803 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -4,7 +4,6 @@ # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php -from builtins import str from collections import namedtuple import logging import os diff --git a/requirements.txt b/requirements.txt index c0cca9f49..63d5ddfe7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1 @@ gitdb2 (>=2.0.0) -gitdb>=0.6.4 -ddt>=1.1.1 diff --git a/setup.py b/setup.py index 65656d555..49288f697 100755 --- a/setup.py +++ b/setup.py @@ -79,7 +79,7 @@ def _stamp_version(filename): package_data={'git.test': ['fixtures/*']}, package_dir={'git': 'git'}, license="BSD License", - python_requires='>=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*', + python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*', install_requires=requirements, tests_require=requirements + test_requirements, zip_safe=False, @@ -102,6 +102,8 @@ def _stamp_version(filename): "Operating System :: Microsoft :: Windows", "Operating System :: MacOS :: MacOS X", "Programming Language :: Python", + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", From 859ad046aecc077b9118f0a1c2896e3f9237cd75 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 29 Jul 2019 08:01:07 +0800 Subject: [PATCH 02/12] Bring back python 2 support --- VERSION | 2 +- doc/source/changes.rst | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 348fc11ef..ea4bd0fb3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.12 +2.1.13 diff --git a/doc/source/changes.rst b/doc/source/changes.rst index 92c28b69b..b9f286384 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -2,6 +2,12 @@ Changelog ========= +2.1.13 - Bring back Python 2.7 support +====================================== + +My apologies for any inconvenience this may have caused. Following semver, backward incompatible changes +will be introduced in a minor version. + 2.1.12 - Bugfixes and Features ============================== From 80204335d827eb9ed4861e16634822bf9aa60912 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Fri, 26 Jul 2019 21:14:32 -0500 Subject: [PATCH 03/12] Remove python 2 from CI Python 2 support was dropped, there is not need to run tests in py2 --- .appveyor.yml | 9 --------- test-requirements.txt | 1 - tox.ini | 2 +- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 017cf1204..2658d96e5 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -5,9 +5,6 @@ environment: CYGWIN64_GIT_PATH: "C:\\cygwin64\\bin;%GIT_DAEMON_PATH%" matrix: - - PYTHON: "C:\\Python27" - PYTHON_VERSION: "2.7" - GIT_PATH: "%GIT_DAEMON_PATH%" - PYTHON: "C:\\Python34-x64" PYTHON_VERSION: "3.4" GIT_PATH: "%GIT_DAEMON_PATH%" @@ -26,12 +23,6 @@ environment: MAYFAIL: "yes" GIT_PATH: "%GIT_DAEMON_PATH%" ## Cygwin - - PYTHON: "C:\\Miniconda-x64" - PYTHON_VERSION: "2.7" - IS_CONDA: "yes" - IS_CYGWIN: "yes" - MAYFAIL: "yes" - GIT_PATH: "%CYGWIN_GIT_PATH%" - PYTHON: "C:\\Python35-x64" PYTHON_VERSION: "3.5" IS_CYGWIN: "yes" diff --git a/test-requirements.txt b/test-requirements.txt index ec0e4c561..ec2912baf 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,4 +3,3 @@ coverage flake8 nose tox -mock; python_version=='2.7' diff --git a/tox.ini b/tox.ini index e46136d67..36048fbc2 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py34,py35,py36,py37,flake8 +envlist = py34,py35,py36,py37,flake8 [testenv] commands = nosetests {posargs} From daa3f353091ada049c0ede23997f4801cbe9941b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Ne=C4=8Das?= Date: Tue, 23 Jul 2019 12:43:24 +0200 Subject: [PATCH 04/12] Fix Git.transform_kwarg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Kwargs were not transformed correctly if a value was set to 0 due to wrong if condition. Signed-off-by: František Nečas --- git/cmd.py | 2 +- git/test/test_git.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/git/cmd.py b/git/cmd.py index 64c3d480a..50b1e3212 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -893,7 +893,7 @@ def transform_kwarg(self, name, value, split_single_char_options): else: if value is True: return ["--%s" % dashify(name)] - elif value not in (False, None): + elif value is not False and value is not None: return ["--%s=%s" % (dashify(name), value)] return [] diff --git a/git/test/test_git.py b/git/test/test_git.py index 30a6a335e..4a189267e 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -86,6 +86,7 @@ def test_it_transforms_kwargs_into_git_command_arguments(self): assert_equal(["--max-count"], self.git.transform_kwargs(**{'max_count': True})) assert_equal(["--max-count=5"], self.git.transform_kwargs(**{'max_count': 5})) + assert_equal(["--max-count=0"], self.git.transform_kwargs(**{'max_count': 0})) assert_equal([], self.git.transform_kwargs(**{'max_count': None})) # Multiple args are supported by using lists/tuples From 0b6b90f9f1e5310a6f39b75e17a04c1133269e8f Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 16 Jul 2019 11:42:43 +0200 Subject: [PATCH 05/12] use git rev-parse to look for config file --- git/repo/base.py | 56 ++++++++++++++++++++++++++++++------------ git/test/lib/helper.py | 3 +-- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/git/repo/base.py b/git/repo/base.py index f35870803..af8e0c74c 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -66,7 +66,7 @@ class Repo(object): 'git_dir' is the .git repository directory, which is always set.""" DAEMON_EXPORT_FILE = 'git-daemon-export-ok' - git = None # Must exist, or __del__ will fail in case we raise on `__init__()` + _git = None # Must exist, or __del__ will fail in case we raise on `__init__()` working_dir = None _working_tree_dir = None git_dir = None @@ -202,7 +202,6 @@ def __init__(self, path=None, odbt=GitCmdObjectDB, search_parent_directories=Fal # END working dir handling self.working_dir = self._working_tree_dir or self.common_dir - self.git = self.GitCommandWrapperType(self.working_dir) # special handling, in special times args = [osp.join(self.common_dir, 'objects')] @@ -210,6 +209,35 @@ def __init__(self, path=None, odbt=GitCmdObjectDB, search_parent_directories=Fal args.append(self.git) self.odb = odbt(*args) + def _get_git(self): + working_dir = self._working_tree_dir or self.common_dir + if self._git: + if self._git._working_dir != expand_path(working_dir): + self.close() + self._git = None + + if not self._git: + self._git = self.GitCommandWrapperType(working_dir) + return self._git + + def _del_git(self): + if self._git: + self._git.clear_cache() + self._git = None + # Tempfiles objects on Windows are holding references to + # open files until they are collected by the garbage + # collector, thus preventing deletion. + # TODO: Find these references and ensure they are closed + # and deleted synchronously rather than forcing a gc + # collection. + if is_win: + gc.collect() + gitdb.util.mman.collect() + if is_win: + gc.collect() + + git = property(fget=_get_git, fdel=_del_git) + def __enter__(self): return self @@ -223,19 +251,7 @@ def __del__(self): pass def close(self): - if self.git: - self.git.clear_cache() - # Tempfiles objects on Windows are holding references to - # open files until they are collected by the garbage - # collector, thus preventing deletion. - # TODO: Find these references and ensure they are closed - # and deleted synchronously rather than forcing a gc - # collection. - if is_win: - gc.collect() - gitdb.util.mman.collect() - if is_win: - gc.collect() + del self.git def __eq__(self, rhs): if isinstance(rhs, Repo): @@ -431,7 +447,15 @@ def _get_config_path(self, config_level): elif config_level == "global": return osp.normpath(osp.expanduser("~/.gitconfig")) elif config_level == "repository": - return osp.normpath(osp.join(self._common_dir or self.git_dir, "config")) + try: + config_path = self.git.rev_parse("config", git_path=True) + except GitCommandError: + return osp.normpath(osp.join(self._common_dir or self.git_dir, "config")) + else: + if self.git._working_dir: + return osp.normpath(osp.join(self.git._working_dir, config_path)) + else: + return config_path raise ValueError("Invalid configuration level: %r" % config_level) diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py index 1c06010f4..687db9906 100644 --- a/git/test/lib/helper.py +++ b/git/test/lib/helper.py @@ -366,8 +366,7 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): - cls.rorepo.git.clear_cache() - cls.rorepo.git = None + del cls.rorepo.git def _make_file(self, rela_path, data, repo=None): """ From 2e7e82b114a5c1b3eb61f171c376e1cf85563d07 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 29 Jul 2019 08:11:21 +0800 Subject: [PATCH 06/12] Drop python 2 support, again (revert previous revert) This reverts commit 913d806f02cf50250d230f88b897350581f80f6b. --- .travis.yml | 1 - README.md | 2 +- doc/source/intro.rst | 2 +- git/compat.py | 5 ++++- git/repo/base.py | 1 + requirements.txt | 2 ++ setup.py | 4 +--- 7 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 56c86d1b9..206c133e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: python python: - - "2.7" - "3.4" - "3.5" - "3.6" diff --git a/README.md b/README.md index e252c34c9..3734019ec 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ If it is not in your `PATH`, you can help GitPython find it by setting the `GIT_PYTHON_GIT_EXECUTABLE=` environment variable. * Git (1.7.x or newer) -* Python 2.7 to 3.7. +* Python 3 to 3.7. The list of dependencies are listed in `./requirements.txt` and `./test-requirements.txt`. The installer takes care of installing them for you. diff --git a/doc/source/intro.rst b/doc/source/intro.rst index d68e5eb22..e2cd196b8 100644 --- a/doc/source/intro.rst +++ b/doc/source/intro.rst @@ -13,7 +13,7 @@ The object database implementation is optimized for handling large quantities of Requirements ============ -* `Python`_ 2.7 or newer +* `Python`_ 3.0 or newer * `Git`_ 1.7.0 or newer It should also work with older versions, but it may be that some operations involving remotes will not work as expected. diff --git a/git/compat.py b/git/compat.py index b63768f3d..02dc69de8 100644 --- a/git/compat.py +++ b/git/compat.py @@ -30,7 +30,10 @@ is_win = (os.name == 'nt') is_posix = (os.name == 'posix') is_darwin = (os.name == 'darwin') -defenc = sys.getdefaultencoding() +if hasattr(sys, 'getfilesystemencoding'): + defenc = sys.getfilesystemencoding() +if defenc is None: + defenc = sys.getdefaultencoding() if PY3: import io diff --git a/git/repo/base.py b/git/repo/base.py index af8e0c74c..52eeb67ba 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -4,6 +4,7 @@ # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php +from builtins import str from collections import namedtuple import logging import os diff --git a/requirements.txt b/requirements.txt index 63d5ddfe7..c0cca9f49 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ gitdb2 (>=2.0.0) +gitdb>=0.6.4 +ddt>=1.1.1 diff --git a/setup.py b/setup.py index 49288f697..65656d555 100755 --- a/setup.py +++ b/setup.py @@ -79,7 +79,7 @@ def _stamp_version(filename): package_data={'git.test': ['fixtures/*']}, package_dir={'git': 'git'}, license="BSD License", - python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*', + python_requires='>=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*', install_requires=requirements, tests_require=requirements + test_requirements, zip_safe=False, @@ -102,8 +102,6 @@ def _stamp_version(filename): "Operating System :: Microsoft :: Windows", "Operating System :: MacOS :: MacOS X", "Programming Language :: Python", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", From 71bd08050c122eff2a7b6970ba38564e67e33760 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 29 Jul 2019 08:10:32 +0800 Subject: [PATCH 07/12] Version 3.0 - drop python 2 support --- VERSION | 2 +- doc/source/changes.rst | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index ea4bd0fb3..4a36342fc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.13 +3.0.0 diff --git a/doc/source/changes.rst b/doc/source/changes.rst index b9f286384..fd7bd6867 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -2,6 +2,22 @@ Changelog ========= +3.0.0 - Remove Python 2 support +=============================== + +Motivation for this is a patch which improves unicode handling when dealing with filesystem paths. +Python 2 compatibility was introduced to deal with differences, and I thought it would be a good idea +to 'just' drop support right now, mere 5 months away from the official maintenance stop of python 2.7. + +The underlying motivation clearly is my anger when thinking python and unicode, which was a hassle from the +start, at least in a codebase as old as GitPython, which totally doesn't handle encodings correctly in many cases. + +Having migrated to using `Rust` exclusively for tooling, I still see that correct handling of encodings isn't entirely +trivial, but at least `Rust` makes clear what has to be done at compile time, allowing to write software that is pretty +much guaranteed to work once it compiles. + +Again, my apologies if removing Python 2 support caused inconveniences, please see release 2.1.13 which returns it. + 2.1.13 - Bring back Python 2.7 support ====================================== From 326409d7afd091c693f3c931654b054df6997d97 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Aug 2019 14:56:39 +0800 Subject: [PATCH 08/12] Fix test bound to major version --- git/test/test_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/test/test_docs.py b/git/test/test_docs.py index 770f78e20..c14f5ff3b 100644 --- a/git/test/test_docs.py +++ b/git/test/test_docs.py @@ -106,7 +106,7 @@ def test_init_repo_object(self, rw_dir): # [11-test_init_repo_object] assert now.commit.message != past.commit.message # You can read objects directly through binary streams, no working tree required - assert (now.commit.tree / 'VERSION').data_stream.read().decode('ascii').startswith('2') + assert (now.commit.tree / 'VERSION').data_stream.read().decode('ascii').startswith('3') # You can traverse trees as well to handle all contained files of a particular commit file_count = 0 From acbd5c05c7a7987c0ac9ae925032ae553095ebee Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Aug 2019 16:09:38 +0800 Subject: [PATCH 09/12] Avoid creating python 2 release Thank you! https://github.com/gitpython-developers/GitPython/issues/898#issuecomment-515831903 [skip CI] --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 3c6e79cf3..aa76baec6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,2 @@ [bdist_wheel] -universal=1 +universal=0 From d2cd5970af1ea8024ecf82b11c1b3802d7c72ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Antoine=20Gombeaud?= Date: Wed, 7 Aug 2019 16:08:24 +0200 Subject: [PATCH 10/12] Fix typo in documentation `mutli_options` -> `multi_options` --- git/repo/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/repo/base.py b/git/repo/base.py index 52eeb67ba..31b57a332 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -1036,7 +1036,7 @@ def clone_from(cls, url, to_path, progress=None, env=None, multi_options=None, * :param to_path: Path to which the repository should be cloned to :param progress: See 'git.remote.Remote.push'. :param env: Optional dictionary containing the desired environment variables. - :param mutli_options: See ``clone`` method + :param multi_options: See ``clone`` method :param kwargs: see the ``clone`` method :return: Repo instance pointing to the cloned directory""" git = Git(os.getcwd()) From dab0c2e0da17c879e13f0b1f6fbf307acf48a4ff Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Mon, 5 Aug 2019 09:41:10 +0200 Subject: [PATCH 11/12] Correcting a file name --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3279a6722..0347afcb5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,6 +2,6 @@ * [fork this project](https://github.com/gitpython-developers/GitPython/fork) on GitHub * For setting up the environment to run the self tests, look at `.travis.yml`. -* Add yourself to AUTHORS.md and write your patch. **Write a test that fails unless your patch is present.** +* Add yourself to AUTHORS and write your patch. **Write a test that fails unless your patch is present.** * Initiate a pull request From 5fa99bff215249378f90e1ce0254e66af155a301 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 12 Aug 2019 11:17:20 +0800 Subject: [PATCH 12/12] finalize chagnes.rst for 3.0 release --- doc/source/changes.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/source/changes.rst b/doc/source/changes.rst index fd7bd6867..176611df8 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -18,6 +18,12 @@ much guaranteed to work once it compiles. Again, my apologies if removing Python 2 support caused inconveniences, please see release 2.1.13 which returns it. +see the following for (most) details: +https://github.com/gitpython-developers/gitpython/milestone/27?closed=1 + +or run have a look at the difference between tags v2.1.12 and v3.0.0: +https://github.com/gitpython-developers/GitPython/compare/2.1.12...3.0.0. + 2.1.13 - Bring back Python 2.7 support ====================================== @@ -29,9 +35,6 @@ will be introduced in a minor version. * Multi-value support and interface improvements for Git configuration. Thanks to A. Jesse Jiryu Davis. -see the following for (most) details: -https://github.com/gitpython-developers/gitpython/milestone/27?closed=1 - or run have a look at the difference between tags v2.1.11 and v2.1.12: https://github.com/gitpython-developers/GitPython/compare/2.1.11...2.1.12