Skip to content

Commit

Permalink
Merge pull request #36 from guidow/reverse_config_dir_order
Browse files Browse the repository at this point in the history
Reverse the order in which config files are loaded
  • Loading branch information
opalmer committed Jan 9, 2015
2 parents f4a19d1 + 12625b4 commit a1bc90c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
35 changes: 19 additions & 16 deletions pyfarm/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,21 +498,24 @@ def directories(self, validate=True, unversioned_only=False):

versions.append("") # the 'version free' directory

# If provided, append the root discovered in the environment
if self.environment_root is not None:
roots.append(join(self.environment_root, self.child_dir))
# If provided, insert the default root
if self.system_root: # could be empty in the environment
roots.append(join(self.system_root, self.child_dir))

# If provided, append the user directory
if self.user_root: # could be empty in the environment
if not WINDOWS:
roots.append(join(self.user_root, "." + self.child_dir))
else:
roots.append(join(self.user_root, self.child_dir))

# If provided append a local directory
if self.local_dir is not None:
roots.append(join(self.local_dir, self.child_dir))

# If provided, append the user directory
if self.user_root: # could be empty in the environment
roots.append(join(self.user_root, "." + self.child_dir))

# If provided, insert the default root
if self.system_root: # could be empty in the environment
roots.append(join(self.system_root, self.child_dir))
# If provided, append the root discovered in the environment
if self.environment_root is not None:
roots.append(join(self.environment_root, self.child_dir))

all_directories = []
existing_directories = []
Expand Down Expand Up @@ -549,12 +552,6 @@ def files(self, validate=True, unversioned_only=False):
filename = self.name + self.file_extension
existing_files = []

for directory in directories:
filepath = join(directory, filename)

if not validate or isfile(filepath):
existing_files.append(filepath)

if self.package_configuration is not None:
if not validate or isfile(self.package_configuration):
existing_files.append(self.package_configuration)
Expand All @@ -565,6 +562,12 @@ def files(self, validate=True, unversioned_only=False):
"to find %r but this path does not exist.",
self._name, self.package_configuration)

for directory in directories:
filepath = join(directory, filename)

if not validate or isfile(filepath):
existing_files.append(filepath)

if not existing_files: # pragma: no cover
logger.error(
"No configuration file(s) %s were found in %s",
Expand Down
24 changes: 12 additions & 12 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,22 +213,22 @@ def test_files_system_root(self):
split = config.split_version()
filename = config.name + config.file_extension
all_paths = [
join(config.environment_root, config.child_dir, split[0], filename),
join(config.environment_root, config.child_dir, split[1], filename),
join(config.environment_root, config.child_dir, split[2], filename),
join(config.environment_root, config.child_dir + os.sep, filename),
join(config.local_dir, config.child_dir, split[0], filename),
join(config.local_dir, config.child_dir, split[1], filename),
join(config.local_dir, config.child_dir, split[2], filename),
join(config.local_dir, config.child_dir + os.sep, filename),
join(config.user_root, "." + config.child_dir, split[0], filename),
join(config.user_root, "." + config.child_dir, split[1], filename),
join(config.user_root, "." + config.child_dir, split[2], filename),
join(config.user_root, "." + config.child_dir + os.sep, filename),
join(config.system_root, config.child_dir, split[0], filename),
join(config.system_root, config.child_dir, split[1], filename),
join(config.system_root, config.child_dir, split[2], filename),
join(config.system_root, config.child_dir + os.sep, filename),
join(config.user_root, "." + config.child_dir, split[0], filename),
join(config.user_root, "." + config.child_dir, split[1], filename),
join(config.user_root, "." + config.child_dir, split[2], filename),
join(config.user_root, "." + config.child_dir + os.sep, filename),
join(config.local_dir, config.child_dir, split[0], filename),
join(config.local_dir, config.child_dir, split[1], filename),
join(config.local_dir, config.child_dir, split[2], filename),
join(config.local_dir, config.child_dir + os.sep, filename),
join(config.environment_root, config.child_dir, split[0], filename),
join(config.environment_root, config.child_dir, split[1], filename),
join(config.environment_root, config.child_dir, split[2], filename),
join(config.environment_root, config.child_dir + os.sep, filename),
]
self.assertEqual(config.files(validate=False), all_paths)

Expand Down

0 comments on commit a1bc90c

Please sign in to comment.