Skip to content

Commit

Permalink
chore: replace double underscores with single
Browse files Browse the repository at this point in the history
  • Loading branch information
atarutin committed Jun 14, 2024
1 parent 44f2950 commit 3c05cf2
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 127 deletions.
13 changes: 7 additions & 6 deletions core/cvs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The module contains classes to keep info about CVS repositories."""

from enum import Enum

from config import Config
Expand All @@ -23,8 +24,8 @@ def __init__(self, git_cloud: GitCloudService, url: str, config=None):
if config is None:
config = Config()

self.__git_cloud = git_cloud
self.__url = url
self._git_cloud = git_cloud
self._url = url

# to access private repositories we need to provide
# username and password (accessToken for github)
Expand All @@ -35,25 +36,25 @@ def __init__(self, git_cloud: GitCloudService, url: str, config=None):
else config.data[git_cloud.value]["password"]
)

self.__url = self.__url.replace(
self._url = self._url.replace(
"https://",
f"https://{username}:{password}@",
)

@property
def url(self):
"""Repository url"""
return self.__url
return self._url

@property
def sanitized_url(self):
"""Repository url without credentials"""
return CodeRepository.sanitize_git_url(self.__url)
return CodeRepository.sanitize_git_url(self._url)

@property
def git_cloud(self):
"""Git cloud service"""
return self.__git_cloud
return self._git_cloud

@staticmethod
def sanitize_git_url(url: str) -> str:
Expand Down
34 changes: 17 additions & 17 deletions core/nova_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,52 +120,52 @@ class NovaComponent:
longest_component_name = 0

def __init__(self, name: str, repo: CodeRepository | None):
self.__name = name
self.__ctype = parse_component_type(name)
self.__tasks: list[NovaTask] = []
self._name = name
self._ctype = parse_component_type(name)
self._tasks: list[NovaTask] = []
self.repo = repo
NovaComponent.longest_component_name = max(
NovaComponent.longest_component_name, len(self.__name)
NovaComponent.longest_component_name, len(self._name)
)

def __str__(self):
return self.__name
return self._name

def __repr__(self):
return self.__str__()

def __eq__(self, other):
return self.__name == other.name
return self._name == other.name

@property
def name(self):
"""Component name"""
return self.__name
return self._name

@property
def tasks(self) -> list[NovaTask]:
"""Returns component tasks"""
return self.__tasks
return self._tasks

@property
def ctype(self) -> NovaComponentType:
"""Returns component type"""
return self.__ctype
return self._ctype

def add_task(self, task: NovaTask):
"""Adds task to component"""
self.__tasks.append(task)
self._tasks.append(task)

def add_tasks(self, tasks: list[NovaTask]):
"""Adds tasks to component"""
self.__tasks.extend(tasks)
self._tasks.extend(tasks)

@property
def status(self) -> Status:
"""Returns component status"""
if not self.__tasks:
if not self._tasks:
return Status.UNDEFINED
statuses = [task.status for task in self.__tasks]
statuses = [task.status for task in self._tasks]
if any(s == Status.UNDEFINED for s in statuses):
return Status.UNDEFINED
if all(s == Status.DONE for s in statuses):
Expand All @@ -176,10 +176,10 @@ def status(self) -> Status:

def describe_status(self) -> str:
"""Returns component status description"""
tasks_count = len(self.__tasks)
tasks_count = len(self._tasks)
width = NovaComponent.longest_component_name
description = (
f"{self.__name:<{width}}"
f"{self._name:<{width}}"
+ f" | {str(self.status):<20}"
+ f" | {tasks_count:>3} tasks"
)
Expand All @@ -195,10 +195,10 @@ def get_release_notes(self, revision_from, revision_to) -> str:
revision_from,
revision_to,
self.repo.sanitized_url,
self.__tasks,
self._tasks,
)
if self.repo.git_cloud == GitCloudService.BITBUCKET:
return get_release_notes_bitbucket(self.__tasks)
return get_release_notes_bitbucket(self._tasks)

return ""

Expand Down
3 changes: 2 additions & 1 deletion core/nova_hotfix.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Nova hotfix component module
"""

from core.nova_release import NovaRelease


Expand All @@ -14,7 +15,7 @@ def __init__(self, project, version, delivery, hotfix):
def __str__(self):
return f"""
Nova {self.version}.
Delivery {self.__delivery}.
Delivery {self._delivery}.
Hotfix {self.hotfix}"""

def __repr__(self):
Expand Down
30 changes: 15 additions & 15 deletions core/nova_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class NovaRelease:
"""Nova release component, readonly model"""

def __init__(self, project, version, delivery):
self.__version = version
self.__delivery = delivery
self.__project = project
self.__components: list[NovaComponent] = []
self._version = version
self._delivery = delivery
self._project = project
self._components: list[NovaComponent] = []

def __str__(self):
return "Nova " + str(self.version) + ". Delivery " + str(self.delivery)
Expand All @@ -30,22 +30,22 @@ def __repr__(self):
return self.__str__()

def __iter__(self):
return iter(self.__components)
return iter(self._components)

@property
def version(self):
"""Returns release version"""
return self.__version
return self._version

@property
def delivery(self):
"""Returns release delivery"""
return self.__delivery
return self._delivery

@property
def project(self):
"""Returns release project"""
return self.__project
return self._project

@property
def title(self) -> str:
Expand All @@ -54,23 +54,23 @@ def title(self) -> str:

def add_component(self, component: NovaComponent):
"""Adds component to release model"""
self.__components.append(component)
self._components.append(component)

def get_status(self) -> Status:
"""Returns release status"""
statuses = list({component.status for component in self.__components})
statuses = list({component.status for component in self._components})
return get_release_status(statuses)

def describe_status(self) -> str:
"""Returns release status description"""
text = [str(self), "*" * len(str(self))]
for component in self.__components:
for component in self._components:
text.append(component.describe_status())
text.append("*" * len(str(self)))
text.append("Total: " + str(len(self.__components)) + " component(s)")
text.append("Total: " + str(len(self._components)) + " component(s)")
text.append(
"Total: "
+ str(sum(len(component.tasks) for component in self.__components))
+ str(sum(len(component.tasks) for component in self._components))
+ " task(s)"
)
text.append("Status: " + str(self.get_status()))
Expand All @@ -88,11 +88,11 @@ def get_component_by_name(self, name: str) -> Optional[NovaComponent]:
if not name:
return None
target_components = [
c for c in self.__components if name.lower() == c.name.lower()
c for c in self._components if name.lower() == c.name.lower()
]
else:
target_components = [
c for c in self.__components if name.lower() in c.name.lower()
c for c in self._components if name.lower() in c.name.lower()
]
if not target_components:
return None
Expand Down
23 changes: 12 additions & 11 deletions core/nova_task.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Nova task component module
"""

from typing import Optional
from core.nova_status import Status

Expand Down Expand Up @@ -45,30 +46,30 @@ def __init__(
if not name:
raise ValueError("Task name is not defined")

self.__name = name
self.__status = status
self.__summary = summary
self.__deployment = deployment
self._name = name
self._status = status
self._summary = summary
self._deployment = deployment

@property
def status(self):
"""Task status"""
return self.__status
return self._status

@property
def name(self):
"""Task name"""
return self.__name
return self._name

@property
def summary(self):
"""Task summary"""
return self.__summary
return self._summary

@property
def deployment(self):
"""Task deployment instructions"""
return self.__deployment
return self._deployment

def get_release_notes(self, preview=False) -> str:
"""
Expand All @@ -78,9 +79,9 @@ def get_release_notes(self, preview=False) -> str:
includes asterisk if task has deployment instructions
:return: release notes
"""
key = self.__name.strip().upper()
key = self._name.strip().upper()
summary = (
self.__summary.split("]")[-1]
self._summary.split("]")[-1]
.strip()
.lstrip("[")
.rstrip(".")
Expand All @@ -89,7 +90,7 @@ def get_release_notes(self, preview=False) -> str:
)
ending = "" if summary.endswith(".") else "."
asterisk_or_not = (
(NovaTask.deployment_asterisk if self.__deployment else "")
(NovaTask.deployment_asterisk if self._deployment else "")
if preview
else ""
)
Expand Down
8 changes: 4 additions & 4 deletions integration/gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class GitHubIntegration:
"""

def __init__(self, github: Github, branch: str = "master"):
self.__g = github
self.__branch = branch
self._g = github
self._branch = branch

def get_repository(self, url: str) -> Repository:
"""
Expand All @@ -31,7 +31,7 @@ def get_repository(self, url: str) -> Repository:
"""
compatible_url = gu.get_github_compatible_repo_address(url)

repo = self.__g.get_repo(compatible_url)
repo = self._g.get_repo(compatible_url)
if repo is None:
raise IOError(f"Could not find repository [{url}]")

Expand Down Expand Up @@ -64,7 +64,7 @@ def create_tag(self, repo_url: str, message: str, tag_name: str) -> Tag:
:return: Tag object
"""
repo = self.get_repository(repo_url)
latest_commit = repo.get_branch(self.__branch).commit
latest_commit = repo.get_branch(self._branch).commit
new_git_tag = repo.create_git_tag(
tag_name, message, latest_commit.sha, "commit"
)
Expand Down
4 changes: 2 additions & 2 deletions integration/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GitIntegration:
"""

def __init__(self, branch: str = "master") -> None:
self.__branch = branch
self._branch = branch

def clone(self, url: str, sources_dir: Optional[str] = None) -> str:
"""
Expand All @@ -40,7 +40,7 @@ def clone(self, url: str, sources_dir: Optional[str] = None) -> str:
if sources_dir is None:
sources_dir = tempfile.mkdtemp(prefix="nova")

Repo.clone_from(url, sources_dir, branch=self.__branch)
Repo.clone_from(url, sources_dir, branch=self._branch)

return sources_dir

Expand Down
Loading

0 comments on commit 3c05cf2

Please sign in to comment.