Skip to content

🐛Python 3.11 support #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 3, 2023
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
python_cache_windows_path: ~\AppData\Local\pip\Cache
python_cache_ubuntu_path: ~/.cache/pip
pipenv_version: 2022.11.25
python_version: '3.10'
python_version: '3.11'

jobs:
# Check that a news file has been added to this branch when a PR is created
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest ] # FIXME add other platforms when much quicker macOS-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
multi-platform:
- ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }}
# include:
Expand All @@ -180,7 +180,7 @@ jobs:
include:
- os: macOS-latest
multi-platform: false
python-version: 3.9
python-version: 3.11
# - os: windows-latest
# multi-platform: false
# python-version: 3.9
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Run type checker"
on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]

jobs:
type-check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install pipenv
shell: bash
run: |
python -m pip install --upgrade pipenv
pipenv install --dev
- name: Type check with mypy
run: |
pipenv run mypy ./continuous_delivery_scripts
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: GitHub Release

env:
pipenv_version: 2022.11.25
python_version: '3.10'
python_version: '3.11'

on:
workflow_dispatch:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Pipfile.lock

# macOS
.DS_Store
.tool-versions

# Python
*.pyc
Expand Down
1 change: 0 additions & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Setup Pipenv to use Python 3 (Python 2 is not supported) and install package dev

```bash
cd continuous-delivery-scripts/
pipenv --three
pipenv install --dev
```

Expand Down
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ allow_prereleases = false

[packages]
continuous-delivery-scripts = {editable = true, path = "."}
types-toml = "*"
types-setuptools = "*"
13 changes: 10 additions & 3 deletions continuous_delivery_scripts/assert_news.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pathlib
import re
import sys
from typing import List, Union
from typing import Union, Optional, Iterable, Any, List

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


def _convert_to_string_iter(list: Optional[List[Any]]) -> Iterable[str]:
if list is None:
return []
return [str(item) for item in list]


def generate_news_file(git: GitWrapper, news_dir: pathlib.Path) -> pathlib.Path:
"""Adds a news file if the branch corresponds to an dependency update.

Expand All @@ -114,8 +120,9 @@ def generate_news_file(git: GitWrapper, news_dir: pathlib.Path) -> pathlib.Path:
if not configuration.get_value(ConfigurationVariable.AUTOGENERATE_NEWS_FILE_ON_DEPENDENCY_UPDATE):
raise EnvironmentError(f"Branch {current_branch} must contain a news file.")

list_groups = _convert_to_string_iter(groups)
message = str(configuration.get_value(ConfigurationVariable.DEPENDENCY_UPDATE_NEWS_MESSAGE)).format(
message=", ".join(groups)
message=", ".join(list_groups)
)
logger.info(f"Generating a news file with content: {message}...")
return create_news_file(
Expand All @@ -130,7 +137,7 @@ def _commit_news_file(git: GitWrapper, news_file: pathlib.Path, local: bool) ->
logger.info(f"Committing news file {str(news_file)}...")
if not local:
git.configure_for_github()
git.add(str(news_file))
git.add(news_file)
git.commit("📰 Automatic changes ⚙ Adding news file")
if not local:
git.push()
Expand Down
3 changes: 2 additions & 1 deletion continuous_delivery_scripts/get_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""Determine the project new version."""
import sys

from typing import Optional
import argparse
import logging
from continuous_delivery_scripts.utils.versioning import calculate_version, determine_version_string
Expand All @@ -15,7 +16,7 @@
logger = logging.getLogger(__name__)


def get_project_version_string(commit_type: CommitType) -> str:
def get_project_version_string(commit_type: CommitType) -> Optional[str]:
"""Determine the project version string.

Args:
Expand Down
10 changes: 5 additions & 5 deletions continuous_delivery_scripts/language_specifics.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
logger = logging.getLogger(__name__)


def _retrieve_all_subclasses(subclass: Type[BaseLanguage]) -> Set[Type[BaseLanguage]]:
subclasses = set()
def _retrieve_all_subclasses(subclass: Type) -> Set[Type]:
subclasses: set = set()
if not subclass:
return subclasses
if subclass != BaseLanguage:
Expand All @@ -31,10 +31,10 @@ def all_language_plugins() -> Dict[str, BaseLanguage]:
"""Fetches all language plugins which inherit from BaseLanguage.

Returns:
A list of classes containing language plugins
A list of classes containing language plugins
"""
all_plugins = _retrieve_all_subclasses(BaseLanguage)
return {la.get_related_language().lower().strip(): la for la in [lang() for lang in all_plugins]} # type: ignore
return {la.get_related_language().lower().strip(): la for la in [lang() for lang in all_plugins]}


def fetch_project_language_plugin(all_plugins: Dict[str, BaseLanguage], language: str) -> BaseLanguage:
Expand All @@ -45,7 +45,7 @@ def fetch_project_language_plugin(all_plugins: Dict[str, BaseLanguage], language
language: the language to select

Returns:
A language plugin corresponding to the language requested
A language plugin corresponding to the language requested
"""
return cast(BaseLanguage, all_plugins.get(_sanitise_program_language(language)))

Expand Down
2 changes: 1 addition & 1 deletion continuous_delivery_scripts/plugins/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_related_language(self) -> str:
"""Gets the related language."""
return get_language_from_file_name(__file__)

def get_version_tag(self, version: str):
def get_version_tag(self, version: str) -> str:
"""Gets tag based on version."""
cleansed_version = version.strip().lstrip("v")
return f"v{cleansed_version}"
Expand Down
4 changes: 2 additions & 2 deletions continuous_delivery_scripts/plugins/golang.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _call_goreleaser_check(version: str) -> None:
check_call(_generate_goreleaser_check_command_list(), cwd=ROOT_DIR, env=env)


def _determine_go_module_tag(version) -> Optional[str]:
def _determine_go_module_tag(version: str) -> Optional[str]:
"""Determines go module for tagging.

See https://golang.org/ref/mod#vcs-version.
Expand All @@ -121,7 +121,7 @@ def get_related_language(self) -> str:
"""Gets the related language."""
return get_language_from_file_name(__file__)

def get_version_tag(self, version: str):
def get_version_tag(self, version: str) -> str:
"""Gets tag based on version."""
cleansed_version = version.strip().lstrip("v")
return f"v{cleansed_version}"
Expand Down
2 changes: 1 addition & 1 deletion continuous_delivery_scripts/spdx_report/spdx_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(
package_metadata: PackageMetadata,
other_document_refs: List[DependencySpdxDocumentRef] = list(),
is_dependency: bool = False,
document_namespace: str = None,
document_namespace: Optional[str] = None,
):
"""Constructor."""
self._project_root = Path(configuration.get_value(ConfigurationVariable.PROJECT_ROOT))
Expand Down
4 changes: 2 additions & 2 deletions continuous_delivery_scripts/spdx_report/spdx_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
logger = logging.getLogger(__name__)

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


def determine_spdx_value(value: Optional[str]) -> Union[str, UnKnown, SPDXNone]:
Expand Down
2 changes: 1 addition & 1 deletion continuous_delivery_scripts/spdx_report/spdx_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


def generate_file_based_on_template(
output_dir: Path, template_name: str, template_args: dict, suffix: str = None
output_dir: Path, template_name: str, template_args: dict, suffix: Optional[str] = None
) -> None:
"""Write file based on template and arguments."""
logger.info("Loading template '%s'.", template_name)
Expand Down
2 changes: 1 addition & 1 deletion continuous_delivery_scripts/utils/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class FileConfig(GenericConfig):
PATH_TOKEN = {"DIR", "ROOT", "PATH"}
CONFIG_FILE_NAME = "pyproject.toml"

def __init__(self, file_path: str = None) -> None:
def __init__(self, file_path: Optional[str] = None) -> None:
"""Constructor.

Args:
Expand Down
18 changes: 10 additions & 8 deletions continuous_delivery_scripts/utils/git_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def checkout(self, branch: Any) -> None:
"""
self.repo.git.checkout(branch)

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

def add(self, path: Union[list, set, str]) -> None:
def add(self, path: Union[list, set, Path]) -> None:
"""Adds a file or a list of files.

Args:
Expand Down Expand Up @@ -488,7 +488,7 @@ def is_dirty(self) -> bool:

Repository is considered dirty when git status returns elements which are not committed.
"""
return self.repo.is_dirty(untracked_files=True)
return bool(self.repo.is_dirty(untracked_files=True))

def clean(self) -> None:
"""Cleans the repository.
Expand Down Expand Up @@ -588,17 +588,19 @@ def is_current_branch_feature(self) -> bool:
is_release = self.is_release_branch(current_branch)
return not (is_master or is_beta or is_release)

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

def _is_branch_of_type(self, branch_name: Optional[str], pattern: Optional[str]) -> (bool, Optional[List[Any]]):
def _is_branch_of_type(
self, branch_name: Optional[str], pattern: Optional[str]
) -> Tuple[bool, Optional[List[Any]]]:
if not pattern:
return False, None
if not branch_name:
return False, None
match = re.search(pattern, str(branch_name))
return True if match else False, match.groups() if match else None
return True if match else False, list(match.groups()) if match else None

@property
def uncommitted_changes(self) -> List[Path]:
Expand Down Expand Up @@ -643,7 +645,7 @@ def apply_uncommitted_changes(self, other_repo: "GitWrapper") -> None:
"""Applies the uncommitted changes found in current repository to another.

Args:
other_repo: repository to apply changes to
other_repo: repository to apply changes to
"""
dest_root = other_repo.root
for f in self.uncommitted_changes:
Expand Down Expand Up @@ -738,7 +740,7 @@ def get_corresponding_path(self, path_in_initial_repo: Path) -> Path:
path_in_initial_repo: path to a file/directory in initial repository.

Returns:
corresponding path.
corresponding path.
"""
if not path_in_initial_repo.is_absolute():
return Path(self.root).joinpath(path_in_initial_repo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def tag_release(self, git: GitWrapper, version: str, shortcuts: Dict[str, bool])
"""Tags release commit."""
logger.info(f"Tagging commit as release {version}")
git.create_tag(self.get_version_tag(version), message=f"release {version}")
for shortcut, version in shortcuts.items():
if version:
for shortcut, versions in shortcuts.items():
if versions:
git.create_tag(self.get_version_tag(shortcut), message=f"{shortcut} release")
else:
git.create_tag(shortcut, message=shortcut)
Expand Down
8 changes: 4 additions & 4 deletions continuous_delivery_scripts/utils/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def determine_version_string(
commit_count = version_elements.get(auto_version_tool.Constants.COMMIT_COUNT_FIELD, None)
if not commit_count:
with LocalProjectRepository() as git:
commit_count = git.get_commit_count()
commit_count = str(git.get_commit_count())
commit_hash = version_elements.get(auto_version_tool.Constants.COMMIT_FIELD, None)
if not commit_hash:
with LocalProjectRepository() as git:
commit_hash = git.get_commit_hash()
commit_hash = str(git.get_commit_hash())
return "%s-%s.%s+%s" % (
new_version,
auto_version_tool.config.BUILD_TOKEN,
Expand Down Expand Up @@ -129,11 +129,11 @@ def determine_version_shortcuts(
commit_count = version_elements.get(auto_version_tool.Constants.COMMIT_COUNT_FIELD, None)
if not commit_count:
with LocalProjectRepository() as git:
commit_count = git.get_commit_count()
commit_count = str(git.get_commit_count())
commit_hash = version_elements.get(auto_version_tool.Constants.COMMIT_FIELD, None)
if not commit_hash:
with LocalProjectRepository() as git:
commit_hash = git.get_commit_hash()
commit_hash = str(git.get_commit_hash())
shortcuts[f"{auto_version_tool.config.BUILD_TOKEN}.{commit_count}+{commit_hash}"] = False

return shortcuts
Expand Down
1 change: 1 addition & 0 deletions news/20230303162821.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support python 3.11
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Software Development :: Build Tools",
],
description="Continuous Delivery scripts to increase automation",
Expand Down