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

Commit6b3e7c0

Browse files
chore: convert to using relative imports
Switch to using relative imports to ensure that we are importing fromwithin our library.Also use the form: from foo import bar as barWhen we want to signify that we want the import to be re-exported.https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-no-implicit-reexport
1 parent789122d commit6b3e7c0

File tree

69 files changed

+301
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+301
-319
lines changed

‎gitlab/__init__.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@
1919
importwarnings
2020
fromtypingimportAny
2121

22-
importgitlab.config# noqa: F401
23-
fromgitlab.versionimport (# noqa: F401
24-
__author__,
25-
__copyright__,
26-
__email__,
27-
__license__,
28-
__title__,
29-
__version__,
30-
)
31-
fromgitlab.clientimportGitlab,GitlabList# noqa: F401
32-
fromgitlab.exceptionsimport*# noqa: F401,F403
22+
from .importconfigasconfig# noqa: F401
23+
from .importconstasconst
24+
from .importexceptionsasexceptions# noqa: F401
25+
from .clientimportGitlabasGitlab# noqa: F401
26+
from .clientimportGitlabListasGitlabList# noqa: F401
27+
from .exceptionsimport*# noqa: F401,F403
28+
from .versionimport__author__as__author__# noqa: F401
29+
from .versionimport__copyright__as__copyright__# noqa: F401
30+
from .versionimport__email__as__email__# noqa: F401
31+
from .versionimport__license__as__license__# noqa: F401
32+
from .versionimport__title__as__title__# noqa: F401
33+
from .versionimport__version__as__version__# noqa: F401
3334

3435
warnings.filterwarnings("default",category=DeprecationWarning,module="^gitlab")
3536

@@ -39,12 +40,12 @@
3940
# 'from gitlab.const import *' statement.
4041
def__getattr__(name:str)->Any:
4142
# Deprecate direct access to constants without namespace
42-
ifnameingitlab.const._DEPRECATED:
43+
ifnameinconst._DEPRECATED:
4344
warnings.warn(
4445
f"\nDirect access to 'gitlab.{name}' is deprecated and will be "
4546
f"removed in a future major python-gitlab release. Please "
4647
f"use 'gitlab.const.{name}' instead.",
4748
DeprecationWarning,
4849
)
49-
returngetattr(gitlab.const,name)
50+
returngetattr(const,name)
5051
raiseAttributeError(f"module{__name__} has no attribute{name}")

‎gitlab/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
importgitlab.cli
1+
from .importcli
22

33
if__name__=="__main__":
4-
gitlab.cli.main()
4+
cli.main()

‎gitlab/base.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
fromtypesimportModuleType
2121
fromtypingimportAny,Dict,Iterable,NamedTuple,Optional,Tuple,Type
2222

23-
importgitlab
24-
fromgitlabimporttypesasg_types
25-
fromgitlab.exceptionsimportGitlabParsingError
26-
2723
from .clientimportGitlab,GitlabList
24+
from .exceptionsimportGitlabParsingError
25+
from .typesimportGitlabAttribute
26+
from .versionimport__version__
2827

2928
__all__= [
3029
"RequiredOptional",
@@ -35,7 +34,7 @@
3534

3635

3736
_URL_ATTRIBUTE_ERROR= (
38-
f"https://python-gitlab.readthedocs.io/en/{gitlab.__version__}/"
37+
f"https://python-gitlab.readthedocs.io/en/{__version__}/"
3938
f"faq.html#attribute-error-list"
4039
)
4140

@@ -317,7 +316,7 @@ class RESTManager(object):
317316
_path:Optional[str]=None
318317
_obj_cls:Optional[Type[RESTObject]]=None
319318
_from_parent_attrs:Dict[str,Any]= {}
320-
_types:Dict[str,Type[g_types.GitlabAttribute]]= {}
319+
_types:Dict[str,Type[GitlabAttribute]]= {}
321320

322321
_computed_path:Optional[str]
323322
_parent:Optional[RESTObject]

‎gitlab/cli.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727

2828
fromrequests.structuresimportCaseInsensitiveDict
2929

30-
importgitlab.config
31-
fromgitlab.baseimportRESTObject
30+
from .import__version__
31+
from .importconfigasgl_config
32+
from .baseimportRESTObject
33+
from .clientimportGitlab
3234

3335
# This regex is based on:
3436
# https://github.com/jpvanhal/inflection/blob/master/inflection/__init__.py
@@ -246,10 +248,10 @@ def _get_base_parser(add_help: bool = True) -> argparse.ArgumentParser:
246248
def_get_parser()->argparse.ArgumentParser:
247249
# NOTE: We must delay import of gitlab.v4.cli until now or
248250
# otherwise it will cause circular import errors
249-
importgitlab.v4.cli
251+
from.v4importcli
250252

251253
parser=_get_base_parser()
252-
returngitlab.v4.cli.extend_parser(parser)
254+
returncli.extend_parser(parser)
253255

254256

255257
def_parse_value(v:Any)->Any:
@@ -279,7 +281,7 @@ def docs() -> argparse.ArgumentParser: # pragma: no cover
279281

280282
defmain()->None:
281283
if"--version"insys.argv:
282-
print(gitlab.__version__)
284+
print(__version__)
283285
sys.exit(0)
284286

285287
parser=_get_base_parser(add_help=False)
@@ -289,8 +291,8 @@ def main() -> None:
289291
# any subparser setup
290292
(options,_)=parser.parse_known_args(sys.argv)
291293
try:
292-
config=gitlab.config.GitlabConfigParser(options.gitlab,options.config_file)
293-
exceptgitlab.config.ConfigErrorase:
294+
config=gl_config.GitlabConfigParser(options.gitlab,options.config_file)
295+
exceptgl_config.ConfigErrorase:
294296
if"--help"insys.argvor"-h"insys.argv:
295297
parser.print_help()
296298
sys.exit(0)
@@ -346,7 +348,7 @@ def main() -> None:
346348
args_dict= {k:_parse_value(v)fork,vinargs_dict.items()ifvisnotNone}
347349

348350
try:
349-
gl=gitlab.Gitlab.merge_config(vars(options),gitlab_id,config_files)
351+
gl=Gitlab.merge_config(vars(options),gitlab_id,config_files)
350352
ifgl.private_tokenorgl.oauth_token:
351353
gl.auth()
352354
exceptExceptionase:
@@ -355,4 +357,6 @@ def main() -> None:
355357
ifdebug:
356358
gl.enable_debug()
357359

358-
gitlab.v4.cli.run(gl,what,action,args_dict,verbose,output,fields)
360+
from .v4importcli
361+
362+
cli.run(gl,what,action,args_dict,verbose,output,fields)

‎gitlab/client.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
importrequests.utils
2525
fromrequests_toolbelt.multipart.encoderimportMultipartEncoder# type: ignore
2626

27-
importgitlab.config
28-
importgitlab.const
29-
importgitlab.exceptions
30-
fromgitlabimportutils
27+
from .importconfigasgl_config
28+
from .importconst,exceptions,utils
3129

3230
REDIRECT_MSG= (
3331
"python-gitlab detected a {status_code} ({reason!r}) redirection. You must update "
@@ -73,7 +71,7 @@ def __init__(
7371
per_page:Optional[int]=None,
7472
pagination:Optional[str]=None,
7573
order_by:Optional[str]=None,
76-
user_agent:str=gitlab.const.USER_AGENT,
74+
user_agent:str=const.USER_AGENT,
7775
retry_transient_errors:bool=False,
7876
)->None:
7977

@@ -110,9 +108,9 @@ def __init__(
110108
raiseModuleNotFoundError(name=f"gitlab.v{self._api_version}.objects")
111109
# NOTE: We must delay import of gitlab.v4.objects until now or
112110
# otherwise it will cause circular import errors
113-
importgitlab.v4.objects
111+
from.v4importobjectsasv4_objects
114112

115-
objects=gitlab.v4.objects
113+
objects=v4_objects
116114
self._objects=objects
117115

118116
self.broadcastmessages=objects.BroadcastMessageManager(self)
@@ -202,9 +200,9 @@ def __setstate__(self, state: Dict[str, Any]) -> None:
202200
raiseModuleNotFoundError(name=f"gitlab.v{self._api_version}.objects")
203201
# NOTE: We must delay import of gitlab.v4.objects until now or
204202
# otherwise it will cause circular import errors
205-
importgitlab.v4.objects
203+
from.v4importobjectsasv4_objects
206204

207-
self._objects=gitlab.v4.objects
205+
self._objects=v4_objects
208206

209207
@property
210208
defurl(self)->str:
@@ -237,7 +235,7 @@ def from_config(
237235
Raises:
238236
gitlab.config.GitlabDataError: If the configuration is not correct.
239237
"""
240-
config=gitlab.config.GitlabConfigParser(
238+
config=gl_config.GitlabConfigParser(
241239
gitlab_id=gitlab_id,config_files=config_files
242240
)
243241
returncls(
@@ -287,14 +285,14 @@ def merge_config(
287285
Raises:
288286
gitlab.config.GitlabDataError: If the configuration is not correct.
289287
"""
290-
config=gitlab.config.GitlabConfigParser(
288+
config=gl_config.GitlabConfigParser(
291289
gitlab_id=gitlab_id,config_files=config_files
292290
)
293291
url= (
294292
options.get("server_url")
295293
orconfig.url
296294
oros.getenv("CI_SERVER_URL")
297-
orgitlab.const.DEFAULT_URL
295+
orconst.DEFAULT_URL
298296
)
299297
private_token,oauth_token,job_token=cls._merge_auth(options,config)
300298

@@ -313,7 +311,7 @@ def merge_config(
313311
)
314312

315313
@staticmethod
316-
def_merge_auth(options:dict,config:gitlab.config.GitlabConfigParser)->Tuple:
314+
def_merge_auth(options:dict,config:gl_config.GitlabConfigParser)->Tuple:
317315
"""
318316
Return a tuple where at most one of 3 token types ever has a value.
319317
Since multiple types of tokens may be present in the environment,
@@ -371,7 +369,7 @@ def version(self) -> Tuple[str, str]:
371369

372370
returncast(str,self._server_version),cast(str,self._server_revision)
373371

374-
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabVerifyError)
372+
@exceptions.on_http_error(exceptions.GitlabVerifyError)
375373
deflint(self,content:str,**kwargs:Any)->Tuple[bool,List[str]]:
376374
"""Validate a gitlab CI configuration.
377375
@@ -392,7 +390,7 @@ def lint(self, content: str, **kwargs: Any) -> Tuple[bool, List[str]]:
392390
assertnotisinstance(data,requests.Response)
393391
return (data["status"]=="valid",data["errors"])
394392

395-
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabMarkdownError)
393+
@exceptions.on_http_error(exceptions.GitlabMarkdownError)
396394
defmarkdown(
397395
self,text:str,gfm:bool=False,project:Optional[str]=None,**kwargs:Any
398396
)->str:
@@ -419,7 +417,7 @@ def markdown(
419417
assertnotisinstance(data,requests.Response)
420418
returndata["html"]
421419

422-
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabLicenseError)
420+
@exceptions.on_http_error(exceptions.GitlabLicenseError)
423421
defget_license(self,**kwargs:Any)->Dict[str,Any]:
424422
"""Retrieve information about the current license.
425423
@@ -438,7 +436,7 @@ def get_license(self, **kwargs: Any) -> Dict[str, Any]:
438436
returnresult
439437
return {}
440438

441-
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabLicenseError)
439+
@exceptions.on_http_error(exceptions.GitlabLicenseError)
442440
defset_license(self,license:str,**kwargs:Any)->Dict[str,Any]:
443441
"""Add a new license.
444442
@@ -529,7 +527,7 @@ def _get_base_url(self, url: Optional[str] = None) -> str:
529527
The base URL
530528
"""
531529
ifnoturl:
532-
returngitlab.const.DEFAULT_URL
530+
returnconst.DEFAULT_URL
533531

534532
returnurl.rstrip("/")
535533

@@ -563,7 +561,7 @@ def _check_redirects(self, result: requests.Response) -> None:
563561
ifitem.request.method=="GET":
564562
continue
565563
target=item.headers.get("location")
566-
raisegitlab.exceptions.RedirectError(
564+
raiseexceptions.RedirectError(
567565
REDIRECT_MSG.format(
568566
status_code=item.status_code,
569567
reason=item.reason,
@@ -718,13 +716,13 @@ def http_request(
718716
pass
719717

720718
ifresult.status_code==401:
721-
raisegitlab.exceptions.GitlabAuthenticationError(
719+
raiseexceptions.GitlabAuthenticationError(
722720
response_code=result.status_code,
723721
error_message=error_message,
724722
response_body=result.content,
725723
)
726724

727-
raisegitlab.exceptions.GitlabHttpError(
725+
raiseexceptions.GitlabHttpError(
728726
response_code=result.status_code,
729727
error_message=error_message,
730728
response_body=result.content,
@@ -770,7 +768,7 @@ def http_get(
770768
try:
771769
returnresult.json()
772770
exceptExceptionase:
773-
raisegitlab.exceptions.GitlabParsingError(
771+
raiseexceptions.GitlabParsingError(
774772
error_message="Failed to parse the server message"
775773
)frome
776774
else:
@@ -867,7 +865,7 @@ def http_post(
867865
ifresult.headers.get("Content-Type",None)=="application/json":
868866
returnresult.json()
869867
exceptExceptionase:
870-
raisegitlab.exceptions.GitlabParsingError(
868+
raiseexceptions.GitlabParsingError(
871869
error_message="Failed to parse the server message"
872870
)frome
873871
returnresult
@@ -915,7 +913,7 @@ def http_put(
915913
try:
916914
returnresult.json()
917915
exceptExceptionase:
918-
raisegitlab.exceptions.GitlabParsingError(
916+
raiseexceptions.GitlabParsingError(
919917
error_message="Failed to parse the server message"
920918
)frome
921919

@@ -935,7 +933,7 @@ def http_delete(self, path: str, **kwargs: Any) -> requests.Response:
935933
"""
936934
returnself.http_request("delete",path,**kwargs)
937935

938-
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabSearchError)
936+
@exceptions.on_http_error(exceptions.GitlabSearchError)
939937
defsearch(
940938
self,scope:str,search:str,**kwargs:Any
941939
)->Union["GitlabList",List[Dict[str,Any]]]:
@@ -1009,7 +1007,7 @@ def _query(
10091007
try:
10101008
self._data:List[Dict[str,Any]]=result.json()
10111009
exceptExceptionase:
1012-
raisegitlab.exceptions.GitlabParsingError(
1010+
raiseexceptions.GitlabParsingError(
10131011
error_message="Failed to parse the server message"
10141012
)frome
10151013

‎gitlab/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
frompathlibimportPath
2424
fromtypingimportList,Optional,Union
2525

26-
fromgitlab.constimportUSER_AGENT
26+
from .constimportUSER_AGENT
2727

2828
_DEFAULT_FILES:List[str]= [
2929
"/etc/python-gitlab.cfg",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp