-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathproject.py
85 lines (64 loc) · 2.71 KB
/
project.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#
# Copyright (c) 2020-2021 Arm Limited and Contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
"""Defines the public API of the package."""
import pathlib
import logging
from typing import List, Any
from mbed_tools.project.mbed_program import MbedProgram, parse_url
from mbed_tools.project._internal.libraries import LibraryReferences
from mbed_tools.project._internal import git_utils
logger = logging.getLogger(__name__)
def import_project(url: str, dst_path: Any = None, recursive: bool = False) -> pathlib.Path:
"""Clones an Mbed project from a remote repository.
Args:
url: URL of the repository to clone.
dst_path: Destination path for the repository.
recursive: Recursively clone all project dependencies.
Returns:
The path the project was cloned to.
"""
git_data = parse_url(url)
url = git_data["url"]
if not dst_path:
dst_path = pathlib.Path(git_data["dst_path"])
git_utils.clone(url, dst_path)
if recursive:
libs = LibraryReferences(root=dst_path, ignore_paths=["mbed-os"])
libs.fetch()
return dst_path
def initialise_project(path: pathlib.Path, create_only: bool) -> None:
"""Create a new Mbed project, optionally fetching and adding mbed-os.
Args:
path: Path to the project folder. Created if it doesn't exist.
create_only: Flag which suppreses fetching mbed-os. If the value is `False`, fetch mbed-os from the remote.
"""
program = MbedProgram.from_new(path)
if not create_only:
libs = LibraryReferences(root=program.root, ignore_paths=["mbed-os"])
libs.fetch()
def deploy_project(path: pathlib.Path, force: bool = False) -> None:
"""Deploy a specific revision of the current Mbed project.
This function also resolves and syncs all library dependencies to the revision specified in the library reference
files.
Args:
path: Path to the Mbed project.
force: Force overwrite uncommitted changes. If False, the deploy will fail if there are uncommitted local
changes.
"""
libs = LibraryReferences(path, ignore_paths=["mbed-os"])
libs.checkout(force=force)
if list(libs.iter_unresolved()):
logger.info("Unresolved libraries detected, downloading library source code.")
libs.fetch()
def get_known_libs(path: pathlib.Path) -> List:
"""List all resolved library dependencies.
This function will not resolve dependencies. This will only generate a list of resolved dependencies.
Args:
path: Path to the Mbed project.
Returns:
A list of known dependencies.
"""
libs = LibraryReferences(path, ignore_paths=["mbed-os"])
return list(sorted(libs.iter_resolved()))