Commit Graph

14 Commits

Author SHA1 Message Date
Pieter De Gendt d2d099031c tests: Format and sort imports
Apply isort on files in tests/

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-11-05 08:18:41 +01:00
Martí Bolívar 6702922356 tests: test_help: python implementation detail tweak
The argparse module changed some implementation details in in a way
that's causing a false failure in testing. Handle it.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2022-03-18 10:59:14 -07:00
Martí Bolívar d57aa43d6e tests: ensure we're run via tox
Otherwise, setup functions that set git config variables like
user.name are potentially dangerous to run.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-02-10 09:06:29 -08:00
Martí Bolívar a58261fc39 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>
2020-01-22 07:36:31 -05:00
Martí Bolívar e8fafed5cd tree-wide: add python file copyright headers
And update a couple.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-01-17 17:14:36 +01:00
Martí Bolívar 47b5f710e0 tree-wide: use f-strings more, tweak logs
Use f-strings instead of str.format() or string concatenation with +
whenever practical. Tweak a few log messages while we're here.

I may be getting a little f-string-happy, but I think having a single,
consistent style throughout the code base makes things easier to read,
and f-strings look like the natural default choice to me.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-01-16 09:18:30 -08:00
Martí Bolívar 885828ebc0 main.py: re-work, adding a new WestApp class
The main() function has gotten really long, and it's getting hard to
read. I want to break it up, but there's a fair bit of interdependent
state to manage.

Rather than using global variables, create a WestApp instance to
contain them all and use it instead. This helps with readability
without making #149 harder to do.

We'll extend this later to handle manifest imports.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2019-12-04 12:33:07 +01:00
Martí Bolívar ae784d516d tests: adjust for windows incompatibilities
Windows does a few things differently. Deal with it.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2019-11-18 11:17:57 +01:00
Martí Bolívar 564e1d4659 main: fix up help printing
We are getting an extra newline at the end of our help, which is
inconsistent with how argparse usually works and is causing tox issues
on Windows.

Avoid having an empty line at the end of help messages.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2019-11-18 11:17:57 +01:00
Marti Bolivar e2325ca348 main: reorganize some internals
This refactoring will make it easier to handle ManifestVersionError.

Make 'west help' invoke a WestCommand too. API improvements made over
time make this easy to do.

It also has the pleasant side effect of making it really easy for
"west --help init" to be equivalent to "west help init" instead of
"west --help".

It works slightly different in case of error, though
("west --help unknown" produces different output than "west help
unknown"). I can't fix that without breaking the argparse abstraction
barrier, though, so it's OK.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-10-15 14:16:40 +02:00
Marti Bolivar dc031a6385 main: fix west help <some-extension-command>
This slipped through the cracks when adding the manifest field to each
command instance in 7694f88 ("commands: save the parsed manifest from
main"). It only shows up for extensions -- built-ins work fine.

Add a regression test.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-09-06 12:39:52 -06:00
Marti Bolivar f170447619 tests: test_help cosmetics
Adjust some comments and remove parentheses (which are unnecessary in
assert statements in Python).

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-09-06 12:39:52 -06:00
Marti Bolivar ecb81be96b tests: fix test_help
There is a return that got in there that makes the test inoperative.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-09-06 12:39:52 -06:00
Marti Bolivar e19e7e61b5 tests: flatten the hierarchy
There's no good reason to have these tests in subdirectories. Flatten
them out. Keep the directory of invalid manifests separate to keep the
directory listing clean, though.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-20 11:06:53 +02:00