Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

Commit

Permalink
Support single-threaded mode
Browse files Browse the repository at this point in the history
  • Loading branch information
SanmerDev committed Oct 2, 2023
1 parent 318d13e commit 170f088
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 12 deletions.
4 changes: 3 additions & 1 deletion sync/cli/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def github(cls) -> int:
tracks.get_tracks(
user_name=cls._args.user_name,
repo_names=cls._args.repo_names,
single=cls._args.single,
cover=cls._args.cover,
use_ssh=cls._args.ssh
)
Expand All @@ -253,7 +254,8 @@ def sync(cls) -> int:
sync.create_local_tracks()
sync.update(
module_ids=cls._args.module_ids,
force=cls._args.force
force=cls._args.force,
single=cls._args.single
)

index = Index(root_folder=root_folder, config=config)
Expand Down
30 changes: 25 additions & 5 deletions sync/cli/Parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

if add_custom_help:
Parameters.add_parser_help(self)
self.add_argument(
"-h",
"--help",
action=_HelpAction,
help="Show this help message and exit.",
)


class BoolOrStrAction(Action):
Expand Down Expand Up @@ -267,7 +272,12 @@ def configure_parser_github(cls, sub_parsers):

env = cls.add_parser_env(p, add_quiet=True)
env.add_argument(
"--api-token",
"--single",
action="store_true",
help="Run in single-threaded mode."
)
env.add_argument(
"--token",
metavar="GITHUB_TOKEN",
type=str,
default=cls._github_token,
Expand Down Expand Up @@ -311,7 +321,12 @@ def configure_parser_sync(cls, sub_parsers):
help="Remove all old versions of modules."
)
cls.add_parser_git(p)
cls.add_parser_env(p, add_quiet=True)
env = cls.add_parser_env(p, add_quiet=True)
env.add_argument(
"--single",
action="store_true",
help="Run in single-threaded mode."
)

@classmethod
def configure_parser_index(cls, sub_parsers):
Expand Down Expand Up @@ -393,7 +408,12 @@ def add_parser_env(cls, p, add_quiet=False):
)

if add_quiet:
cls.add_parser_quiet(env)
env.add_argument(
"-q",
"--quiet",
action="store_true",
help="Disable all logging piped through stdout."
)

env.add_argument(
"--debug",
Expand Down Expand Up @@ -438,7 +458,7 @@ def add_parser_quiet(cls, p):
"-q",
"--quiet",
action="store_true",
help="Disable all logging piped through stdout."
help="Show only error logs (piped through stderr)."
)

@classmethod
Expand Down
5 changes: 3 additions & 2 deletions sync/core/Sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ def create_local_tracks(self):
)
return self._tracks

def update(self, module_ids=None, force=False, **kwargs):
def update(self, module_ids=None, force=False, single=False, **kwargs):
user_name = kwargs.get("user_name")
if user_name is not None:
if self._check_tracks(self._tracks, GithubTracks):
tracks = self._tracks.get_tracks(
user_name=user_name,
repo_names=module_ids,
single=single,
cover=kwargs.get("cover", False),
use_ssh=kwargs.get("use_ssh", True)
)
Expand All @@ -141,7 +142,7 @@ def update(self, module_ids=None, force=False, **kwargs):
else:
tracks = self._tracks.get_tracks(module_ids)

with ThreadPoolExecutor() as executor:
with ThreadPoolExecutor(max_workers=1 if single else None) as executor:
futures = []
for track in tracks:
futures.append(
Expand Down
8 changes: 7 additions & 1 deletion sync/core/Sync.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class Sync:
def _check_tracks(obj: BaseTracks, cls: type) -> bool: ...
def create_github_tracks(self, api_token: str, after_date: Optional[date] = ...) -> BaseTracks: ...
def create_local_tracks(self) -> BaseTracks: ...
def update(self, module_ids: Optional[List[str]] = ..., force: bool = ..., **kwargs): ...
def update(
self,
module_ids: Optional[List[str]] = ...,
force: bool = ...,
single: bool = ...,
**kwargs
): ...
def push_by_git(self, branch: str): ...
def get_versions_diff(self) -> Optional[str]: ...
6 changes: 3 additions & 3 deletions sync/track/GithubTracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _get_from_repo_common(self, repo: Repository, use_ssh):
name=repo.name
)
if homepage is None:
homepage = repo.html_url
homepage = ""

return TrackJson(
id=repo.name,
Expand Down Expand Up @@ -106,7 +106,7 @@ def get_track(self, user_name, repo_name, *, cover=False, use_ssh=True):

return self._get_from_repo(repo, cover, use_ssh)

def get_tracks(self, user_name, repo_names=None, *, cover=False, use_ssh=True):
def get_tracks(self, user_name, repo_names=None, *, single=False, cover=False, use_ssh=True):
self._tracks.clear()
self._log.i(f"get_tracks: user_name = {user_name}")

Expand All @@ -124,7 +124,7 @@ def get_tracks(self, user_name, repo_names=None, *, cover=False, use_ssh=True):
else:
repos = user.get_repos()

with ThreadPoolExecutor() as executor:
with ThreadPoolExecutor(max_workers=1 if single else None) as executor:
futures = []
for repo in repos:
futures.append(
Expand Down
1 change: 1 addition & 0 deletions sync/track/GithubTracks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class GithubTracks(BaseTracks):
user_name: str,
repo_names: Optional[List[str]] = ...,
*,
single: bool = ...,
cover: bool = ...,
use_ssh: bool = ...
) -> List[TrackJson]: ...
Expand Down

0 comments on commit 170f088

Please sign in to comment.