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

Commit

Permalink
Allow users to init config from Transifex, and not just CLI or envars…
Browse files Browse the repository at this point in the history
…. Disallow pos params in Transifex(). (#14)
  • Loading branch information
why-not-try-calmer authored Feb 16, 2023
1 parent 1115753 commit a7b5b17
Showing 1 changed file with 17 additions and 2 deletions.
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

0 comments on commit a7b5b17

Please sign in to comment.