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

Allow users to init config from Transifex, and not just CLI or envars. #14

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions pytransifex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,22 @@ class Transifex:

client = None

def __new__(cls, defer_login: bool = False):
def __new__(cls, *, defer_login: bool = False, **kwargs):
if not cls.client:
cls.client = Client(ApiConfig.from_env(), defer_login)
try:
if kwargs:
config = ApiConfig(**kwargs)
else:
logging.info(
f"As you called 'Transifex' without argument, we'll try defining your project from environment variables."
)
config = ApiConfig.from_env()

cls.client = Client(config, defer_login)

except Exception as error:
available = list(ApiConfig._fields)
msg = f"Unable to define a proper config. API initialization uses the following fields, with only 'project_slug' optional: {available}"
logging.error(f"{msg}:\n{error}")

return cls.client