Commit Graph

376 Commits

Author SHA1 Message Date
Marti Bolivar f7256dd608 commands: project: use banner() and small_banner()
Now that these are abstractions in west.log, use them. No behavioral
changes expected.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar f71a85f42c log: add banner() and small_banner()
These are also from code in project.py. It will be useful to have
similar behavior for extensions available without duplicating code, in
case the behavior changes.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar d3d69dd3a8 commands: project: use get_projects() internally
Use self.manifest.get_projects() instead of the older implementation
of similar functionality. With the previous modification to west list
in place, no behavioral changes are expected.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar 3b3f8842fa commands: do not require cloned projects in west list
That's unnecessary for almost all the format strings, and users may
want to get information about projects they don't have cloned in order
to decide whether or not to clone them.

Use the fact that we're delaying evaluation of all git related
commands to exit out only if the sha of an uncloned project is
requested. Otherwise, all the information we need is in the manifest.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar b090710a05 manifest: add Manifest.get_projects()
This method allows finding a list of projects by name or path.
It's inspired by a helper method in projects.py, but has slightly
different semantics.

We'll move projects.py over to using it in the next patch, but having
this in manifest.py makes it API which is usable by extension commands.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar 15c8ad25b6 manifest: add Project.is_cloned(), from project.py
This is a generally useful thing to know, and, like all the other
Project.git() wrappers, a nondestructive operation on the project
itself.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar ab5f5dfdc2 commands: project: use util.canon_path()
Just a cleanup we ought to do while we're refactoring in here.

Use util.canon_path(path), which is normcase(abspath(path)), instead
of normcase(realpath(path)) (in one case) or reimplementing the same
functionality (in a couple of others).

Regarding realpath:

- there's no difference on Windows (where abspath
  and realpath are the same as symlinks are generally unsupported
  there).

- on Unixes, avoiding realpath() means that symbolic links are not
  derefenced, which is something we're trying to achieve in west in
  general to support symlinks better.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar db258e1087 commands: project: refactor exclude_manifest internal
Just a refactoring:

- remove exclude_manifest kwarg from _ProjectCommand._projects(),
  using isinstance(..., ManifestProject) in the only user instead
- rename some variables

No functional changes expected, but this will enable moving the code
elsewhere, to make it available to extension commands which also want
similar functionality.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar 52261a25f4 commands: project: use cached manifest instead of reparsing
Now that we have a self.manifest attribute which returns the manifest
when it's available and fails gracefully when it isn't, we can avoid
re-parsing the manifest in the project command implementations.

Note this change is more convenient to make after having introduced
_ProjectCommand to allow accessing per-instance state from each of
these commands, instead of using standalone module-level functions.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar 7694f88a07 commands: save the parsed manifest from main
This allows individual commands to avoid re-parsing. Properly
initialize it in the constructor (and topdir while we're here).

Use a property to get and set the manifest to allow us to fail with a
consistent error message when commands that require a manifest don't
get one.

We are basically saving the manifest similarly to topdir.

This opens up opportunities to avoid re-parsing the manifest
repeatedly.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar 7c0bbe8130 commands: project: remove dead code
Delete unused code.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar 23aed43841 commands: project: re-work parser and project boilerplate helpers
I find the _add_parser() and _project() helper methods a bit
opaque.

- The parser boilerplate being avoided could be made easier to read by
  being written in a more imperative style

- the project related helpers feel more like common instance
  methods (since they need the WestCommand instance or knowledge about
  its arguments to do their job) than true standalone functions.

Add a ProjectCommand superclass with helper methods for parsing and
doing some of the project related functionality instead of having
separate helper functions. This will pay dividends in subsequent
patches when we need to access more instance state.

We leave some other module-level functions, like _fetch(), where they
are for now to minimize changes.

Fix up tweak various pieces of help text while we're here -- there
were some really old mistakes left lying around from the 0.3 and 0.4
days. Yikes.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar b9cd8db734 test_project.py: remove invalid tests
The diff and status commands with extra arguments never worked.
Remove the invalid test cases for them. The next patch is going to
fail this sort of invocation with an error instead of silently
ignoring it.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar 4d977988b1 commands: project: improve sha detection
Rename _is_sha() to _maybe_sha() -- it's technically possible to have
commit refs which are branches that look like SHAs. Any branch name
that begins with a letter A-F an contains only hexadecimal characters
will work.

Allow revisions which are SHA prefixes. This makes it convenient to do
commands like "west init --mr some-sha-prefix" without the remote git
server barfing on an unknown ref.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar 50fdafe64e commands: project: move _fetch() around
The only caller of _fetch() is _update(). Move its definition to right
after _update()'s for readability. No functional changes expected.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar 37cf299420 manifest: allow Project.git to capture stderr
It's not always possible to silence git commands with -q, and it is
sometimes necessary to do so to avoid spurious output being shown to
the user.

One example is using "git cat-file -e SOME_REV" to test if a revision
has been fetched and is available in the local object database. This
prints to stderr if it isn't. The command or other code running
Project.git() in this case may be able to detect and deal with the
missing revision appropriately without wanting the user to see any
messages, and that's currently not possible.

Fix it by adding a capture_stderr that works the same way
capture_stdout does, but for stderr.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar 07f2f22416 manifest: only warn on missing git once
Use memoization to avoid warning multiple times from Project.git() if
the git executable can't be found.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-17 15:59:42 +02:00
Marti Bolivar b2ebf1e848 West 0.6.0
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-08-01 10:49:14 -06:00
Marti Bolivar 5e3482a512 West 0.6.0rc3
Error handling related to malformed manifests, and a new "west
manifest --validate".

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-29 23:01:59 +02:00
Marti Bolivar 4379118ffe commands: manifest: add --validate, tighten up error handling
Add a simple option for validating the current manifest. Make sure to
print useful errors from this command whenever the manifest is
invalid, rather than dumping stack or being opaque about what went
wrong.

Mention this as a possibility for debugging in west --help when things
go wrong.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-29 23:01:59 +02:00
Marti Bolivar 343fe58321 manifest: fix up manifest_path() errors
Document the possible exception behavior more clearly, and raise
FileNotFoundError if the manifest doesn't exist. This makes it
possible for users to detect this condition.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-29 23:01:59 +02:00
Marti Bolivar 3ec16effa8 manifest: propagate proper schema errors up
Save the SchemaError message in the MalformedManifest's string
representation if it is available. This makes it easier for users to
see what is wrong.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-29 23:01:59 +02:00
Marti Bolivar 856cb6354b main: fix --help output on invalid manifest
If the manifest can't be parsed, print a helpful message that the
extension commands can't be loaded.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-29 23:01:59 +02:00
Marti Bolivar 72be429c48 main: silence undesired pykwalify logging errors
We want to handle these ourselves. Without this patch, manifest parse
errors are printed in e.g. "west --version" output, which is not what
we want.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-29 23:01:59 +02:00
Marti Bolivar a14f676b64 main: do not barf on invalid manifest
If the manifest is invalid, we can still run some built-in
commands (like west config), or print help output.

Don't spit up an exception when we can't find extension commands to
allow built-ins to continue. Catch MalformedManifest and
MalformedConfig at top level to handle anything that slips through
without dumping stack.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-29 23:01:59 +02:00
Marti Bolivar 856a3fab69 main: use standard action='version'
This standard action prints the version and exits.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-29 23:01:59 +02:00
Marti Bolivar 90eb970251 west 0.6.0rc2
Compared to rc1, this adds a bugfix and a new feature, the project
'repo-path' attribute, to allow continuing use of remotes with
non-unique project names.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-26 11:33:01 +02:00
Marti Bolivar bfc6786636 manifest: allow 'repo-path' to specify the path within a remote
Users have provided negative feedback about some specifics related to
the new restriction that project names must be unique.

In particular, there is a use case for fetching the same project (the
LittleVGL graphics library) into two separate paths with two separate
revisions (to allow Kconfig to select between two major versions).

Since project names must now be unique, this would require the use of
the `url` attribute instead of `remote` (since the URL is of course
the same for both "projects", "remote.url-base + name" cannot be used
without violating name uniqueness).

To make it possible to keep using remotes, add a new optional
'repo-path' attribute to each project. If given, then 'remote.url-base
+ repo-path' forms the fetch URL.

Like remote itself, 'repo-path' cannot be combined with 'url'.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-26 11:33:01 +02:00
Marti Bolivar a4af95471a manifest: fix incorrect parsing with url + default remote
Manifests which use both default remotes and projects with URL
elements may incorrectly be rejected as invalid. Fix this and add a
regression test.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-26 11:33:01 +02:00
Marti Bolivar 5ccbbbada3 West 0.6.0rc1
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-23 11:02:55 +02:00
Marti Bolivar 33a8b0d62d Require setuptools >= 40.1.0
This is needed for find_namespace_packages. Make sure CI upgrades it
as well; the default shippable container doesn't meet the requirement.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-23 11:02:55 +02:00
Marti Bolivar d0bb31a170 README.rst: update for 0.6
That's nicer.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-23 11:02:55 +02:00
Marti Bolivar e3576399c6 manifest: docstring updates for 0.6
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-23 11:02:55 +02:00
Marti Bolivar 1d0b52d56b util: docstring updates for 0.6
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-23 11:02:55 +02:00
Marti Bolivar 1163500622 log: docstring updates for 0.6
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-23 11:02:55 +02:00
Marti Bolivar c4901486b0 configuration: docstring updates for 0.6
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-23 11:02:55 +02:00
Marti Bolivar e66743f8f7 commands: remove command.py, update docs
Move the contents of command.py to the west.commands package
__init__.py. This makes it possible to use autoclass on the
CommandError subclasses with :show-inheritance: in documentation.

Update some other docstrings to make documentation look nicer.

No functional change expected.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-07-23 11:02:55 +02:00
Marc Herbert 038a3df85f project: rephrase message "branch left behind, to fast forward... "
Invoking 'west update' without the '-r' (rebase) option typically causes
messages like this to be issued:

WARNING: left behind ci-tools branch "mybranch"; to fast forward back,
         use: git -C ../tools/ci-tools checkout mybranch

This is actually two messages somewhat confusingly compressed into one:
 1. How to switch back to "mybranch",
 2. "mybranch" is head of manifest-rev and doesn't need to be rebased.

Some issues:
- While 2. is secondary, it fills most of the space and draws most of the
  attention.
- Whenever plain git uses "fast forward" there doesn't seem to ever be
  any branch switching involved. Yet switching branch is the main
  message here.
- The unfortunate "forward back" sequence sounds weird when parsed too
  quickly.

As discussed and agreed with Marti on Slack, isolate and "downgrade"
the fast forward part of the message like this:

  to switch back to it (fast-forward), use: git checkout...

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-06-18 13:56:41 -06:00
Marti Bolivar fdb5fd127d .shippable.yml: upgrade pip to avoid 3.4 shippable failure
A tox dependency (pluggy) is depending on pathlib2 for python 3.4
only. The version of pip available in the VM (7.x series) is too old
to support "install this only on this version of Python", causing a
failure due to a missing dependency.

"Fix" that by upgrading pip.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-06-07 11:37:48 +02:00
Marti Bolivar 4dd845d8d3 west list: compatibility-breaking improvements
- The default west list format string is not particularly readable
  most of the time. Tweak it so it's better.

- replace multi-word strings like "(not set)" with single word
  equivalents like "N/A", which are easier to deal with in pipelines
  to cut, awk, etc.

- add a new {sha} format specifier that always produces a 40-character
  SHA, or the string N/A padded to the correct length.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-06-07 11:37:48 +02:00
Marti Bolivar 5dbc3e9b0d configuration: move use_colors to private log helper
This lets us call print() when we can't parse the value properly
instead of dumping stack without violating the principle that all
output from west is done by the west.log module.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-30 11:39:05 -06:00
Marti Bolivar 0da14440c6 commands: config: add -d and -D options for deleting
These allow the user to delete existing options.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-30 11:39:05 -06:00
Marti Bolivar 4fe9d4a042 configuration: add delete_config()
We currently have no way to delete options once set. This is not good
for users that want to delete things so they go back to their default
values. Add a library API and tests for this; we'll extend the config
command with options that use them next.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-30 11:39:05 -06:00
Marti Bolivar 4636b3def2 configuration: always use configobj
Delete the shim that tried to use ConfigParser, which was introduced
as a shim during development while we didn't have a release out that
had a dependency on configobj. We do now, and it's no longer needed.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-30 11:39:05 -06:00
Marti Bolivar 46ca8354bd conftest.py: add license/copyright header
This was missing.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-30 11:39:05 -06:00
Marti Bolivar 6cf0a0236b configuration: allow environment overrides
Add three new environment variables which can be used to override the
configuration file locations: WEST_CONFIG_SYSTEM, WEST_CONFIG_GLOBAL,
and WEST_CONFIG_LOCAL.

Use them in the tests. This also has the beneficial side effect of
making sure that "real" system settings do not interfere with the test
environment.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-30 11:39:05 -06:00
Marti Bolivar b94b71bbfa tests: allow cmd() to use non-standard environment
We'll use this the next patch. It's useful for isolation, because the
environment is one of the things that does live on between tests.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-30 11:39:05 -06:00
Marti Bolivar 06683b791c commands: config: add --list option
This prints all existing config options and their values.
It can be combined with the --system, --global, and --local options
to just list the contents of those files.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-30 11:39:05 -06:00
Marti Bolivar 79e7b5b3e1 commands: config: trivial refactor
Factor out read/write helpers. This is useless now but will keep the
code clean later, when we add more things this command can do.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-30 11:39:05 -06:00
Marti Bolivar 52f1f48de6 commands: config: error out if value is unset
This makes sense, and matches git config's behavior too. Stay silent
by default, but log.dbg() what happened.

Add a test case, too.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2019-05-30 11:39:05 -06:00