Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite9a8289

Browse files
author
Andrew Tergis
committed
feat: allow cfg timeout to be overrided via kwargs
On startup, the `timeout` parameter is loaded from config and stored onthe base gitlab object instance. This instance parameter is used as thetimeout for all API requests (it's passed into the `session` object whenmaking HTTP calls).This change allows any API method to specify a `timeout` argument to`**kwargs` that will override the global timeout value. This wassomewhat needed / helpful for the `import_github` method.I have also updated the docs accordingly.
1 parentaa4d41b commite9a8289

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

‎docs/api-usage.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,20 @@ default an exception is raised for these errors.
366366
367367
gl= gitlab.gitlab(url, token,api_version=4)
368368
gl.projects.list(all=True,retry_transient_errors=True)
369+
370+
Timeout
371+
-------
372+
373+
python-gitlab will by default use the ``timeout`` option from it's configuration
374+
for all requests. This is passed downwards to the ``requests`` module at the
375+
time of making the HTTP request. However if you would like to override the
376+
global timeout parameter for a particular call, you can provide the ``timeout``
377+
parameter to that API invocation:
378+
379+
..code-block::python
380+
381+
import gitlab
382+
383+
gl= gitlab.gitlab(url, token,api_version=4)
384+
gl.projects.import_github(ACCESS_TOKEN,123456,"root",timeout=120.0)
385+

‎gitlab/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ def http_request(
491491

492492
verify=opts.pop("verify")
493493
timeout=opts.pop("timeout")
494+
# If timeout was passed into kwargs, allow it to override the default
495+
timeout=kwargs.get("timeout",timeout)
494496

495497
# We need to deal with json vs. data when uploading files
496498
iffiles:

‎gitlab/v4/objects.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4745,13 +4745,7 @@ def import_project(
47454745
)
47464746

47474747
defimport_github(
4748-
self,
4749-
personal_access_token,
4750-
repo_id,
4751-
target_namespace,
4752-
new_name=None,
4753-
timeout_override=60.0,
4754-
**kwargs
4748+
self,personal_access_token,repo_id,target_namespace,new_name=None,**kwargs
47554749
):
47564750
"""Import a project from Github to Gitlab (schedule the import)
47574751
@@ -4761,15 +4755,14 @@ def import_github(
47614755
operation has completed.
47624756
47634757
NOTE: this request may take longer than most other API requests.
4764-
So this method willoverride the sessiontimeoutwith <timeout_override>,
4765-
which defaultsto60 seconds.
4758+
So this method willspecify a 60 second defaulttimeoutif none is specified.
4759+
A timeout can be specified via kwargstooverride this functionality.
47664760
47674761
Args:
47684762
personal_access_token (str): GitHub personal access token
47694763
repo_id (int): Github repository ID
47704764
target_namespace (str): Namespace to import repo into
47714765
new_name (str): New repo name (Optional)
4772-
timeout_override (int or float): Timeout to use for this request
47734766
**kwargs: Extra options to send to the server (e.g. sudo)
47744767
47754768
Raises:
@@ -4801,10 +4794,17 @@ def import_github(
48014794
}
48024795
ifnew_name:
48034796
data["new_name"]=new_name
4804-
prev_timeout=self.gitlab.timeout
4805-
self.gitlab.timeout=timeout_override
4797+
if (
4798+
"timeout"notinkwargs
4799+
orself.gitlab.timeoutisNone
4800+
orself.gitlab.timeout<60.0
4801+
):
4802+
# Ensure that this HTTP request has a longer-than-usual default timeout
4803+
# The base gitlab object tends to have a default that is <10 seconds,
4804+
# and this is too short for this API command, typically.
4805+
# On the order of 24 seconds has been measured on a typical gitlab instance.
4806+
kwargs["timeout"]=60.0
48064807
result=self.gitlab.http_post("/import/github",post_data=data,**kwargs)
4807-
self.gitlab.timeout=prev_timeout
48084808
returnresult
48094809

48104810

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp