Skip to content

Extract all "import gc" to module level #1765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions git/objects/submodule/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import gc
from io import BytesIO
import logging
import os
@@ -1079,8 +1080,6 @@ def remove(
self._clear_cache()
wtd = mod.working_tree_dir
del mod # Release file-handles (Windows).
import gc

gc.collect()
rmtree(str(wtd))
# END delete tree if possible
3 changes: 1 addition & 2 deletions test/performance/test_commit.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

"""Performance tests for commits (iteration, traversal, and serialization)."""

import gc
from io import BytesIO
from time import time
import sys
@@ -17,8 +18,6 @@

class TestPerformance(TestBigRepoRW, TestCommitSerialization):
def tearDown(self):
import gc

gc.collect()

# ref with about 100 commits in its history.
3 changes: 1 addition & 2 deletions test/performance/test_streams.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

"""Performance tests for data streaming."""

import gc
import os
import subprocess
import sys
@@ -92,8 +93,6 @@ def test_large_data_streaming(self, rwrepo):

# del db file so git has something to do.
ostream = None
import gc

gc.collect()
os.remove(db_file)

3 changes: 1 addition & 2 deletions test/test_base.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import gc
import os
import sys
import tempfile
@@ -20,8 +21,6 @@

class TestBase(_TestBase):
def tearDown(self):
import gc

gc.collect()

type_tuples = (
3 changes: 1 addition & 2 deletions test/test_docs.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import gc
import os
import sys

@@ -16,8 +17,6 @@

class Tutorials(TestBase):
def tearDown(self):
import gc

gc.collect()

# ACTUALLY skipped by git.util.rmtree (in local onerror function), from the last call to it via
3 changes: 1 addition & 2 deletions test/test_git.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import gc
import inspect
import logging
import os
@@ -34,8 +35,6 @@ def setUpClass(cls):
cls.git = Git(cls.rorepo.working_dir)

def tearDown(self):
import gc

gc.collect()

def _assert_logged_for_popen(self, log_watcher, name, value):
4 changes: 2 additions & 2 deletions test/test_quick_doc.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import gc

from test.lib import TestBase
from test.lib.helper import with_rw_directory


class QuickDoc(TestBase):
def tearDown(self):
import gc

gc.collect()

@with_rw_directory
3 changes: 1 addition & 2 deletions test/test_remote.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import gc
import os
import os.path as osp
from pathlib import Path
@@ -105,8 +106,6 @@ def assert_received_message(self):

class TestRemote(TestBase):
def tearDown(self):
import gc

gc.collect()

def _print_fetchhead(self, repo):
3 changes: 1 addition & 2 deletions test/test_repo.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import gc
import glob
import io
from io import BytesIO
@@ -72,8 +73,6 @@ def tearDown(self):
if osp.isfile(lfp):
raise AssertionError("Previous TC left hanging git-lock file: {}".format(lfp))

import gc

gc.collect()

def test_new_should_raise_on_invalid_repo_location(self):
3 changes: 1 addition & 2 deletions test/test_submodule.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import contextlib
import gc
import os
import os.path as osp
from pathlib import Path
@@ -61,8 +62,6 @@ def update(self, op, cur_count, max_count, message=""):

class TestSubmodule(TestBase):
def tearDown(self):
import gc

gc.collect()

k_subm_current = "c15a6e1923a14bc760851913858a3942a4193cdb"