-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change order of list returned by config_dirs() #168
base: main
Are you sure you want to change the base?
Changes from all commits
2eb3cc4
349e28f
9beffe6
26419cc
2ea0206
6112674
68e7ff9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -129,14 +129,20 @@ def find_package_path(name): | |||||
return os.path.dirname(os.path.abspath(filepath)) | ||||||
|
||||||
|
||||||
def xdg_config_home(): | ||||||
"""Return the value of the XDG_CONFIG_HOME | ||||||
environment variable if it is set and nonempty, | ||||||
and UNIX_DIR_FALLBACK otherwise | ||||||
""" | ||||||
config_path = os.getenv('XDG_CONFIG_HOME', UNIX_DIR_FALLBACK) | ||||||
return config_path if config_path != '' else UNIX_DIR_FALLBACK | ||||||
|
||||||
def xdg_config_dirs(): | ||||||
"""Returns a list of paths taken from the XDG_CONFIG_DIRS | ||||||
and XDG_CONFIG_HOME environment varibables if they exist | ||||||
environment variable if it exists and is nonempty | ||||||
""" | ||||||
paths = [] | ||||||
if 'XDG_CONFIG_HOME' in os.environ: | ||||||
paths.append(os.environ['XDG_CONFIG_HOME']) | ||||||
if 'XDG_CONFIG_DIRS' in os.environ: | ||||||
if 'XDG_CONFIG_DIRS' in os.environ and os.environ['XDG_CONFIG_DIRS'] != '': | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to look before leap here, just use the default fallback behavior (will return
Suggested change
|
||||||
paths.extend(os.environ['XDG_CONFIG_DIRS'].split(':')) | ||||||
else: | ||||||
paths.append('/etc/xdg') | ||||||
|
@@ -155,7 +161,7 @@ def config_dirs(): | |||||
paths = [] | ||||||
|
||||||
if platform.system() == 'Darwin': | ||||||
paths.append(UNIX_DIR_FALLBACK) | ||||||
paths.append(xdg_config_home()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. XDG does not apply to Darwin. These files should end up somewhere in |
||||||
paths.append(MAC_DIR) | ||||||
paths.extend(xdg_config_dirs()) | ||||||
|
||||||
|
@@ -166,13 +172,13 @@ def config_dirs(): | |||||
|
||||||
else: | ||||||
# Assume Unix. | ||||||
paths.append(UNIX_DIR_FALLBACK) | ||||||
paths.append(xdg_config_home()) | ||||||
paths.extend(xdg_config_dirs()) | ||||||
|
||||||
# Expand and deduplicate paths. | ||||||
# Expand and paths and remove duplicates and relative paths. | ||||||
out = [] | ||||||
for path in paths: | ||||||
path = os.path.abspath(os.path.expanduser(path)) | ||||||
if path not in out: | ||||||
path = os.path.expanduser(path) | ||||||
if path not in out and os.path.isabs(path): | ||||||
out.append(path) | ||||||
return out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty string is falsy. Use as a boolean.