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

Commit a7b5b17

Browse files
Allow users to init config from Transifex, and not just CLI or envars. Disallow pos params in Transifex(). (#14)
1 parent 1115753 commit a7b5b17

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

pytransifex/api.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,22 @@ class Transifex:
335335

336336
client = None
337337

338-
def __new__(cls, defer_login: bool = False):
338+
def __new__(cls, *, defer_login: bool = False, **kwargs):
339339
if not cls.client:
340-
cls.client = Client(ApiConfig.from_env(), defer_login)
340+
try:
341+
if kwargs:
342+
config = ApiConfig(**kwargs)
343+
else:
344+
logging.info(
345+
f"As you called 'Transifex' without argument, we'll try defining your project from environment variables."
346+
)
347+
config = ApiConfig.from_env()
348+
349+
cls.client = Client(config, defer_login)
350+
351+
except Exception as error:
352+
available = list(ApiConfig._fields)
353+
msg = f"Unable to define a proper config. API initialization uses the following fields, with only 'project_slug' optional: {available}"
354+
logging.error(f"{msg}:\n{error}")
355+
341356
return cls.client

0 commit comments

Comments
 (0)