forked from platformio/platformio-core
Allow to skip saving of package dependencies to the "platformio.ini" // Issue #3373
This commit is contained in:
1 parent
eba4231cdc
commit
2201214717
5 files changed
+256
-7
No files matched your search
@@ -89,14 +89,18 @@ def test_project(clirunner, validate_cliresult, isolated_pio_core, tmp_path):
|
||||
)
|
||||
validate_cliresult(result)
|
||||
with fs.cd(str(project_dir)):
|
||||
config = ProjectConfig()
|
||||
lm = LibraryPackageManager(
|
||||
os.path.join(ProjectConfig().get("platformio", "libdeps_dir"), "devkit")
|
||||
os.path.join(config.get("platformio", "libdeps_dir"), "devkit")
|
||||
)
|
||||
assert pkgs_to_names(lm.get_installed()) == ["DallasTemperature", "OneWire"]
|
||||
assert pkgs_to_names(ToolPackageManager().get_installed()) == [
|
||||
"framework-arduino-avr-attiny",
|
||||
"toolchain-atmelavr",
|
||||
]
|
||||
assert config.get("env:devkit", "lib_deps") == [
|
||||
"milesburton/DallasTemperature@^3.9.1"
|
||||
]
|
||||
|
||||
|
||||
def test_unknown_project_dependencies(
|
||||
@@ -175,6 +179,25 @@ def test_custom_project_libraries(
|
||||
# do not expect any platforms/tools
|
||||
assert not os.path.exists(config.get("platformio", "platforms_dir"))
|
||||
assert not os.path.exists(config.get("platformio", "packages_dir"))
|
||||
# check saved deps
|
||||
assert config.get("env:devkit", "lib_deps") == [
|
||||
"bblanchon/ArduinoJson@^6.19.2",
|
||||
]
|
||||
|
||||
# install library without saving to config
|
||||
result = clirunner.invoke(
|
||||
package_install_cmd,
|
||||
["-e", "devkit", "-l", "nanopb/Nanopb@^0.4.6", "--no-save"],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
config = ProjectConfig()
|
||||
lm = LibraryPackageManager(
|
||||
os.path.join(config.get("platformio", "libdeps_dir"), "devkit")
|
||||
)
|
||||
assert pkgs_to_names(lm.get_installed()) == ["ArduinoJson", "Nanopb"]
|
||||
assert config.get("env:devkit", "lib_deps") == [
|
||||
"bblanchon/ArduinoJson@^6.19.2",
|
||||
]
|
||||
|
||||
# unknown libraries
|
||||
result = clirunner.invoke(
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from platformio.package.meta import PackageSpec
|
||||
from platformio.project.config import ProjectConfig
|
||||
from platformio.project.savedeps import save_project_dependencies
|
||||
|
||||
PROJECT_CONFIG_TPL = """
|
||||
[env]
|
||||
board = uno
|
||||
framework = arduino
|
||||
|
||||
[env:bare]
|
||||
|
||||
[env:release]
|
||||
platform = platformio/atmelavr
|
||||
lib_deps =
|
||||
milesburton/DallasTemperature@^3.8
|
||||
|
||||
[env:debug]
|
||||
platform = platformio/atmelavr@^3.4.0
|
||||
lib_deps =
|
||||
milesburton/DallasTemperature@^3.9.1
|
||||
bblanchon/ArduinoJson
|
||||
"""
|
||||
|
||||
|
||||
def test_save_libraries(tmp_path):
|
||||
project_dir = tmp_path / "project"
|
||||
project_dir.mkdir()
|
||||
(project_dir / "platformio.ini").write_text(PROJECT_CONFIG_TPL)
|
||||
specs = [
|
||||
PackageSpec("milesburton/DallasTemperature@^3.9"),
|
||||
PackageSpec("adafruit/Adafruit GPS Library@^1.6.0"),
|
||||
PackageSpec("https://github.com/nanopb/nanopb.git"),
|
||||
]
|
||||
|
||||
# add to the sepcified environment
|
||||
save_project_dependencies(
|
||||
str(project_dir), specs, scope="lib_deps", action="add", environments=["debug"]
|
||||
)
|
||||
config = ProjectConfig.get_instance(str(project_dir / "platformio.ini"))
|
||||
assert config.get("env:debug", "lib_deps") == [
|
||||
"bblanchon/ArduinoJson",
|
||||
"milesburton/DallasTemperature@^3.9",
|
||||
"adafruit/Adafruit GPS Library@^1.6.0",
|
||||
"https://github.com/nanopb/nanopb.git",
|
||||
]
|
||||
assert config.get("env:bare", "lib_deps") == []
|
||||
assert config.get("env:release", "lib_deps") == [
|
||||
"milesburton/DallasTemperature@^3.8"
|
||||
]
|
||||
|
||||
# add to the the all environments
|
||||
save_project_dependencies(str(project_dir), specs, scope="lib_deps", action="add")
|
||||
config = ProjectConfig.get_instance(str(project_dir / "platformio.ini"))
|
||||
assert config.get("env:debug", "lib_deps") == [
|
||||
"bblanchon/ArduinoJson",
|
||||
"milesburton/DallasTemperature@^3.9",
|
||||
"adafruit/Adafruit GPS Library@^1.6.0",
|
||||
"https://github.com/nanopb/nanopb.git",
|
||||
]
|
||||
assert config.get("env:bare", "lib_deps") == [
|
||||
"milesburton/DallasTemperature@^3.9",
|
||||
"adafruit/Adafruit GPS Library@^1.6.0",
|
||||
"https://github.com/nanopb/nanopb.git",
|
||||
]
|
||||
assert config.get("env:release", "lib_deps") == [
|
||||
"milesburton/DallasTemperature@^3.9",
|
||||
"adafruit/Adafruit GPS Library@^1.6.0",
|
||||
"https://github.com/nanopb/nanopb.git",
|
||||
]
|
||||
|
||||
# remove deps from env
|
||||
save_project_dependencies(
|
||||
str(project_dir),
|
||||
[PackageSpec("milesburton/DallasTemperature")],
|
||||
scope="lib_deps",
|
||||
action="remove",
|
||||
environments=["release"],
|
||||
)
|
||||
config = ProjectConfig.get_instance(str(project_dir / "platformio.ini"))
|
||||
assert config.get("env:release", "lib_deps") == [
|
||||
"adafruit/Adafruit GPS Library@^1.6.0",
|
||||
"https://github.com/nanopb/nanopb.git",
|
||||
]
|
||||
# invalid requirements
|
||||
save_project_dependencies(
|
||||
str(project_dir),
|
||||
[PackageSpec("adafruit/Adafruit GPS Library@^9.9.9")],
|
||||
scope="lib_deps",
|
||||
action="remove",
|
||||
environments=["release"],
|
||||
)
|
||||
config = ProjectConfig.get_instance(str(project_dir / "platformio.ini"))
|
||||
assert config.get("env:release", "lib_deps") == [
|
||||
"https://github.com/nanopb/nanopb.git",
|
||||
]
|
||||
|
||||
# remove deps from all envs
|
||||
save_project_dependencies(
|
||||
str(project_dir), specs, scope="lib_deps", action="remove"
|
||||
)
|
||||
config = ProjectConfig.get_instance(str(project_dir / "platformio.ini"))
|
||||
assert config.get("env:debug", "lib_deps") == [
|
||||
"bblanchon/ArduinoJson",
|
||||
]
|
||||
assert config.get("env:bare", "lib_deps") == []
|
||||
assert config.get("env:release", "lib_deps") == []
|
||||
Reference in new issue
Block a user