Skip to content

Commit 3176fcf

Browse files
authored
Merge pull request #2778 from ytausch/readd-git-backend
2 parents e5283d3 + a4e79c5 commit 3176fcf

File tree

7 files changed

+1563
-252
lines changed

7 files changed

+1563
-252
lines changed

conda_forge_tick/auto_tick.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
from conda_forge_tick.git_utils import (
3131
GIT_CLONE_DIR,
3232
comment_on_pr,
33-
get_github_api_requests_left,
3433
get_repo,
34+
github_backend,
3535
is_github_api_limit_reached,
3636
push_repo,
3737
)
@@ -195,13 +195,7 @@ def run(
195195

196196
# TODO: run this in parallel
197197
feedstock_dir, repo = get_repo(
198-
fctx=feedstock_ctx,
199-
branch=branch_name,
200-
feedstock=feedstock_ctx.feedstock_name,
201-
protocol=protocol,
202-
pull_request=pull_request,
203-
fork=fork,
204-
base_branch=base_branch,
198+
fctx=feedstock_ctx, branch=branch_name, base_branch=base_branch
205199
)
206200
if not feedstock_dir or not repo:
207201
logger.critical(
@@ -618,7 +612,8 @@ def _run_migrator_on_feedstock_branch(
618612
fctx.feedstock_name,
619613
)
620614

621-
if is_github_api_limit_reached(e):
615+
if is_github_api_limit_reached():
616+
logger.warning("GitHub API error", exc_info=e)
622617
break_loop = True
623618

624619
except VersionMigrationError as e:
@@ -699,7 +694,8 @@ def _run_migrator_on_feedstock_branch(
699694

700695
def _is_migrator_done(_mg_start, good_prs, time_per, pr_limit):
701696
curr_time = time.time()
702-
api_req = get_github_api_requests_left()
697+
backend = github_backend()
698+
api_req = backend.get_api_requests_left()
703699

704700
if curr_time - START_TIME > TIMEOUT:
705701
logger.info(
@@ -1131,5 +1127,5 @@ def main(ctx: CliContext) -> None:
11311127
# ],
11321128
# )
11331129

1134-
logger.info("API Calls Remaining: %d", get_github_api_requests_left())
1130+
logger.info("API Calls Remaining: %d", github_backend().get_api_requests_left())
11351131
logger.info("Done")

conda_forge_tick/executors.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,21 @@ def __exit__(self, *args, **kwargs):
1616
pass
1717

1818

19-
TRLOCK = TRLock()
20-
PRLOCK = DummyLock()
21-
DRLOCK = DummyLock()
19+
GIT_LOCK_THREAD = TRLock()
20+
GIT_LOCK_PROCESS = DummyLock()
21+
GIT_LOCK_DASK = DummyLock()
22+
23+
24+
@contextlib.contextmanager
25+
def lock_git_operation():
26+
"""
27+
A context manager to lock git operations - it can be acquired once per thread, once per process,
28+
and once per dask worker.
29+
Note that this is a reentrant lock, so it can be acquired multiple times by the same thread/process/worker.
30+
"""
31+
32+
with GIT_LOCK_THREAD, GIT_LOCK_PROCESS, GIT_LOCK_DASK:
33+
yield
2234

2335

2436
logger = logging.getLogger(__name__)
@@ -27,10 +39,12 @@ def __exit__(self, *args, **kwargs):
2739
class DaskRLock(DaskLock):
2840
"""A reentrant lock for dask that is always blocking and never times out."""
2941

30-
def acquire(self):
31-
if not hasattr(self, "_rcount"):
32-
self._rcount = 0
42+
def __init__(self, *args, **kwargs):
43+
super().__init__(*args, **kwargs)
44+
self._rcount = 0
45+
self._rdata = None
3346

47+
def acquire(self, *args):
3448
self._rcount += 1
3549

3650
if self._rcount == 1:
@@ -39,29 +53,29 @@ def acquire(self):
3953
return self._rdata
4054

4155
def release(self):
42-
if not hasattr(self, "_rcount") or self._rcount == 0:
56+
if self._rcount == 0:
4357
raise RuntimeError("Lock not acquired so cannot be released!")
4458

4559
self._rcount -= 1
4660

4761
if self._rcount == 0:
48-
delattr(self, "_rdata")
62+
self._rdata = None
4963
return super().release()
5064
else:
5165
return None
5266

5367

5468
def _init_process(lock):
55-
global PRLOCK
56-
PRLOCK = lock
69+
global GIT_LOCK_PROCESS
70+
GIT_LOCK_PROCESS = lock
5771

5872

5973
def _init_dask(lock):
60-
global DRLOCK
61-
# it appears we have to construct the locak by name instead
74+
global GIT_LOCK_DASK
75+
# it appears we have to construct the lock by name instead
6276
# of passing the object itself
6377
# otherwise dask uses a regular lock
64-
DRLOCK = DaskRLock(name=lock)
78+
GIT_LOCK_DASK = DaskRLock(name=lock)
6579

6680

6781
@contextlib.contextmanager
@@ -70,8 +84,8 @@ def executor(kind: str, max_workers: int, daemon=True) -> typing.Iterator[Execut
7084
7185
This allows us to easily use other executors as needed.
7286
"""
73-
global DRLOCK
74-
global PRLOCK
87+
global GIT_LOCK_DASK
88+
global GIT_LOCK_PROCESS
7589

7690
if kind == "thread":
7791
with ThreadPoolExecutor(max_workers=max_workers) as pool_t:
@@ -85,7 +99,7 @@ def executor(kind: str, max_workers: int, daemon=True) -> typing.Iterator[Execut
8599
initargs=(lock,),
86100
) as pool_p:
87101
yield pool_p
88-
PRLOCK = DummyLock()
102+
GIT_LOCK_PROCESS = DummyLock()
89103
elif kind in ["dask", "dask-process", "dask-thread"]:
90104
import dask
91105
import distributed
@@ -101,6 +115,6 @@ def executor(kind: str, max_workers: int, daemon=True) -> typing.Iterator[Execut
101115
with distributed.Client(cluster) as client:
102116
client.run(_init_dask, "cftick")
103117
yield ClientExecutor(client)
104-
DRLOCK = DummyLock()
118+
GIT_LOCK_DASK = DummyLock()
105119
else:
106120
raise NotImplementedError("That kind is not implemented")

0 commit comments

Comments
 (0)