Rename pio project data to the pio project metadata command

This commit is contained in:
Ivan Kravets
2022-05-15 16:57:27 +03:00
parent 7acae6461e
commit 9163e9e67d
5 changed files with 85 additions and 66 deletions

2
docs

Submodule docs updated: 5e906bbc75...1f171d4bfd

View File

@ -15,16 +15,16 @@
import click
from platformio.project.commands.config import project_config_cmd
from platformio.project.commands.data import project_data_cmd
from platformio.project.commands.init import project_init_cmd
from platformio.project.commands.metadata import project_metadata_cmd
@click.group(
"project",
commands=[
project_config_cmd,
project_data_cmd,
project_init_cmd,
project_metadata_cmd,
],
short_help="Project Manager",
)

View File

@ -99,12 +99,12 @@ def install_project_dependencies(options):
for env in config.envs():
if environments and env not in environments:
continue
if not options["silent"]:
if not options.get("silent"):
click.echo(
"Resolving %s environment packages..." % click.style(env, fg="cyan")
)
already_up_to_date = not install_project_env_dependencies(env, options)
if not options["silent"] and already_up_to_date:
if not options.get("silent") and already_up_to_date:
click.secho("Already up-to-date.", fg="green")

View File

@ -1,61 +0,0 @@
# 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.
import json
import os
import click
from tabulate import tabulate
from platformio import fs
from platformio.project.config import ProjectConfig
from platformio.project.exception import NotPlatformIOProjectError
from platformio.project.helpers import is_platformio_project, load_build_metadata
@click.command("data", short_help="Dump data intended for IDE extensions/plugins")
@click.option(
"-d",
"--project-dir",
default=os.getcwd,
type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True),
)
@click.option("-e", "--environment", multiple=True)
@click.option("--json-output", is_flag=True)
def project_data_cmd(project_dir, environment, json_output):
if not is_platformio_project(project_dir):
raise NotPlatformIOProjectError(project_dir)
with fs.cd(project_dir):
config = ProjectConfig.get_instance()
config.validate(environment)
environment = list(environment or config.envs())
if json_output:
return click.echo(json.dumps(load_build_metadata(project_dir, environment)))
for envname in environment:
click.echo("Environment: " + click.style(envname, fg="cyan", bold=True))
click.echo("=" * (13 + len(envname)))
click.echo(
tabulate(
[
(click.style(name, bold=True), "=", json.dumps(value, indent=2))
for name, value in load_build_metadata(project_dir, envname).items()
],
tablefmt="plain",
)
)
click.echo()
return None

View File

@ -0,0 +1,80 @@
# 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.
import json
import os
import click
from tabulate import tabulate
from platformio import fs
from platformio.package.commands.install import install_project_dependencies
from platformio.project.config import ProjectConfig
from platformio.project.helpers import load_build_metadata
@click.command(
"metadata", short_help="Dump metadata intended for IDE extensions/plugins"
)
@click.option(
"-d",
"--project-dir",
default=os.getcwd,
type=click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True),
)
@click.option("-e", "--environment", "environments", multiple=True)
@click.option("--json-output", is_flag=True)
@click.option("--json-output-path", type=click.Path(resolve_path=True))
def project_metadata_cmd(project_dir, environments, json_output, json_output_path):
with fs.cd(project_dir):
config = ProjectConfig.get_instance()
config.validate(environments)
environments = list(environments or config.envs())
build_metadata = load_build_metadata(project_dir, environments)
if not json_output:
install_project_dependencies(
options=dict(
project_dir=project_dir,
environments=environments,
)
)
click.echo()
if json_output or json_output_path:
if json_output_path:
if os.path.isdir(json_output_path):
json_output_path = os.path.join(json_output_path, "metadata.json")
with open(json_output_path, mode="w", encoding="utf8") as fp:
json.dump(build_metadata, fp)
click.secho(f"Saved metadata to the {json_output_path}", fg="green")
if json_output:
click.echo(json.dumps(build_metadata))
return
for envname, metadata in build_metadata.items():
click.echo("Environment: " + click.style(envname, fg="cyan", bold=True))
click.echo("=" * (13 + len(envname)))
click.echo(
tabulate(
[
(click.style(name, bold=True), "=", json.dumps(value, indent=2))
for name, value in metadata.items()
],
tablefmt="plain",
)
)
click.echo()
return