Coverage for src/ezcompiler/adapters/publisher_factory.py: 100.00%

18 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-16 16:37 +0000

1# /////////////////////////////////////////////////////////////// 

2# PUBLISHER_FACTORY - Factory for creating publisher instances 

3# Project: ezcompiler 

4# /////////////////////////////////////////////////////////////// 

5 

6""" 

7Publisher factory - Factory for creating release publisher instances. 

8 

9Callers go through this factory rather than instantiating concrete 

10publishers, which stay private to the adapters package. 

11""" 

12 

13from __future__ import annotations 

14 

15# /////////////////////////////////////////////////////////////// 

16# IMPORTS 

17# /////////////////////////////////////////////////////////////// 

18# Standard library imports 

19from typing import Any 

20 

21# Local imports 

22from .._types import PublisherPort 

23from ..shared.exceptions import PublisherTypeError 

24from ._github_publisher import GitHubPublisher 

25 

26# /////////////////////////////////////////////////////////////// 

27# CONSTANTS 

28# /////////////////////////////////////////////////////////////// 

29 

30# GitLab is deliberately absent: the `glab` flags are not verified 

31# first-hand. An explicit refusal beats an adapter that guesses. 

32_SUPPORTED: tuple[str, ...] = ("github",) 

33 

34# /////////////////////////////////////////////////////////////// 

35# CLASSES 

36# /////////////////////////////////////////////////////////////// 

37 

38 

39class PublisherFactory: 

40 """ 

41 Factory class for creating release publisher instances. 

42 

43 Example: 

44 >>> publisher = PublisherFactory.create_publisher("github", {"repo": "o/r"}) 

45 >>> PublisherFactory.get_supported_types() 

46 ['github'] 

47 """ 

48 

49 # //////////////////////////////////////////////// 

50 # FACTORY METHODS 

51 # //////////////////////////////////////////////// 

52 

53 @staticmethod 

54 def create_publisher( 

55 publish_type: str, config: dict[str, Any] | None = None 

56 ) -> PublisherPort: 

57 """ 

58 Create a publisher instance based on the specified type. 

59 

60 Args: 

61 publish_type: Platform name ("github"). 

62 config: Configuration dictionary for the publisher (default: None). 

63 

64 Returns: 

65 PublisherPort: Configured publisher instance (satisfies the Port). 

66 

67 Raises: 

68 PublisherTypeError: If the platform is not supported. 

69 """ 

70 publish_type = publish_type.lower() 

71 

72 if publish_type == "github": 

73 return GitHubPublisher(config) 

74 

75 if publish_type == "gitlab": 

76 raise PublisherTypeError( 

77 "'gitlab' publication is not implemented yet. " 

78 "Utiliser release_destination='github', ou une destination " 

79 "de fichiers ('disk', 'server', 'r2')." 

80 ) 

81 

82 raise PublisherTypeError( 

83 f"Unsupported publication platform: '{publish_type}'. " 

84 f"Supported: {', '.join(_SUPPORTED)}." 

85 ) 

86 

87 @staticmethod 

88 def get_supported_types() -> list[str]: 

89 """ 

90 Get the list of supported publication platforms. 

91 

92 Returns: 

93 list[str]: Supported platform names. 

94 """ 

95 return list(_SUPPORTED)