qontract-reconcile 0.10.1rc1202__py3-none-any.whl → 0.10.2.dev1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. qontract_reconcile-0.10.2.dev1.dist-info/METADATA +500 -0
  2. {qontract_reconcile-0.10.1rc1202.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/RECORD +12 -130
  3. {qontract_reconcile-0.10.1rc1202.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/WHEEL +1 -2
  4. {qontract_reconcile-0.10.1rc1202.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/entry_points.txt +1 -0
  5. reconcile/aws_account_manager/README.md +5 -0
  6. reconcile/change_owners/README.md +34 -0
  7. reconcile/glitchtip/README.md +150 -0
  8. reconcile/gql_definitions/introspection.json +51176 -0
  9. reconcile/run_integration.py +293 -0
  10. reconcile/utils/binary.py +2 -2
  11. reconcile/utils/mr/README.md +198 -0
  12. reconcile/utils/oc_map.py +2 -2
  13. tools/qontract_cli.py +0 -0
  14. qontract_reconcile-0.10.1rc1202.dist-info/METADATA +0 -64
  15. qontract_reconcile-0.10.1rc1202.dist-info/top_level.txt +0 -3
  16. reconcile/test/__init__.py +0 -0
  17. reconcile/test/conftest.py +0 -157
  18. reconcile/test/fixtures.py +0 -24
  19. reconcile/test/saas_auto_promotions_manager/__init__.py +0 -0
  20. reconcile/test/saas_auto_promotions_manager/conftest.py +0 -170
  21. reconcile/test/saas_auto_promotions_manager/merge_request_manager/__init__.py +0 -0
  22. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/__init__.py +0 -0
  23. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/conftest.py +0 -115
  24. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/data_keys.py +0 -19
  25. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_desired_state.py +0 -66
  26. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_merge_request_manager.py +0 -86
  27. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_mr_parser.py +0 -352
  28. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_reconciler.py +0 -494
  29. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/__init__.py +0 -0
  30. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/conftest.py +0 -25
  31. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_multiple_namespaces.py +0 -37
  32. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_single_namespace.py +0 -81
  33. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_single_target.py +0 -61
  34. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_json_path_selector.py +0 -74
  35. reconcile/test/saas_auto_promotions_manager/test_integration_test.py +0 -52
  36. reconcile/test/saas_auto_promotions_manager/utils/__init__.py +0 -0
  37. reconcile/test/test_acs_notifiers.py +0 -393
  38. reconcile/test/test_acs_policies.py +0 -497
  39. reconcile/test/test_acs_rbac.py +0 -865
  40. reconcile/test/test_aggregated_list.py +0 -237
  41. reconcile/test/test_amtool.py +0 -37
  42. reconcile/test/test_aws_ami_cleanup.py +0 -230
  43. reconcile/test/test_aws_ami_share.py +0 -68
  44. reconcile/test/test_aws_cloudwatch_log_retention.py +0 -434
  45. reconcile/test/test_aws_iam_keys.py +0 -70
  46. reconcile/test/test_aws_iam_password_reset.py +0 -35
  47. reconcile/test/test_aws_support_cases_sos.py +0 -23
  48. reconcile/test/test_checkpoint.py +0 -178
  49. reconcile/test/test_cli.py +0 -41
  50. reconcile/test/test_closedbox_endpoint_monitoring.py +0 -207
  51. reconcile/test/test_dashdotdb_dora.py +0 -245
  52. reconcile/test/test_database_access_manager.py +0 -660
  53. reconcile/test/test_deadmanssnitch.py +0 -290
  54. reconcile/test/test_gabi_authorized_users.py +0 -72
  55. reconcile/test/test_gcr_mirror.py +0 -14
  56. reconcile/test/test_github_org.py +0 -156
  57. reconcile/test/test_github_repo_invites.py +0 -119
  58. reconcile/test/test_gitlab_housekeeping.py +0 -333
  59. reconcile/test/test_gitlab_labeler.py +0 -126
  60. reconcile/test/test_gitlab_members.py +0 -219
  61. reconcile/test/test_gitlab_permissions.py +0 -164
  62. reconcile/test/test_instrumented_wrappers.py +0 -18
  63. reconcile/test/test_integrations_manager.py +0 -1252
  64. reconcile/test/test_jenkins_worker_fleets.py +0 -57
  65. reconcile/test/test_jira_permissions_validator.py +0 -519
  66. reconcile/test/test_jump_host.py +0 -114
  67. reconcile/test/test_ldap_users.py +0 -125
  68. reconcile/test/test_make.py +0 -28
  69. reconcile/test/test_ocm_additional_routers.py +0 -133
  70. reconcile/test/test_ocm_clusters.py +0 -798
  71. reconcile/test/test_ocm_clusters_manifest_updates.py +0 -87
  72. reconcile/test/test_ocm_machine_pools.py +0 -1103
  73. reconcile/test/test_ocm_update_recommended_version.py +0 -145
  74. reconcile/test/test_ocm_upgrade_scheduler_org_updater.py +0 -125
  75. reconcile/test/test_openshift_base.py +0 -1269
  76. reconcile/test/test_openshift_cluster_bots.py +0 -240
  77. reconcile/test/test_openshift_namespace_labels.py +0 -344
  78. reconcile/test/test_openshift_namespaces.py +0 -256
  79. reconcile/test/test_openshift_resource.py +0 -443
  80. reconcile/test/test_openshift_resources_base.py +0 -478
  81. reconcile/test/test_openshift_saas_deploy.py +0 -188
  82. reconcile/test/test_openshift_saas_deploy_change_tester.py +0 -308
  83. reconcile/test/test_openshift_saas_deploy_trigger_cleaner.py +0 -65
  84. reconcile/test/test_openshift_serviceaccount_tokens.py +0 -282
  85. reconcile/test/test_openshift_tekton_resources.py +0 -265
  86. reconcile/test/test_openshift_upgrade_watcher.py +0 -223
  87. reconcile/test/test_prometheus_rules_tester.py +0 -151
  88. reconcile/test/test_quay_membership.py +0 -86
  89. reconcile/test/test_quay_mirror.py +0 -172
  90. reconcile/test/test_quay_mirror_org.py +0 -82
  91. reconcile/test/test_quay_repos.py +0 -59
  92. reconcile/test/test_queries.py +0 -53
  93. reconcile/test/test_repo_owners.py +0 -47
  94. reconcile/test/test_requests_sender.py +0 -139
  95. reconcile/test/test_saasherder.py +0 -1611
  96. reconcile/test/test_saasherder_allowed_secret_paths.py +0 -125
  97. reconcile/test/test_secret_reader.py +0 -153
  98. reconcile/test/test_slack_base.py +0 -183
  99. reconcile/test/test_slack_usergroups.py +0 -785
  100. reconcile/test/test_sql_query.py +0 -316
  101. reconcile/test/test_status_board.py +0 -258
  102. reconcile/test/test_terraform_aws_route53.py +0 -29
  103. reconcile/test/test_terraform_cloudflare_dns.py +0 -117
  104. reconcile/test/test_terraform_cloudflare_resources.py +0 -408
  105. reconcile/test/test_terraform_cloudflare_users.py +0 -747
  106. reconcile/test/test_terraform_repo.py +0 -440
  107. reconcile/test/test_terraform_resources.py +0 -519
  108. reconcile/test/test_terraform_tgw_attachments.py +0 -1295
  109. reconcile/test/test_terraform_users.py +0 -152
  110. reconcile/test/test_terraform_vpc_peerings.py +0 -576
  111. reconcile/test/test_terraform_vpc_peerings_build_desired_state.py +0 -1434
  112. reconcile/test/test_three_way_diff_strategy.py +0 -131
  113. reconcile/test/test_utils_jinja2.py +0 -130
  114. reconcile/test/test_vault_replication.py +0 -534
  115. reconcile/test/test_vault_utils.py +0 -47
  116. reconcile/test/test_version_bump.py +0 -18
  117. reconcile/test/test_vpc_peerings_validator.py +0 -194
  118. reconcile/test/test_wrong_region.py +0 -78
  119. release/__init__.py +0 -0
  120. release/test_version.py +0 -50
  121. release/version.py +0 -104
  122. tools/cli_commands/test/__init__.py +0 -0
  123. tools/cli_commands/test/conftest.py +0 -332
  124. tools/cli_commands/test/test_aws_cost_report.py +0 -258
  125. tools/cli_commands/test/test_cost_management_api.py +0 -326
  126. tools/cli_commands/test/test_gpg_encrypt.py +0 -235
  127. tools/cli_commands/test/test_openshift_cost_optimization_report.py +0 -255
  128. tools/cli_commands/test/test_openshift_cost_report.py +0 -295
  129. tools/cli_commands/test/test_util.py +0 -70
  130. tools/test/__init__.py +0 -0
  131. tools/test/conftest.py +0 -77
  132. tools/test/test_app_interface_metrics_exporter.py +0 -48
  133. tools/test/test_erv2.py +0 -80
  134. tools/test/test_get_container_images.py +0 -230
  135. tools/test/test_qontract_cli.py +0 -197
  136. tools/test/test_saas_promotion_state.py +0 -187
  137. tools/test/test_sd_app_sre_alert_report.py +0 -74
  138. tools/test/test_sre_checkpoints.py +0 -79
@@ -1,194 +0,0 @@
1
- import pytest
2
-
3
- from reconcile.gql_definitions.vpc_peerings_validator.vpc_peerings_validator import (
4
- AWSVPCV1,
5
- ClusterNetworkV1,
6
- ClusterPeeringConnectionAccountV1,
7
- ClusterPeeringConnectionClusterAccepterV1,
8
- ClusterPeeringV1,
9
- ClusterSpecV1,
10
- ClusterV1,
11
- VpcPeeringsValidatorQueryData,
12
- )
13
- from reconcile.gql_definitions.vpc_peerings_validator.vpc_peerings_validator_peered_cluster_fragment import (
14
- ClusterSpecV1 as PeeredClusterSpec,
15
- )
16
- from reconcile.gql_definitions.vpc_peerings_validator.vpc_peerings_validator_peered_cluster_fragment import (
17
- VpcPeeringsValidatorPeeredCluster,
18
- )
19
- from reconcile.vpc_peerings_validator import (
20
- find_cidr_overlap,
21
- validate_no_cidr_overlap,
22
- validate_no_internal_to_public_peerings,
23
- validate_no_public_to_public_peerings,
24
- )
25
-
26
-
27
- @pytest.fixture
28
- def query_data_i2p() -> VpcPeeringsValidatorQueryData:
29
- return VpcPeeringsValidatorQueryData(
30
- clusters=[
31
- ClusterV1(
32
- name="cluster1",
33
- network=ClusterNetworkV1(vpc="192.168.0.0/16"),
34
- spec=ClusterSpecV1(private=True),
35
- internal=True,
36
- peering=ClusterPeeringV1(
37
- connections=[
38
- ClusterPeeringConnectionClusterAccepterV1(
39
- provider="cluster-vpc-accepter",
40
- cluster=VpcPeeringsValidatorPeeredCluster(
41
- name="cluster2",
42
- network=ClusterNetworkV1(vpc="192.168.0.0/16"),
43
- spec=PeeredClusterSpec(private=False),
44
- internal=False,
45
- ),
46
- ),
47
- ],
48
- ),
49
- ),
50
- ],
51
- )
52
-
53
-
54
- def test_validate_no_internal_to_public_peerings_invalid(
55
- query_data_i2p: VpcPeeringsValidatorQueryData,
56
- ):
57
- assert validate_no_internal_to_public_peerings(query_data_i2p) is False
58
-
59
-
60
- def test_validate_no_internal_to_public_peerings_valid_private(
61
- query_data_i2p: VpcPeeringsValidatorQueryData,
62
- ):
63
- query_data_i2p.clusters[0].peering.connections[0].cluster.spec.private = True # type: ignore[index,union-attr]
64
- assert validate_no_internal_to_public_peerings(query_data_i2p) is True
65
-
66
-
67
- def test_validate_no_internal_to_public_peerings_valid_internal(
68
- query_data_i2p: VpcPeeringsValidatorQueryData,
69
- ):
70
- assert query_data_i2p.clusters is not None
71
- query_data_i2p.clusters[0].peering.connections[0].cluster.internal = True # type: ignore[union-attr]
72
- assert validate_no_internal_to_public_peerings(query_data_i2p) is True
73
-
74
-
75
- @pytest.fixture
76
- def query_data_p2p() -> VpcPeeringsValidatorQueryData:
77
- return VpcPeeringsValidatorQueryData(
78
- clusters=[
79
- ClusterV1(
80
- name="cluster1",
81
- spec=ClusterSpecV1(private=False),
82
- network=ClusterNetworkV1(vpc="192.168.0.0/16"),
83
- internal=False,
84
- peering=ClusterPeeringV1(
85
- connections=[
86
- ClusterPeeringConnectionClusterAccepterV1(
87
- provider="cluster-vpc-accepter",
88
- cluster=VpcPeeringsValidatorPeeredCluster(
89
- name="cluster2",
90
- network=ClusterNetworkV1(vpc="192.168.0.0/16"),
91
- spec=PeeredClusterSpec(private=False),
92
- internal=False,
93
- ),
94
- ),
95
- ],
96
- ),
97
- ),
98
- ],
99
- )
100
-
101
-
102
- def test_validate_no_public_to_public_peerings_invalid(
103
- query_data_p2p: VpcPeeringsValidatorQueryData,
104
- ):
105
- assert validate_no_public_to_public_peerings(query_data_p2p) is False
106
-
107
-
108
- def test_validate_no_public_to_public_peerings_valid(
109
- query_data_p2p: VpcPeeringsValidatorQueryData,
110
- ):
111
- query_data_p2p.clusters[0].peering.connections[0].cluster.spec.private = True # type: ignore[index,union-attr]
112
- assert validate_no_public_to_public_peerings(query_data_p2p) is True
113
-
114
-
115
- def test_validate_validate_cidr_overlap():
116
- test_list = [
117
- {
118
- "provider": "cluster-self-vpc",
119
- "vpc_name": "cluster-name",
120
- "cidr_block": "10.25.0.0/16",
121
- },
122
- {
123
- "provider": "account-vpc",
124
- "vpc_name": "vpc-name-1",
125
- "cidr_block": "10.18.0.0/18",
126
- },
127
- {
128
- "provider": "account-vpc",
129
- "vpc_name": "vpc-name-2",
130
- "cidr_block": "10.18.0.0/18",
131
- },
132
- ]
133
- cluster_name = "cluster-name"
134
- assert find_cidr_overlap(cluster_name, test_list) is True
135
-
136
-
137
- def test_validate_validate_no_cidr_overlap():
138
- test_list = [
139
- {
140
- "provider": "cluster-self-vpc",
141
- "vpc_name": "cluster-name",
142
- "cidr_block": "10.25.0.0/16",
143
- },
144
- {
145
- "provider": "account-vpc",
146
- "vpc_name": "vpc-name-1",
147
- "cidr_block": "10.18.0.0/18",
148
- },
149
- {
150
- "provider": "account-vpc",
151
- "vpc_name": "vpc-name-2",
152
- "cidr_block": "10.19.0.0/18",
153
- },
154
- ]
155
- cluster_name = "cluster-name"
156
- assert find_cidr_overlap(cluster_name, test_list) is False
157
-
158
-
159
- @pytest.fixture
160
- def query_data_vpc_cidr_overlap() -> VpcPeeringsValidatorQueryData:
161
- return VpcPeeringsValidatorQueryData(
162
- clusters=[
163
- ClusterV1(
164
- name="clustertest",
165
- network=ClusterNetworkV1(vpc="10.20.0.0/20"),
166
- spec=ClusterSpecV1(private=True),
167
- internal=True,
168
- peering=ClusterPeeringV1(
169
- connections=[
170
- ClusterPeeringConnectionAccountV1(
171
- provider="account-vpc",
172
- vpc=AWSVPCV1(
173
- cidr_block="192.168.1.0/24",
174
- name="vpc1",
175
- ),
176
- ),
177
- ClusterPeeringConnectionAccountV1(
178
- provider="account-vpc",
179
- vpc=AWSVPCV1(
180
- cidr_block="192.168.1.0/24",
181
- name="vpc2",
182
- ),
183
- ),
184
- ]
185
- ),
186
- ),
187
- ]
188
- )
189
-
190
-
191
- def test_create_dict_for_validate_no_cidr_overlap(
192
- query_data_vpc_cidr_overlap: VpcPeeringsValidatorQueryData,
193
- ):
194
- assert validate_no_cidr_overlap(query_data_vpc_cidr_overlap) is False
@@ -1,78 +0,0 @@
1
- import pytest
2
-
3
- from reconcile.utils.aws_api import AWSApi
4
- from reconcile.utils.terrascript_aws_client import TerrascriptClient
5
-
6
-
7
- @pytest.fixture
8
- def default_region():
9
- return "default-region"
10
-
11
-
12
- @pytest.fixture
13
- def tf_bucket_region():
14
- return "tf-bucket-region"
15
-
16
-
17
- @pytest.fixture
18
- def accounts(default_region):
19
- return [
20
- {
21
- "name": "some-account",
22
- "automationToken": {
23
- "path": "path",
24
- },
25
- "resourcesDefaultRegion": default_region,
26
- "supportedDeploymentRegions": [default_region],
27
- "providerVersion": "1.2.3",
28
- "uid": "123",
29
- "terraformState": {},
30
- }
31
- ]
32
-
33
-
34
- @pytest.fixture
35
- def secret(tf_bucket_region):
36
- return {
37
- "aws_access_key_id": "key_id",
38
- "aws_secret_access_key": "access_key",
39
- "region": tf_bucket_region,
40
- "bucket": "tf-bucket-name",
41
- "_key": "tf_key.tfstate",
42
- }
43
-
44
-
45
- @pytest.fixture
46
- def aws_api(accounts, secret, mocker):
47
- mock_secret_reader = mocker.patch(
48
- "reconcile.utils.aws_api.SecretReader", autospec=True
49
- )
50
- mock_secret_reader.return_value.read_all.return_value = secret
51
- return AWSApi(1, accounts, init_users=False)
52
-
53
-
54
- @pytest.fixture
55
- def terrascript(accounts, secret, mocker):
56
- mock_secret_reader = mocker.patch(
57
- "reconcile.utils.terrascript_aws_client.SecretReader", autospec=True
58
- )
59
- mock_secret_reader.return_value.read_all.return_value = secret
60
- return TerrascriptClient("", "", 1, accounts)
61
-
62
-
63
- def test_wrong_region_aws_api(aws_api, accounts, default_region):
64
- for a in accounts:
65
- assert aws_api.sessions[a["name"]].region_name == default_region
66
-
67
-
68
- def test_wrong_region_terrascript(terrascript, accounts, tf_bucket_region):
69
- for a in accounts:
70
- assert terrascript.configs[a["name"]]["region"] == tf_bucket_region
71
-
72
-
73
- def test_wrong_region_both(
74
- aws_api, terrascript, accounts, default_region, tf_bucket_region
75
- ):
76
- for a in accounts:
77
- assert aws_api.sessions[a["name"]].region_name == default_region
78
- assert terrascript.configs[a["name"]]["region"] == tf_bucket_region
release/__init__.py DELETED
File without changes
release/test_version.py DELETED
@@ -1,50 +0,0 @@
1
- import packaging.version as pep440
2
-
3
- from reconcile.utils.semver_helper import parse_semver
4
- from release import version
5
-
6
-
7
- def test_version_semver() -> None:
8
- assert version.semver("0.4.0") == "0.4.0"
9
- assert version.semver("0.4.0-6-gaaaaaaa") == "0.4.1-6+aaaaaaa"
10
-
11
-
12
- def test_semver_ordering() -> None:
13
- # 6 commits after 0.4.0
14
- assert parse_semver("0.4.1-6+aaaaaaa") > parse_semver("0.4.0")
15
- # prerelease version are lower than release ones
16
- assert parse_semver("0.4.0") > parse_semver("0.4.0-6+aaaaaaa")
17
- # build info (after '+') don't count in semver comparisons
18
- assert parse_semver("0.4.0-6+bbbbbbb") == parse_semver("0.4.0-6+aaaaaa")
19
- # 7 commits after 0.4.0 is a higher version than 6 commits after 0.4.0
20
- assert parse_semver("0.4.1-7+aaaaaaa") > parse_semver("0.4.1-6+aaaaaaa")
21
- # number of commits (prerelease) is treated as a number, not as a string: 50 > 6
22
- assert parse_semver("0.4.1-50+aaaaaaa") > parse_semver("0.4.1-6+aaaaaaa")
23
-
24
-
25
- def test_version_pip() -> None:
26
- assert version.pip("0.4.0") == "0.4.0"
27
- assert version.pip("0.4.0-6-gaaaaaaa") == "0.4.1.pre6"
28
- # assert version.pip("0.4.0-6-gaaaaaaa") == "0.4.0.post6"
29
-
30
-
31
- def test_pep440_ordering() -> None:
32
- assert pep440.Version("0.4.1") > pep440.Version("0.4.0")
33
-
34
- # using pre-releases
35
- assert pep440.Version("0.4.1.pre6") > pep440.Version("0.4.0")
36
- assert pep440.Version("0.4.1.pre6") < pep440.Version("0.4.1")
37
- assert pep440.Version("0.4.1.pre6") > pep440.Version("0.4.1.pre5")
38
- assert pep440.Version("0.4.1.pre50") > pep440.Version("0.4.1.pre6")
39
-
40
- # using post-releases
41
- assert pep440.Version("0.4.0.post6") > pep440.Version("0.4.0")
42
- assert pep440.Version("0.4.0.post6") < pep440.Version("0.4.1")
43
- assert pep440.Version("0.4.0.post6") > pep440.Version("0.4.0.post5")
44
- assert pep440.Version("0.4.0.post50") > pep440.Version("0.4.0.post6")
45
-
46
-
47
- def test_version_docker() -> None:
48
- assert version.docker("0.4.0") == "0.4.0"
49
- assert version.docker("0.4.0-6-gaaaaaaa") == "0.4.1.pre6"
50
- # assert version.docker("0.4.0-6-gaaaaaaa") == "0.4.0.post6"
release/version.py DELETED
@@ -1,104 +0,0 @@
1
- #!/usr/bin/env python3
2
-
3
- import locale
4
- import os
5
- import re
6
- import subprocess
7
- import sys
8
- from typing import Optional
9
-
10
- GIT_VERSION_FILE = "GIT_VERSION"
11
-
12
-
13
- def git() -> str:
14
- """get the version from git. Can be
15
- - X.Y.Z if a tag is set on the current HEAD
16
- - X.Y.Z-<count>-g<commitid> otherwise where
17
- - X.Y.Z is the latest version tag found
18
- - <count> is the number of commits since then
19
- - <commitid> is the current HEAD commitid
20
- """
21
- cmd = "git describe --tags --match=[0-9]*.[0-9]*.[0-9]*"
22
- try:
23
- p = subprocess.run(cmd.split(" "), capture_output=True, check=True)
24
- v = p.stdout.decode("utf-8").strip()
25
- # tox is running setup.py sdist from the git repo, and then runs again outside
26
- # of the git repo. At this second step, we cannot run git commands.
27
- # So we save the git version in a file and include it in the source distribution
28
- with open(
29
- GIT_VERSION_FILE, "w", encoding=locale.getpreferredencoding(False)
30
- ) as f:
31
- f.write(v)
32
- return v
33
- except subprocess.CalledProcessError as e:
34
- # if we're not in a git repo, try reading out from the GIT_VERSION file
35
- if os.path.exists(GIT_VERSION_FILE):
36
- with open(
37
- GIT_VERSION_FILE, encoding=locale.getpreferredencoding(False)
38
- ) as f:
39
- return f.read()
40
- print(e.stderr)
41
- raise e
42
-
43
-
44
- def commit(length: int = 7) -> str:
45
- """get the current git commitid"""
46
- cmd = f"git rev-parse --short={length} HEAD"
47
- p = subprocess.run(cmd.split(" "), capture_output=True, check=True)
48
- return p.stdout.decode("utf-8").strip()
49
-
50
-
51
- def semver(git_version: Optional[str] = None) -> str: # noqa: UP007 - RHEL8 has python 3.8
52
- """get a semantic version out of the input git version (see git())
53
- - if a X.Y.Z tag is set on the current HEAD, we'll use this
54
- - else we'll use X.Y.<Z+1>-<count>+<commitid> to respect semver and version
55
- ordering. <count> is the prerelease id, <commitid> is a buildinfo
56
- """
57
- v = git_version or git()
58
- m = re.match(r"(\d+)\.(\d+)\.(\d+)-(\d+)-g(.+)", v)
59
- if m:
60
- major, minor, patch, prerelease, buildinfo = m.groups()
61
- # semver prerelase are supposed to show build increments *prior* to a release.
62
- # So we're bumping the patch number to show what the next release would be.
63
- # this allows correct version ordering
64
- patch = str(int(patch) + 1)
65
- # X.Y.Z-<count>-g<commitid> is not a valid as <count>-g<commitid> would be
66
- # compared as a string, leading to (count=50) < (count=6)
67
- # X.Y.Z-<count>+<commitid> is valid .
68
- # <count> is then the prerelease field, treated as a numeric.
69
- # <commitid> is then a buildinfo string, not used in version comparisons
70
- v = f"{major}.{minor}.{patch}-{prerelease}+{buildinfo}"
71
- return str(v)
72
-
73
-
74
- def pip(git_version: Optional[str] = None) -> str: # noqa: UP007 - RHEL8 has python 3.8
75
- """get a pip version out of the input git version (see git()),
76
- according to https://peps.python.org/pep-0440/
77
- - if a X.Y.Z tag is set on the current HEAD, we'll use this
78
- - else we'll use X.Y.(Z+1).pre<count>+<commitid> to respect PEP-0440 versioning
79
- """
80
- return semver(git_version).replace("-", ".pre").split("+", maxsplit=1)[0]
81
- # Alternatively, use postreleases
82
- # v = git_version or git()
83
- # m = re.match(r"(\d+)\.(\d+)\.(\d+)-(\d+)-g(.+)", v)
84
- # if m:
85
- # major, minor, patch, count, commitid = m.groups()
86
- # v = f"{major}.{minor}.{patch}.post{count}+{commitid}"
87
- # return str(v)
88
-
89
-
90
- def docker(git_version: Optional[str] = None) -> str: # noqa: UP007 - RHEL8 has python 3.8
91
- # docker tags don't like '+' characters, let's remove the buildinfo/commitid
92
- return pip(git_version)
93
-
94
-
95
- if __name__ == "__main__":
96
- type_param = sys.argv[1] if len(sys.argv) > 1 else "--git"
97
- v = {
98
- "--git": git(),
99
- "--commit": commit(),
100
- "--semver": semver(),
101
- "--pip": pip(),
102
- "--docker": docker(),
103
- }[type_param]
104
- print(v)
File without changes