Skip to content

Commit

Permalink
Set config file to be platform dependent, and follow the XDG standard. (
Browse files Browse the repository at this point in the history
#90)

Also had to make a change in setup.py as the exec call was importing
__init__.py before any external dependencies were loaded / installed.

setup.py should be deprecated in favor of pyproject.toml, but that's
outside the scope of this change.
  • Loading branch information
pcmxgti committed Nov 30, 2022
1 parent 6091e6b commit 7e9937b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
beautifulsoup4>=4.6.0
botocore>=1.12.36
platformdirs>=2.4.0 # This can be bumped after Python 3.6 is deprecated.
requests>=2.19.0
beautifulsoup4>=4.6.0
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
required = f.read().splitlines()

about = {}
with open(os.path.join(here, "tokendito", "__init__.py"), "r") as f:
exec(f.read(), about)
with open(os.path.join(here, "tokendito", "__init__.py")) as f:
for line in f:
if line.startswith("__"):
split_line = line.strip().split(" = ")
about[split_line[0]] = "".join(split_line[1:]).replace('"', "")

if "DEVBUILD" in os.environ:
now = datetime.datetime.now()
Expand Down
8 changes: 6 additions & 2 deletions tokendito/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from os.path import expanduser
import sys

from platformdirs import user_config_dir

__version__ = "2.0.0"
__title__ = "tokendito"
__description__ = "Get AWS STS tokens from Okta SSO"
Expand All @@ -22,8 +24,10 @@ class Config(object):
# Instantiated objects can get Class defaults with get_defaults()
_defaults = dict(
user=dict(
config_dir=os.path.join(expanduser("~"), ".aws"),
config_file=os.path.join(expanduser("~"), ".aws", "okta_auth"),
config_dir=user_config_dir(appname=__title__, appauthor=False),
config_file=os.path.join(
user_config_dir(appname=__title__, appauthor=False), f"{__title__}.ini"
),
config_profile="default",
encoding=sys.stdin.encoding,
loglevel="INFO",
Expand Down
2 changes: 1 addition & 1 deletion tokendito/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def parse_cli_args(args):
"--config-file",
dest="user_config_file",
default=config.user["config_file"],
help="Use an alternative configuration file",
help=f"Use an alternative configuration file. Defaults to {config.user['config_file']}",
)
parser.add_argument(
"--loglevel",
Expand Down

0 comments on commit 7e9937b

Please sign in to comment.