Skip to content

Commit

Permalink
messages: support appdirs user_log_dir for darwin
Browse files Browse the repository at this point in the history
appdirs.user_log_dir takes appname as the first parameter and while
the code path works when it is None for windows and linux, it runs
`os.path.expandpath("~/...", appname)` and darwin which fails as
appname is None.

https://github.com/ActiveState/appdirs/blob/48357882e5c095003e10f8351b405bf54e41424f/appdirs.py#L395

Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
  • Loading branch information
sergiusens committed Oct 18, 2021
1 parent a0e36d0 commit 26ebe16
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
tests:
strategy:
matrix:
os: [ubuntu-18.04, ubuntu-20.04]
os: [macos-10.15, ubuntu-18.04, ubuntu-20.04]
python-version: [3.8, 3.9]

runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion craft_cli/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _get_log_filepath(appname: str) -> pathlib.Path:
Existing files are not renamed (no need, as each name is unique) nor gzipped (they may
be currently in use by another process).
"""
basedir = pathlib.Path(appdirs.user_log_dir()) / appname
basedir = pathlib.Path(appdirs.user_log_dir(appname))
filename = f"{appname}-{datetime.now():%Y%m%d-%H%M%S.%f}.log"

# ensure the basedir is there
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_messages_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_log_dir(tmp_path, monkeypatch):
"""Provide a test log filepath, also fixing appdirs to use a temp dir."""
dirpath = tmp_path / "testlogdir"
dirpath.mkdir()
monkeypatch.setattr(appdirs, "user_log_dir", lambda: dirpath)
monkeypatch.setattr(appdirs, "user_log_dir", lambda appname: dirpath / appname)
return dirpath


Expand Down Expand Up @@ -145,7 +145,7 @@ def test_getlogpath_ignore_other_files(test_log_dir, monkeypatch):
def test_getlogpath_deep_dirs(tmp_path, monkeypatch):
"""The log directory is inside a path that does not exist yet."""
dirpath = tmp_path / "foo" / "bar" / "testlogdir"
monkeypatch.setattr(appdirs, "user_log_dir", lambda: dirpath)
monkeypatch.setattr(appdirs, "user_log_dir", lambda appname: dirpath / appname)
fpath = _get_log_filepath("testapp")

# check the file is inside the proper dir and that it exists
Expand Down

0 comments on commit 26ebe16

Please sign in to comment.