Skip to content

Commit

Permalink
Merge pull request #28 from m3brown/plz.yml
Browse files Browse the repository at this point in the history
recommend not-hidden plz.yaml filename
  • Loading branch information
m3brown committed Dec 5, 2021
2 parents 7b0de18 + 0e632f4 commit 10ed363
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 22 deletions.
14 changes: 7 additions & 7 deletions README.md
Expand Up @@ -28,14 +28,14 @@ pip install plz-cmd

### Example

plz looks for a `.plz.yaml` file either in the current directory or in the root
plz looks for a `plz.yaml` file either in the current directory or in the root
of the git repo you're currently in. This file can (and should) be checked into
version control.

For a .plz.yaml file located in the git root directory, commands run will be
For a plz.yaml file located in the git root directory, commands run will be
executed relative to that directory, not the current directory.

Suppose we have the following `.plz.yaml` file:
Suppose we have the following `plz.yaml` file:

```yaml
commands:
Expand Down Expand Up @@ -80,26 +80,26 @@ the current directory when running the command. Using this repo as an example:

```
bash$ ls .*.yaml
.plz.yaml .pre-commit-config.yaml
plz.yaml .pre-commit-config.yaml
bash$ cd plz
bash$ plz ls ../.*.yaml
[INFO] Using config: /path/plz/.plz.yaml
[INFO] Using config: /path/plz/plz.yaml
===============================================================================
Running command: ls
===============================================================================
.plz.yaml
plz.yaml
.pre-commit-config.yaml
[INFO] Process complete, return code: 0
bash$ plz ls __*.py
[INFO] Using config: /path/plz/.plz.yaml
[INFO] Using config: /path/plz/plz.yaml
===============================================================================
Running command: ls
Expand Down
File renamed without changes.
31 changes: 21 additions & 10 deletions plz/config.py
Expand Up @@ -43,7 +43,7 @@ def invalid_yaml(filename):
"""
Error parsing yaml config: {}
For more information on .plz.yaml formatting, visit {}
For more information on plz.yaml formatting, visit {}
""".format(
filename, DOC_URL
)
Expand Down Expand Up @@ -73,17 +73,28 @@ def load_config(filename):
raise InvalidYamlException(filename)


def find_file(filename):
if os.path.isfile(filename):
return (filename, None)
else:
root = git_root().rstrip("/")
full_path = os.path.join(root, filename)
if os.path.isfile(full_path):
return (full_path, root)


def plz_config():
filename = ".plz.yaml"
try:
if os.path.isfile(filename):
return (load_config(filename), None)
else:
root = git_root().rstrip("/")
full_path = os.path.join(root, filename)
if os.path.isfile(full_path):
return (load_config(full_path), root)
raise NoFileException
match = find_file("plz.yaml")
if not match:
match = find_file(".plz.yaml")
if match:
print_error(
"DEPRECATION WARNING: Please rename '.plz.yaml' to 'plz.yaml'"
)
else:
raise NoFileException
return (load_config(match[0]), match[1])
except NoFileException:
invalid_directory()
except InvalidYamlException as e:
Expand Down
24 changes: 21 additions & 3 deletions tests/config_test.py
Expand Up @@ -33,7 +33,7 @@ def test_plz_config_detects_local_file(mock_load_config, mock_isfile):
plz_config()

# Assert
mock_load_config.assert_called_with(".plz.yaml")
mock_load_config.assert_called_with("plz.yaml")


@patch("os.path.isfile")
Expand All @@ -51,7 +51,25 @@ def test_plz_config_falls_back_to_git_root_file(
plz_config()

# Assert
mock_load_config.assert_called_with("{}/.plz.yaml".format(test_path))
mock_load_config.assert_called_with("{}/plz.yaml".format(test_path))


@patch("os.path.isfile")
@patch("plz.config.git_root")
@patch("plz.config.load_config")
def test_plz_config_falls_back_to_legacy_filename(
mock_load_config, mock_git_root, mock_isfile
):
# Arrange
mock_isfile.side_effect = [False, False, True]
mock_git_root.return_value = "git"

# Act
plz_config()

# Assert
assert mock_isfile.call_count == 3
mock_load_config.assert_called_with(".plz.yaml")


@patch("os.path.isfile")
Expand Down Expand Up @@ -116,7 +134,7 @@ def test_plz_config_handles_extra_trailing_slash(
plz_config()

# Assert
mock_load_config.assert_called_with("{}/.plz.yaml".format(test_path))
mock_load_config.assert_called_with("{}/plz.yaml".format(test_path))


@patch("{}.open".format(builtins_module))
Expand Down
4 changes: 2 additions & 2 deletions tests/run_command_test.py
Expand Up @@ -84,7 +84,7 @@ def test_run_command_glob_with_cwd(capfd):
"""
Integration test
Scenario: the .plz.yaml file is "located" in the plz directory.
Scenario: the plz.yaml file is "located" in the plz directory.
In this case, the user will be running something like: `plz ls`
"""
Expand All @@ -105,7 +105,7 @@ def test_run_command_glob_with_cwd_and_args(capfd):
"""
Integration test
Scenario: the .plz.yaml file is "located" in the root of this repo, but
Scenario: the plz.yaml file is "located" in the root of this repo, but
the command is run from the child plz directory.
In this case, the user will be running something like: `plz ls ../*.md`
Expand Down

0 comments on commit 10ed363

Please sign in to comment.