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

Commit

Permalink
Fixing incorrect 'list_resources' method.
Browse files Browse the repository at this point in the history
  • Loading branch information
why-not-try-calmer committed Feb 15, 2023
1 parent 99ed7d0 commit cd4d4dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
18 changes: 10 additions & 8 deletions pytransifex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ def get_project(self, project_slug: str) -> None | Resource:
return None

@ensure_login
def list_resources(self, project_slug: str) -> list[Resource]:
def list_resources(self, project_slug: str) -> list[Any]:
"""List all resources for the project passed as argument"""
if self.projects:
res = self.projects.filter(slug=project_slug)
logging.info("Obtained these resources:")
return res
if project := self.get_project(project_slug=project_slug):
if resources := project.fetch("resources"):
return list(resources.all())
else:
return []

raise Exception(
f"Unable to find any project under this organization: '{self.organization}'"
)
Expand All @@ -109,8 +111,8 @@ def create_resource(
if project := self.get_project(project_slug=project_slug):
resource = tx_api.Resource.create(
project=project,
name=resource_name,
slug=resource_slug,
name=resource_name or resource_slug,
slug=resource_slug or resource_name,
i18n_format=tx_api.I18nFormat(id=self.i18n_type),
)

Expand Down Expand Up @@ -305,7 +307,7 @@ def push(
logging.info(f"Slug: {slug}. Resources: {resources}.")
if not slug in resources:
logging.info(
f"{project_slug} is missing {slug}. Created it from {path}."
f"{project_slug} is missing {slug}. Creating it from {path}."
)
self.create_resource(
project_slug=project_slug, path_to_file=path, resource_slug=slug
Expand Down
14 changes: 7 additions & 7 deletions pytransifex/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ def concurrently(
args: list[Any] | None = None,
partials: list[Any] | None = None,
) -> list[Any]:
if args and len(args) == 0:
return []
if partials and len(partials) == 0:
return []

with ThreadPoolExecutor() as pool:
if partials:
if not partials is None:
assert args is None and fn is None
futures = [pool.submit(p) for p in partials]
elif fn and args:
elif (not args is None) and (not fn is None):
assert partials is None
futures = [pool.submit(fn, *a) for a in args]
else:
raise Exception("Either partials or fn and args!")
raise ValueError(
"Exactly 1 of 'partials' or 'args' must be defined. Found neither was when calling concurrently."
)
return [f.result() for f in as_completed(futures)]

0 comments on commit cd4d4dc

Please sign in to comment.