Skip to content

Commit ecffafa

Browse files
authoredMar 3, 2023
🐛Python 3.11 support (#80)
<!-- Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved. SPDX-License-Identifier: Apache-2.0 --> ### Description <!-- Please add any detail or context that would be useful to a reviewer. --> Make updates to allow the codebase to run on python 3.11 ### Test Coverage <!-- Please put an `x` in the correct box e.g. `[x]` to indicate the testing coverage of this change. --> - [x] This change is covered by existing or additional automated tests. - [ ] Manual testing has been performed (and evidence provided) as automated testing was not feasible. - [ ] Additional tests are not required for this change (e.g. documentation update).
1 parent 2fe5dec commit ecffafa

20 files changed

+76
-36
lines changed
 

‎.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ env:
1111
python_cache_windows_path: ~\AppData\Local\pip\Cache
1212
python_cache_ubuntu_path: ~/.cache/pip
1313
pipenv_version: 2022.11.25
14-
python_version: '3.10'
14+
python_version: '3.11'
1515

1616
jobs:
1717
# Check that a news file has been added to this branch when a PR is created
@@ -166,7 +166,7 @@ jobs:
166166
fail-fast: false
167167
matrix:
168168
os: [ubuntu-latest ] # FIXME add other platforms when much quicker macOS-latest, windows-latest]
169-
python-version: ["3.8", "3.9", "3.10"]
169+
python-version: ["3.8", "3.9", "3.10", "3.11"]
170170
multi-platform:
171171
- ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }}
172172
# include:
@@ -180,7 +180,7 @@ jobs:
180180
include:
181181
- os: macOS-latest
182182
multi-platform: false
183-
python-version: 3.9
183+
python-version: 3.11
184184
# - os: windows-latest
185185
# multi-platform: false
186186
# python-version: 3.9

‎.github/workflows/mypy.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "Run type checker"
2+
on:
3+
push:
4+
branches: [ "main" ]
5+
pull_request:
6+
# The branches below must be a subset of the branches above
7+
branches: [ "main" ]
8+
9+
jobs:
10+
type-check:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Setup Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: "3.11"
19+
- name: Install pipenv
20+
shell: bash
21+
run: |
22+
python -m pip install --upgrade pipenv
23+
pipenv install --dev
24+
- name: Type check with mypy
25+
run: |
26+
pipenv run mypy ./continuous_delivery_scripts

‎.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: GitHub Release
22

33
env:
44
pipenv_version: 2022.11.25
5-
python_version: '3.10'
5+
python_version: '3.11'
66

77
on:
88
workflow_dispatch:

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Pipfile.lock
66

77
# macOS
88
.DS_Store
9+
.tool-versions
910

1011
# Python
1112
*.pyc

‎DEVELOPMENT.md

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ Setup Pipenv to use Python 3 (Python 2 is not supported) and install package dev
5151

5252
```bash
5353
cd continuous-delivery-scripts/
54-
pipenv --three
5554
pipenv install --dev
5655
```
5756

‎Pipfile

+2
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ allow_prereleases = false
2323

2424
[packages]
2525
continuous-delivery-scripts = {editable = true, path = "."}
26+
types-toml = "*"
27+
types-setuptools = "*"

‎continuous_delivery_scripts/assert_news.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pathlib
99
import re
1010
import sys
11-
from typing import List, Union
11+
from typing import Union, Optional, Iterable, Any, List
1212

1313
from continuous_delivery_scripts.utils.configuration import configuration, ConfigurationVariable
1414
from continuous_delivery_scripts.utils.git_helpers import ProjectTempClone, LocalProjectRepository, GitWrapper
@@ -98,6 +98,12 @@ def validate_news_files(git: GitWrapper, root_dir: str, news_dir: str) -> None:
9898
validate_news_file(absolute_file_path)
9999

100100

101+
def _convert_to_string_iter(list: Optional[List[Any]]) -> Iterable[str]:
102+
if list is None:
103+
return []
104+
return [str(item) for item in list]
105+
106+
101107
def generate_news_file(git: GitWrapper, news_dir: pathlib.Path) -> pathlib.Path:
102108
"""Adds a news file if the branch corresponds to an dependency update.
103109
@@ -114,8 +120,9 @@ def generate_news_file(git: GitWrapper, news_dir: pathlib.Path) -> pathlib.Path:
114120
if not configuration.get_value(ConfigurationVariable.AUTOGENERATE_NEWS_FILE_ON_DEPENDENCY_UPDATE):
115121
raise EnvironmentError(f"Branch {current_branch} must contain a news file.")
116122

123+
list_groups = _convert_to_string_iter(groups)
117124
message = str(configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_MESSAGE)).format(
118-
message=", ".join(groups)
125+
message=", ".join(list_groups)
119126
)
120127
logger.info(f"Generating a news file with content: {message}...")
121128
return create_news_file(
@@ -130,7 +137,7 @@ def _commit_news_file(git: GitWrapper, news_file: pathlib.Path, local: bool) ->
130137
logger.info(f"Committing news file {str(news_file)}...")
131138
if not local:
132139
git.configure_for_github()
133-
git.add(str(news_file))
140+
git.add(news_file)
134141
git.commit("📰 Automatic changes ⚙ Adding news file")
135142
if not local:
136143
git.push()

‎continuous_delivery_scripts/get_version.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""Determine the project new version."""
66
import sys
77

8+
from typing import Optional
89
import argparse
910
import logging
1011
from continuous_delivery_scripts.utils.versioning import calculate_version, determine_version_string
@@ -15,7 +16,7 @@
1516
logger = logging.getLogger(__name__)
1617

1718

18-
def get_project_version_string(commit_type: CommitType) -> str:
19+
def get_project_version_string(commit_type: CommitType) -> Optional[str]:
1920
"""Determine the project version string.
2021
2122
Args:

‎continuous_delivery_scripts/language_specifics.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
logger = logging.getLogger(__name__)
1717

1818

19-
def _retrieve_all_subclasses(subclass: Type[BaseLanguage]) -> Set[Type[BaseLanguage]]:
20-
subclasses = set()
19+
def _retrieve_all_subclasses(subclass: Type) -> Set[Type]:
20+
subclasses: set = set()
2121
if not subclass:
2222
return subclasses
2323
if subclass != BaseLanguage:
@@ -31,10 +31,10 @@ def all_language_plugins() -> Dict[str, BaseLanguage]:
3131
"""Fetches all language plugins which inherit from BaseLanguage.
3232
3333
Returns:
34-
A list of classes containing language plugins
34+
A list of classes containing language plugins
3535
"""
3636
all_plugins = _retrieve_all_subclasses(BaseLanguage)
37-
return {la.get_related_language().lower().strip(): la for la in [lang() for lang in all_plugins]} # type: ignore
37+
return {la.get_related_language().lower().strip(): la for la in [lang() for lang in all_plugins]}
3838

3939

4040
def fetch_project_language_plugin(all_plugins: Dict[str, BaseLanguage], language: str) -> BaseLanguage:
@@ -45,7 +45,7 @@ def fetch_project_language_plugin(all_plugins: Dict[str, BaseLanguage], language
4545
language: the language to select
4646
4747
Returns:
48-
A language plugin corresponding to the language requested
48+
A language plugin corresponding to the language requested
4949
"""
5050
return cast(BaseLanguage, all_plugins.get(_sanitise_program_language(language)))
5151

‎continuous_delivery_scripts/plugins/ci.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_related_language(self) -> str:
3030
"""Gets the related language."""
3131
return get_language_from_file_name(__file__)
3232

33-
def get_version_tag(self, version: str):
33+
def get_version_tag(self, version: str) -> str:
3434
"""Gets tag based on version."""
3535
cleansed_version = version.strip().lstrip("v")
3636
return f"v{cleansed_version}"

‎continuous_delivery_scripts/plugins/golang.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _call_goreleaser_check(version: str) -> None:
9494
check_call(_generate_goreleaser_check_command_list(), cwd=ROOT_DIR, env=env)
9595

9696

97-
def _determine_go_module_tag(version) -> Optional[str]:
97+
def _determine_go_module_tag(version: str) -> Optional[str]:
9898
"""Determines go module for tagging.
9999
100100
See https://golang.org/ref/mod#vcs-version.
@@ -121,7 +121,7 @@ def get_related_language(self) -> str:
121121
"""Gets the related language."""
122122
return get_language_from_file_name(__file__)
123123

124-
def get_version_tag(self, version: str):
124+
def get_version_tag(self, version: str) -> str:
125125
"""Gets tag based on version."""
126126
cleansed_version = version.strip().lstrip("v")
127127
return f"v{cleansed_version}"

‎continuous_delivery_scripts/spdx_report/spdx_document.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(
3131
package_metadata: PackageMetadata,
3232
other_document_refs: List[DependencySpdxDocumentRef] = list(),
3333
is_dependency: bool = False,
34-
document_namespace: str = None,
34+
document_namespace: Optional[str] = None,
3535
):
3636
"""Constructor."""
3737
self._project_root = Path(configuration.get_value(ConfigurationVariable.PROJECT_ROOT))

‎continuous_delivery_scripts/spdx_report/spdx_helpers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
logger = logging.getLogger(__name__)
3434

3535
# Copyright similar to the regex defined in flake8-copyright
36-
COPYRIGHT_PATTERN = r"((?i)Copyright(?i).*$)"
36+
COPYRIGHT_PATTERN = r"(?i)Copyright.*$"
3737
COPYRIGHT_REGEX_PATTERN = re.compile(COPYRIGHT_PATTERN, re.MULTILINE)
3838
# Specification of the identifier based on https://spdx.org/spdx-specification-21-web-version#h.twlc0ztnng3b
3939
# and https://spdx.org/ids-how
@@ -73,7 +73,7 @@ def determine_file_copyright_text(path: Path) -> Optional[str]:
7373
match = scan_file_for_pattern(path, COPYRIGHT_REGEX_PATTERN)
7474
if not match:
7575
return None
76-
return str(match.group(1).strip())
76+
return str(match.group(0).strip())
7777

7878

7979
def determine_spdx_value(value: Optional[str]) -> Union[str, UnKnown, SPDXNone]:

‎continuous_delivery_scripts/spdx_report/spdx_summary.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
def generate_file_based_on_template(
30-
output_dir: Path, template_name: str, template_args: dict, suffix: str = None
30+
output_dir: Path, template_name: str, template_args: dict, suffix: Optional[str] = None
3131
) -> None:
3232
"""Write file based on template and arguments."""
3333
logger.info("Loading template '%s'.", template_name)

‎continuous_delivery_scripts/utils/configuration.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class FileConfig(GenericConfig):
240240
PATH_TOKEN = {"DIR", "ROOT", "PATH"}
241241
CONFIG_FILE_NAME = "pyproject.toml"
242242

243-
def __init__(self, file_path: str = None) -> None:
243+
def __init__(self, file_path: Optional[str] = None) -> None:
244244
"""Constructor.
245245
246246
Args:

‎continuous_delivery_scripts/utils/git_helpers.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def checkout(self, branch: Any) -> None:
114114
"""
115115
self.repo.git.checkout(branch)
116116

117-
def _add_one_file_or_one_dir(self, path: str) -> None:
117+
def _add_one_file_or_one_dir(self, path: Path) -> None:
118118
if not path:
119119
raise ValueError("Unspecified path.")
120120
self._add_one_path(Path(path))
@@ -132,7 +132,7 @@ def _add_one_path(self, path_model: Path) -> None:
132132
logger.info(f"Adding {unix_relative_path} to repository.")
133133
self.repo.git.add(unix_relative_path)
134134

135-
def add(self, path: Union[list, set, str]) -> None:
135+
def add(self, path: Union[list, set, Path]) -> None:
136136
"""Adds a file or a list of files.
137137
138138
Args:
@@ -488,7 +488,7 @@ def is_dirty(self) -> bool:
488488
489489
Repository is considered dirty when git status returns elements which are not committed.
490490
"""
491-
return self.repo.is_dirty(untracked_files=True)
491+
return bool(self.repo.is_dirty(untracked_files=True))
492492

493493
def clean(self) -> None:
494494
"""Cleans the repository.
@@ -588,17 +588,19 @@ def is_current_branch_feature(self) -> bool:
588588
is_release = self.is_release_branch(current_branch)
589589
return not (is_master or is_beta or is_release)
590590

591-
def is_current_branch_of_type(self, pattern: str) -> (bool, Optional[List[Any]]):
591+
def is_current_branch_of_type(self, pattern: str) -> Tuple[bool, Optional[List[Any]]]:
592592
"""Returns boolean indicating whether the current branch follows the pattern and the list of groups if any."""
593593
return self._is_branch_of_type(self.get_current_branch(), pattern)
594594

595-
def _is_branch_of_type(self, branch_name: Optional[str], pattern: Optional[str]) -> (bool, Optional[List[Any]]):
595+
def _is_branch_of_type(
596+
self, branch_name: Optional[str], pattern: Optional[str]
597+
) -> Tuple[bool, Optional[List[Any]]]:
596598
if not pattern:
597599
return False, None
598600
if not branch_name:
599601
return False, None
600602
match = re.search(pattern, str(branch_name))
601-
return True if match else False, match.groups() if match else None
603+
return True if match else False, list(match.groups()) if match else None
602604

603605
@property
604606
def uncommitted_changes(self) -> List[Path]:
@@ -643,7 +645,7 @@ def apply_uncommitted_changes(self, other_repo: "GitWrapper") -> None:
643645
"""Applies the uncommitted changes found in current repository to another.
644646
645647
Args:
646-
other_repo: repository to apply changes to
648+
other_repo: repository to apply changes to
647649
"""
648650
dest_root = other_repo.root
649651
for f in self.uncommitted_changes:
@@ -738,7 +740,7 @@ def get_corresponding_path(self, path_in_initial_repo: Path) -> Path:
738740
path_in_initial_repo: path to a file/directory in initial repository.
739741
740742
Returns:
741-
corresponding path.
743+
corresponding path.
742744
"""
743745
if not path_in_initial_repo.is_absolute():
744746
return Path(self.root).joinpath(path_in_initial_repo)

‎continuous_delivery_scripts/utils/language_specifics_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def tag_release(self, git: GitWrapper, version: str, shortcuts: Dict[str, bool])
7979
"""Tags release commit."""
8080
logger.info(f"Tagging commit as release {version}")
8181
git.create_tag(self.get_version_tag(version), message=f"release {version}")
82-
for shortcut, version in shortcuts.items():
83-
if version:
82+
for shortcut, versions in shortcuts.items():
83+
if versions:
8484
git.create_tag(self.get_version_tag(shortcut), message=f"{shortcut} release")
8585
else:
8686
git.create_tag(shortcut, message=shortcut)

‎continuous_delivery_scripts/utils/versioning.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ def determine_version_string(
7373
commit_count = version_elements.get(auto_version_tool.Constants.COMMIT_COUNT_FIELD, None)
7474
if not commit_count:
7575
with LocalProjectRepository() as git:
76-
commit_count = git.get_commit_count()
76+
commit_count = str(git.get_commit_count())
7777
commit_hash = version_elements.get(auto_version_tool.Constants.COMMIT_FIELD, None)
7878
if not commit_hash:
7979
with LocalProjectRepository() as git:
80-
commit_hash = git.get_commit_hash()
80+
commit_hash = str(git.get_commit_hash())
8181
return "%s-%s.%s+%s" % (
8282
new_version,
8383
auto_version_tool.config.BUILD_TOKEN,
@@ -129,11 +129,11 @@ def determine_version_shortcuts(
129129
commit_count = version_elements.get(auto_version_tool.Constants.COMMIT_COUNT_FIELD, None)
130130
if not commit_count:
131131
with LocalProjectRepository() as git:
132-
commit_count = git.get_commit_count()
132+
commit_count = str(git.get_commit_count())
133133
commit_hash = version_elements.get(auto_version_tool.Constants.COMMIT_FIELD, None)
134134
if not commit_hash:
135135
with LocalProjectRepository() as git:
136-
commit_hash = git.get_commit_hash()
136+
commit_hash = str(git.get_commit_hash())
137137
shortcuts[f"{auto_version_tool.config.BUILD_TOKEN}.{commit_count}+{commit_hash}"] = False
138138

139139
return shortcuts

‎news/20230303162821.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support python 3.11

‎setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"Programming Language :: Python :: 3.8",
3333
"Programming Language :: Python :: 3.9",
3434
"Programming Language :: Python :: 3.10",
35+
"Programming Language :: Python :: 3.11",
3536
"Topic :: Software Development :: Build Tools",
3637
],
3738
description="Continuous Delivery scripts to increase automation",

0 commit comments

Comments
 (0)
Please sign in to comment.