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

Commitc873c92

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 parenta588390 commitc873c92

File tree

69 files changed

+298
-316
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

+298
-316
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
@@ -26,8 +26,10 @@
2626

2727
fromrequests.structuresimportCaseInsensitiveDict
2828

29-
importgitlab.config
30-
fromgitlab.baseimportRESTObject
29+
from .import__version__
30+
from .importconfigasgl_config
31+
from .baseimportRESTObject
32+
from .clientimportGitlab
3133

3234
# This regex is based on:
3335
# https://github.com/jpvanhal/inflection/blob/master/inflection/__init__.py
@@ -158,10 +160,10 @@ def _get_base_parser(add_help: bool = True) -> argparse.ArgumentParser:
158160
def_get_parser()->argparse.ArgumentParser:
159161
# NOTE: We must delay import of gitlab.v4.cli until now or
160162
# otherwise it will cause circular import errors
161-
importgitlab.v4.cli
163+
from.v4importcli
162164

163165
parser=_get_base_parser()
164-
returngitlab.v4.cli.extend_parser(parser)
166+
returncli.extend_parser(parser)
165167

166168

167169
def_parse_value(v:Any)->Any:
@@ -191,7 +193,7 @@ def docs() -> argparse.ArgumentParser: # pragma: no cover
191193

192194
defmain()->None:
193195
if"--version"insys.argv:
194-
print(gitlab.__version__)
196+
print(__version__)
195197
sys.exit(0)
196198

197199
parser=_get_base_parser(add_help=False)
@@ -201,8 +203,8 @@ def main() -> None:
201203
# any subparser setup
202204
(options,_)=parser.parse_known_args(sys.argv)
203205
try:
204-
config=gitlab.config.GitlabConfigParser(options.gitlab,options.config_file)
205-
exceptgitlab.config.ConfigErrorase:
206+
config=gl_config.GitlabConfigParser(options.gitlab,options.config_file)
207+
exceptgl_config.ConfigErrorase:
206208
if"--help"insys.argvor"-h"insys.argv:
207209
parser.print_help()
208210
sys.exit(0)
@@ -248,7 +250,7 @@ def main() -> None:
248250
args_dict= {k:_parse_value(v)fork,vinargs_dict.items()ifvisnotNone}
249251

250252
try:
251-
gl=gitlab.Gitlab.from_config(gitlab_id,config_files)
253+
gl=Gitlab.from_config(gitlab_id,config_files)
252254
ifgl.private_tokenorgl.oauth_tokenorgl.job_token:
253255
gl.auth()
254256
exceptExceptionase:
@@ -257,4 +259,6 @@ def main() -> None:
257259
ifdebug:
258260
gl.enable_debug()
259261

260-
gitlab.v4.cli.run(gl,what,action,args_dict,verbose,output,fields)
262+
from .v4importcli
263+
264+
cli.run(gl,what,action,args_dict,verbose,output,fields)

‎gitlab/client.py

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

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

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

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

114-
objects=gitlab.v4.objects
112+
objects=v4_objects
115113
self._objects=objects
116114

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

206-
self._objects=gitlab.v4.objects
204+
self._objects=v4_objects
207205

208206
@property
209207
defurl(self)->str:
@@ -236,7 +234,7 @@ def from_config(
236234
Raises:
237235
gitlab.config.GitlabDataError: If the configuration is not correct.
238236
"""
239-
config=gitlab.config.GitlabConfigParser(
237+
config=gl_config.GitlabConfigParser(
240238
gitlab_id=gitlab_id,config_files=config_files
241239
)
242240
returncls(
@@ -289,7 +287,7 @@ def version(self) -> Tuple[str, str]:
289287

290288
returncast(str,self._server_version),cast(str,self._server_revision)
291289

292-
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabVerifyError)
290+
@exceptions.on_http_error(exceptions.GitlabVerifyError)
293291
deflint(self,content:str,**kwargs:Any)->Tuple[bool,List[str]]:
294292
"""Validate a gitlab CI configuration.
295293
@@ -310,7 +308,7 @@ def lint(self, content: str, **kwargs: Any) -> Tuple[bool, List[str]]:
310308
assertnotisinstance(data,requests.Response)
311309
return (data["status"]=="valid",data["errors"])
312310

313-
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabMarkdownError)
311+
@exceptions.on_http_error(exceptions.GitlabMarkdownError)
314312
defmarkdown(
315313
self,text:str,gfm:bool=False,project:Optional[str]=None,**kwargs:Any
316314
)->str:
@@ -337,7 +335,7 @@ def markdown(
337335
assertnotisinstance(data,requests.Response)
338336
returndata["html"]
339337

340-
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabLicenseError)
338+
@exceptions.on_http_error(exceptions.GitlabLicenseError)
341339
defget_license(self,**kwargs:Any)->Dict[str,Any]:
342340
"""Retrieve information about the current license.
343341
@@ -356,7 +354,7 @@ def get_license(self, **kwargs: Any) -> Dict[str, Any]:
356354
returnresult
357355
return {}
358356

359-
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabLicenseError)
357+
@exceptions.on_http_error(exceptions.GitlabLicenseError)
360358
defset_license(self,license:str,**kwargs:Any)->Dict[str,Any]:
361359
"""Add a new license.
362360
@@ -447,7 +445,7 @@ def _get_base_url(self, url: Optional[str] = None) -> str:
447445
The base URL
448446
"""
449447
ifnoturl:
450-
returngitlab.const.DEFAULT_URL
448+
returnconst.DEFAULT_URL
451449

452450
returnurl.rstrip("/")
453451

@@ -481,7 +479,7 @@ def _check_redirects(self, result: requests.Response) -> None:
481479
ifitem.request.method=="GET":
482480
continue
483481
target=item.headers.get("location")
484-
raisegitlab.exceptions.RedirectError(
482+
raiseexceptions.RedirectError(
485483
REDIRECT_MSG.format(
486484
status_code=item.status_code,
487485
reason=item.reason,
@@ -636,13 +634,13 @@ def http_request(
636634
pass
637635

638636
ifresult.status_code==401:
639-
raisegitlab.exceptions.GitlabAuthenticationError(
637+
raiseexceptions.GitlabAuthenticationError(
640638
response_code=result.status_code,
641639
error_message=error_message,
642640
response_body=result.content,
643641
)
644642

645-
raisegitlab.exceptions.GitlabHttpError(
643+
raiseexceptions.GitlabHttpError(
646644
response_code=result.status_code,
647645
error_message=error_message,
648646
response_body=result.content,
@@ -688,7 +686,7 @@ def http_get(
688686
try:
689687
returnresult.json()
690688
exceptExceptionase:
691-
raisegitlab.exceptions.GitlabParsingError(
689+
raiseexceptions.GitlabParsingError(
692690
error_message="Failed to parse the server message"
693691
)frome
694692
else:
@@ -785,7 +783,7 @@ def http_post(
785783
ifresult.headers.get("Content-Type",None)=="application/json":
786784
returnresult.json()
787785
exceptExceptionase:
788-
raisegitlab.exceptions.GitlabParsingError(
786+
raiseexceptions.GitlabParsingError(
789787
error_message="Failed to parse the server message"
790788
)frome
791789
returnresult
@@ -833,7 +831,7 @@ def http_put(
833831
try:
834832
returnresult.json()
835833
exceptExceptionase:
836-
raisegitlab.exceptions.GitlabParsingError(
834+
raiseexceptions.GitlabParsingError(
837835
error_message="Failed to parse the server message"
838836
)frome
839837

@@ -853,7 +851,7 @@ def http_delete(self, path: str, **kwargs: Any) -> requests.Response:
853851
"""
854852
returnself.http_request("delete",path,**kwargs)
855853

856-
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabSearchError)
854+
@exceptions.on_http_error(exceptions.GitlabSearchError)
857855
defsearch(
858856
self,scope:str,search:str,**kwargs:Any
859857
)->Union["GitlabList",List[Dict[str,Any]]]:
@@ -929,7 +927,7 @@ def _query(
929927
try:
930928
self._data:List[Dict[str,Any]]=result.json()
931929
exceptExceptionase:
932-
raisegitlab.exceptions.GitlabParsingError(
930+
raiseexceptions.GitlabParsingError(
933931
error_message="Failed to parse the server message"
934932
)frome
935933

‎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.constimportDEFAULT_URL,USER_AGENT
26+
from .constimportDEFAULT_URL,USER_AGENT
2727

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp