tree-wide: move CLI into new west.app package

This relates to issue #38, the TL;DR of which is that we've never
gotten around to properly separating west's application internals from
its API in source code, and instead relied on documentation to spell
out exactly what the API was that users could rely on.

Let's start fixing that by moving everything users can't rely on into
a new west.app. This includes everything in west.commands except the
__init__ module, so we can just make that a new src/west/commands.py
file and have it be a module instead of a package. This lets its
pykwalify schema file, west-commands-schema.yml, sit next to it in
src/west, which is flatter than before.

The code changes in this commit (source lines changed, rather than
files just getting moved around) are:

- change the entry point in setup.py to west.app.main:main
- change some imports in src/west/app/main.py to import from
  west.app instead of west.commands
- add a new src/west/app/__init__.py, since we're not using
  namespace packages
- changes in MANIFEST.in and test_help.py to reflect new paths
- adjust some comments and docstrings

This change makes the API divide clearer. This in turn exposes some
problems with our use of west.log from west.manifest:

1. logging to stdout is a bad practice from a library
2. west.log also uses global state (which relates to #149 also)
   which non-command-line users won't have set up properly
   (this is an example of why #1 is true)

Subsequent commits will move to only using west.log from within
west.app.* and the existing deprecated west.build and west.cmake APIs,
which users should be migrating away from anyway.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2020-01-21 07:31:26 -08:00 committed by Marti Bolivar
parent 82cf0e3630
commit a58261fc39
10 changed files with 18 additions and 6 deletions

View File

@ -1,2 +1,2 @@
include src/west/commands/west-commands-schema.yml
include src/west/west-commands-schema.yml
include src/west/manifest-schema.yml

View File

@ -46,5 +46,5 @@ setuptools.setup(
'packaging',
],
python_requires='>=3.6',
entry_points={'console_scripts': ('west = west.main:main',)},
entry_points={'console_scripts': ('west = west.app.main:main',)},
)

8
src/west/app/README.txt Normal file
View File

@ -0,0 +1,8 @@
The west.app package contains the implementation of the west command
line tool and its built-in features.
Nothing in this package should be considered API.
In particular, authors of west extension commands should not rely on
the behavior this package or any of its contents to remain stable over
time.

3
src/west/app/__init__.py Normal file
View File

@ -0,0 +1,3 @@
# Copyright (c) 2020, Nordic Semiconductor ASA
# nothing here

View File

@ -29,9 +29,9 @@ from west import log
from west import configuration as config
from west.commands import WestCommand, extension_commands, \
CommandError, ExtensionCommandError
from west.commands.project import List, ManifestCommand, Diff, Status, \
from west.app.project import List, ManifestCommand, Diff, Status, \
SelfUpdate, ForAll, Init, Update, Topdir
from west.commands.config import Config
from west.app.config import Config
from west.manifest import Manifest, MalformedConfig, MalformedManifest, \
ManifestVersionError, ManifestImportFailed, \
ManifestProject, MANIFEST_REV_BRANCH

View File

@ -22,7 +22,6 @@ from west.util import escapes_directory
This package provides WestCommand, which is the common abstraction all
west commands subclass.
All built-in west commands are implemented as modules in this package.
This package also provides support for extension commands.'''
__all__ = ['CommandContextError', 'CommandError', 'WestCommand']
@ -131,6 +130,8 @@ class WestCommand(ABC):
return self.parser
#
# Mandatory subclass hooks
#

View File

@ -5,7 +5,7 @@ import itertools
import os
import sys
from west.main import BUILTIN_COMMAND_GROUPS
from west.app.main import BUILTIN_COMMAND_GROUPS
from conftest import cmd
def test_builtin_help_and_dash_h(west_init_tmpdir):