Skip to content

Commit

Permalink
app: Re-use constant WEST_DIR
Browse files Browse the repository at this point in the history
Use the literal constant WEST_DIR instead of using the same string
value scattered around the project.

Signed-off-by: Pieter De Gendt <[email protected]>
  • Loading branch information
pdgendt committed Oct 21, 2024
1 parent c3aadf5 commit 3ff5d52
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/west/app/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def do_run(self, args, _):
This forces west to search for a workspace there.
Try unsetting ZEPHYR_BASE and re-running this command.''')
else:
west_dir = Path(self.topdir) / '.west'
west_dir = Path(self.topdir) / WEST_DIR
msg = ("\n Hint: if you do not want a workspace there, \n"
" remove this directory and re-run this command:\n\n"
f" {west_dir}")
Expand Down Expand Up @@ -2094,7 +2094,7 @@ def projects_unknown(manifest, projects):
#

# Top-level west directory, containing west itself and the manifest.
WEST_DIR = '.west'
WEST_DIR = util.WEST_DIR

# Default manifest repository URL.
MANIFEST_URL_DEFAULT = 'https://github.com/zephyrproject-rtos/zephyr'
Expand Down
4 changes: 2 additions & 2 deletions src/west/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from typing import Any, Dict, Iterable, List, Optional, Tuple, TYPE_CHECKING
import warnings

from west.util import west_dir, WestNotFound, PathType
from west.util import WEST_DIR, west_dir, WestNotFound, PathType

class MalformedConfig(Exception):
'''The west configuration was malformed.
Expand Down Expand Up @@ -616,7 +616,7 @@ def _location(cfg: ConfigFile, topdir: Optional[PathType] = None,
return env['WEST_CONFIG_LOCAL']

if topdir:
return os.fspath(Path(topdir) / '.west' / 'config')
return os.fspath(Path(topdir) / WEST_DIR / 'config')

if find_local:
# Might raise WestNotFound!
Expand Down
6 changes: 4 additions & 2 deletions src/west/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# otherwise, but it doesn't seem worth it.
PathType = Union[str, os.PathLike]

WEST_DIR = '.west'

def escapes_directory(path: PathType, directory: PathType) -> bool:
'''Returns True if `path` escapes parent directory `directory`.
Expand Down Expand Up @@ -58,7 +60,7 @@ def west_dir(start: Optional[PathType] = None) -> str:
Raises WestNotFound if no .west directory is found.
'''
return os.path.join(west_topdir(start), '.west')
return os.path.join(west_topdir(start), WEST_DIR)

def west_topdir(start: Optional[PathType] = None,
fall_back: bool = True) -> str:
Expand All @@ -69,7 +71,7 @@ def west_topdir(start: Optional[PathType] = None,
cur_dir = pathlib.Path(start or os.getcwd())

while True:
if (cur_dir / '.west').is_dir():
if (cur_dir / WEST_DIR).is_dir():
return os.fspath(cur_dir)

parent_dir = cur_dir.parent
Expand Down

0 comments on commit 3ff5d52

Please sign in to comment.