From a58261fc396bb7a713fe292c71df4f4d72b8d9e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Tue, 21 Jan 2020 07:31:26 -0800 Subject: [PATCH] tree-wide: move CLI into new west.app package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- MANIFEST.in | 2 +- setup.py | 2 +- src/west/app/README.txt | 8 ++++++++ src/west/app/__init__.py | 3 +++ src/west/{commands => app}/config.py | 0 src/west/{ => app}/main.py | 4 ++-- src/west/{commands => app}/project.py | 0 src/west/{commands/__init__.py => commands.py} | 3 ++- src/west/{commands => }/west-commands-schema.yml | 0 tests/test_help.py | 2 +- 10 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 src/west/app/README.txt create mode 100644 src/west/app/__init__.py rename src/west/{commands => app}/config.py (100%) rename src/west/{ => app}/main.py (99%) rename src/west/{commands => app}/project.py (100%) rename src/west/{commands/__init__.py => commands.py} (99%) rename src/west/{commands => }/west-commands-schema.yml (100%) diff --git a/MANIFEST.in b/MANIFEST.in index bbc131d..2818531 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/setup.py b/setup.py index 97c7470..7089d1e 100644 --- a/setup.py +++ b/setup.py @@ -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',)}, ) diff --git a/src/west/app/README.txt b/src/west/app/README.txt new file mode 100644 index 0000000..83e8abd --- /dev/null +++ b/src/west/app/README.txt @@ -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. diff --git a/src/west/app/__init__.py b/src/west/app/__init__.py new file mode 100644 index 0000000..9d49dc4 --- /dev/null +++ b/src/west/app/__init__.py @@ -0,0 +1,3 @@ +# Copyright (c) 2020, Nordic Semiconductor ASA + +# nothing here diff --git a/src/west/commands/config.py b/src/west/app/config.py similarity index 100% rename from src/west/commands/config.py rename to src/west/app/config.py diff --git a/src/west/main.py b/src/west/app/main.py similarity index 99% rename from src/west/main.py rename to src/west/app/main.py index 5ef3f56..a22cba5 100755 --- a/src/west/main.py +++ b/src/west/app/main.py @@ -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 diff --git a/src/west/commands/project.py b/src/west/app/project.py similarity index 100% rename from src/west/commands/project.py rename to src/west/app/project.py diff --git a/src/west/commands/__init__.py b/src/west/commands.py similarity index 99% rename from src/west/commands/__init__.py rename to src/west/commands.py index 88872e7..e9be819 100644 --- a/src/west/commands/__init__.py +++ b/src/west/commands.py @@ -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 # diff --git a/src/west/commands/west-commands-schema.yml b/src/west/west-commands-schema.yml similarity index 100% rename from src/west/commands/west-commands-schema.yml rename to src/west/west-commands-schema.yml diff --git a/tests/test_help.py b/tests/test_help.py index c229ac4..734243c 100644 --- a/tests/test_help.py +++ b/tests/test_help.py @@ -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):