Coverage for src/hatch_ci/version_hook.py: 0%

1 from hatchling.version.source.plugin.interface import VersionSourceInterface

2

3 from .common import PLUGIN_NAME

4

5

6 class ValidationError(Exception):

7 pass

8

9

10 class CIVersionSource(VersionSourceInterface):

11 PLUGIN_NAME = PLUGIN_NAME

12

13 def __init__(self, *args, **kwargs):

14 super().__init__(*args, **kwargs)

15

16 #

17 # @property

18 # def config_tag_pattern(self):

19 # if self.__config_tag_pattern is None:

20 # tag_pattern = self.config.get('tag-pattern', '')

21 # if not isinstance(tag_pattern, str):

22 # raise TypeError('option `tag-pattern` must be a string')

23 #

24 # self.__config_tag_pattern = tag_pattern

25 #

26 # return self.__config_tag_pattern

27 #

28 # @property

29 # def config_fallback_version(self):

30 # if self.__config_fallback_version is None:

31 # fallback_version = self.config.get('fallback-version', '')

32 # if not isinstance(fallback_version, str):

33 # raise TypeError('option `fallback-version` must be a string')

34 #

35 # self.__config_fallback_version = fallback_version

36 #

37 # return self.__config_fallback_version

38 #

39 # @property

40 # def config_raw_options(self):

41 # if self.__config_raw_options is None:

42 # raw_options = self.config.get('raw-options', {})

43 # if not isinstance(raw_options, dict):

44 # raise TypeError('option `raw-options` must be a table')

45 #

46 # self.__config_raw_options = raw_options

47 #

48 # return self.__config_raw_options

49 #

50 # def construct_setuptools_scm_config(self):

51 # from copy import deepcopy

52 #

53 # config = deepcopy(self.config_raw_options)

54 # config.setdefault('root', self.root)

55 #

56 # config.setdefault('tag_regex', self.config_tag_pattern)

57 #

58 # # Only set for non-empty strings

59 # if self.config_fallback_version:

60 # config['fallback_version'] = self.config_fallback_version

61 #

62 # # Writing only occurs when the build hook is enabled

63 # config.pop('write_to', None)

64 # config.pop('write_to_template', None)

65 # return config

66

67 def get_version_data(self):

68 from os import getenv

69 from pathlib import Path

70

71 from hatch_ci import tools

72

73 initfile = Path(self.root) / self.config["version-file"]

74 if not initfile.exists():

75 raise ValidationError(

76 f"no 'version-file' key for plugin {self.PLUGIN_NAME}"

77 )

78 version = tools.update_version(initfile, getenv("GITHUB_DUMP"), abort=False)

79 return {"version": version}