These are just for safety, so mypy can yell at us if we break any
rules by assuming an os.PathLike is a str.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Rely on pathlib instead, which handles canonicalization on Windows in
a much better way.
Start using os.fspath(pathlike) instead of str(pathlike). After
studying some CPython sources that deal with path-like objects, this
seems to be the recommended thing to do.
The reason why is that not all os.PathLike objects are going to return
their file system path representations when str() is called on them;
even though the pathlib ones do.
I therefore want to use os.fspath() everywhere instead of str(), even
if it's sometimes safe to use str(). That way, when we inevitably
start copy/pasting code around, it will still do the right thing when
we're dealing with the general case os.PathLike behavior, e.g. from a
user-supplied argument to an API function, which may do something
different in its __str__ than its __fspath__ method.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Move the PathType type alias from west.manifest to west.util and use
it there to type-annotate individual functions as accepting either str
or an os.PathLike.
Change the source code as needed to make this true. Delete a stale
comment mentioning the long-gone bootstrapper while at it.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Add an assertion about a program invariant that will matter when
west.util gets type annotated.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
The subprocess's Popen constructor takes a cwd kwarg. Since v3.6, this
can be a PathLike on POSIX operating systems, but Windows didn't
officially get this feature until 3.7. This ability was back-ported
onto the v3.6 series after v3.6.1-rc1, but v3.6.0 doesn't have it.
To handle that, force cwd to a str on versions below 3.6.1 if it isn't
one already. Add a regression test just for fun, though west's CI
uses 3.6.8, so it passes even without the manifest.py patch.
It seems very unlikely to be an issue in practice since nobody should
be using 3.6.0, but I spent the time tracking this down from the docs
and (irrationally) feel like something ought to be done about it.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Add missing type annotations. Paths are generally 'str' for now,
though there is one place where we can use the PathType value we
defined in a previous commit.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
As we did for previous patches, Project has to be done as a str at
this part of the file, since we haven't gotten around to defining
Project yet.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Now that the internal callers are using the right types,
annotate the validate() and manifest_path() arguments.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This is used internally to pass along an import context in a way that
can't casually be done by a user, since '-' is not a valid character
in an identifier.
Adding asserts about its value won't hurt, and will help convince the
type checker that this is doing the right thing later on.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
The posixpath() property if checks are copy/pasted from abspath, but
they aren't quite right. The _posixpath attribute really cares about
whether self.abspath is None, not self.topdir. Fix it.
This shouldn't affect correctness because self.abspath is non-None
exactly when self.topdir is, but is cleaner readability wise and will
make it easier to type annotate this property.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
These are just duplicating functionality already present in the parent
class. The abspath property has to stay because, unlike Project,
ManifestProject might have a self._path set to None (... which,
looking at it again, is yet another reason it's not sensible to treat
it like a Project).
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Change the url, revision, and clone_depth properties to plain old
attributes, changing url from None to the empty string. This will be
used to make it possible to type annotate Project in a subsequent
commit.
This seems like even more evidence that ManifestProject is not a
Project in a subtyping sense, should not have been treated like one,
and should be removed (#327).
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
We should be passing the actual version string to
ManifestVersionError, not the parsed version object.
Do the same in the f-string just for consistency.
Caught by mypy.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
We were forced to allow multiple values into west_commands during the
west 0.7 dev cycle as a result of the way manifest imports work, but
the way it was implemented needs a bit of fixing up.
Make sure that Project and ManifestProject can take either a list or
a string of west_commands and that the resulting object attribute is
always a list, for consistency. Fix the docstrings to make clear
what's going on. Adjust users in commands.py -- this is cleaner now.
Callers have had to cope with the possibility that this could be a
list since v0.7 was released, so this shouldn't break any up-to-date
extensions.
This patch also enables a schema relaxation where we could support
multiple extension spec YAML files in a single manifest written by
hand. But let's defer that work until someone actually asks for it.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
The SchemaError type's error message should be accessed via the msg()
property, not the underlying private instance variable.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This is partially being done to clean up and reorganize, but the
specific goal in mind is making it easier to add type information
to more functions and methods.
- make Manifest.projects a property, and ensure the underlying
_projects attribute is always a list
- move code around so that definitions of types are visible more
often when variables of those types are used. For instance, move
the Project definition above Manifest, because many variables
in the Manifest methods have type Project, List[Project], etc.
This is in my opinion a readability improvement, and also will allow
using the token Project as a type name from the Manifest class
definition later. Similar comments apply to named tuple definitions,
etc.
No functionality changes expected.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This reverts commit 5843eef713. We
figured out another way to accomplish the goal that this was done for,
so there's no reason to expose these details to the user now.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Added documentation to main() as it is now officially supported to
directly call main from west.app.main module.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
These changes introduce initial support for type hints. Support for mypy
static analysis on GitHub workflows has also been enabled.
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Some new flake8 errors are enabled by default now; fix them up:
./src/west/manifest.py:1633:47: E741 ambiguous variable name 'l'
./src/west/app/project.py:802:21: F541 f-string is missing placeholders
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
The output is kind of cluttered when many projects are available.
Let's silence output for projects with no diff when not in verbose mode.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
A few process changes from doing a point release, mainly that we'll
cut an alpha release instead of an RC. That's being done because
uploading an alpha is something a maintainer can just do, without
having to go through the usual "bump version.py" review process.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
If the user imports a manifest, and specifies its west-commands, like
this:
- name: zephyr
west-commands: scripts/west-commands.yml
where zephyr/west.yml also specifies a west-commands, then they get
warnings when the manifest is parsed, like this:
WARNING: ignoring project zephyr extension command "completion"; command "completion" is already defined as extension command
WARNING: ignoring project zephyr extension command "boards"; command "boards" is already defined as extension command
WARNING: ignoring project zephyr extension command "build"; command "build" is already defined as extension command
WARNING: ignoring project zephyr extension command "sign"; command "sign" is already defined as extension command
WARNING: ignoring project zephyr extension command "flash"; command "flash" is already defined as extension command
WARNING: ignoring project zephyr extension command "debug"; command "debug" is already defined as extension command
WARNING: ignoring project zephyr extension command "debugserver"; command "debugserver" is already defined as extension command
WARNING: ignoring project zephyr extension command "attach"; command "attach" is already defined as extension command
Filter duplicates when merging west commands during manifest parsing
to avoid this outcome.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Make the 'west update' output more helpful:
- If --keep-descendants is given, also run 'git status' to highlight a
dirty tree, etc. Also make the west output prefixed by 'west update';
it's clear what project is being worked on due to the earlier banner.
- if --rebase is given, do the same change to just use 'west update'
as an output prefix.
- if neither is given, remove --quiet and the small_banner() call. This
also shows information about a dirty tree.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Fixes: #378
When Zephyr is also the manifest repository then west fails to identify
ZEPHYR_BASE correctly as the project name is manifest, with path zephyr.
Therefore, before checking projects with path `zephyr` we first check if
the manifest repository has path == zephyr.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This is where we'll put notes for west maintainers.
For now, it includes information on cutting a release.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Fixes: #374
This commit ensures that west topdir always prints in posix style and
thus fixes an issue in windows where CMake fails to parse the path when
'\' is used as separator.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
With all the statistics gathering, this is getting pretty long and
hard to read. Let's factor it out into some new methods.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Track all operations which invoke a subprocess.
Track the total time in the update() call, and print out time spent
doing work not explicitly tracked.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>