Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dvc: rename plot to plots #3802

Merged
merged 2 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions dvc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
move,
params,
pipeline,
plot,
plots,
remote,
remove,
repro,
Expand Down Expand Up @@ -74,7 +74,7 @@
version,
update,
git_hook,
plot,
plots,
]


Expand Down
104 changes: 56 additions & 48 deletions dvc/command/plot.py β†’ dvc/command/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

from dvc.command.base import CmdBase, append_doc_link, fix_subparsers
from dvc.exceptions import DvcException
from dvc.repo.plot.data import WORKSPACE_REVISION_NAME
from dvc.repo.plots.data import WORKSPACE_REVISION_NAME

logger = logging.getLogger(__name__)


class CmdPLot(CmdBase):
class CmdPlots(CmdBase):
def _revisions(self):
raise NotImplementedError

Expand Down Expand Up @@ -79,12 +79,12 @@ def run(self):
return 0


class CmdPlotShow(CmdPLot):
class CmdPlotsShow(CmdPlots):
def _revisions(self):
return None


class CmdPlotDiff(CmdPLot):
class CmdPlotsDiff(CmdPlots):
def _revisions(self):
revisions = self.args.revisions or []
if len(revisions) <= 1:
Expand All @@ -95,143 +95,151 @@ def _revisions(self):


def add_parser(subparsers, parent_parser):
PLOT_HELP = (
PLOTS_HELP = (
"Generating plots for metrics stored in structured files "
"(JSON, CSV, TSV)."
)

plot_parser = subparsers.add_parser(
"plot",
plots_parser = subparsers.add_parser(
"plots",
parents=[parent_parser],
description=append_doc_link(PLOT_HELP, "plot"),
help=PLOT_HELP,
description=append_doc_link(PLOTS_HELP, "plots"),
help=PLOTS_HELP,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
plot_subparsers = plot_parser.add_subparsers(
plots_subparsers = plots_parser.add_subparsers(
dest="cmd",
help="Use `dvc plot CMD --help` to display command-specific help.",
help="Use `dvc plots CMD --help` to display command-specific help.",
)

fix_subparsers(plot_subparsers)
fix_subparsers(plots_subparsers)

SHOW_HELP = "Generate a plot image file from a metrics file."
plot_show_parser = plot_subparsers.add_parser(
SHOW_HELP = "Generate a plots image file from a metrics file."
plots_show_parser = plots_subparsers.add_parser(
"show",
parents=[parent_parser],
description=append_doc_link(SHOW_HELP, "plot/show"),
description=append_doc_link(SHOW_HELP, "plots/show"),
help=SHOW_HELP,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
plot_show_parser.add_argument(
plots_show_parser.add_argument(
"-t",
"--template",
nargs="?",
default=None,
help="File to be injected with data.",
)
plot_show_parser.add_argument(
plots_show_parser.add_argument(
"-f", "--file", default=None, help="Name of the generated file."
)
plot_show_parser.add_argument(
plots_show_parser.add_argument(
"-s",
"--select",
default=None,
help="Choose which field(s) or JSONPath to include in the plot.",
help="Choose which field(s) or JSONPath to include in the plots.",
)
plot_show_parser.add_argument(
plots_show_parser.add_argument(
"-x", default=None, help="Field name for x axis."
)
plot_show_parser.add_argument(
plots_show_parser.add_argument(
"-y", default=None, help="Field name for y axis."
)
plot_show_parser.add_argument(
plots_show_parser.add_argument(
"--stdout",
action="store_true",
default=False,
help="Print plot specification to stdout.",
help="Print plots specification to stdout.",
)
plot_show_parser.add_argument(
plots_show_parser.add_argument(
"--no-csv-header",
action="store_true",
default=False,
help="Required when CSV or TSV datafile does not have a header.",
)
plot_show_parser.add_argument(
plots_show_parser.add_argument(
"--no-html",
action="store_true",
default=False,
help="Do not wrap Vega plot JSON with HTML.",
)
plot_show_parser.add_argument("--title", default=None, help="Plot title.")
plot_show_parser.add_argument("--xlab", default=None, help="X axis title.")
plot_show_parser.add_argument("--ylab", default=None, help="Y axis title.")
plot_show_parser.add_argument(
plots_show_parser.add_argument("--title", default=None, help="Plot title.")
plots_show_parser.add_argument(
"--xlab", default=None, help="X axis title."
)
plots_show_parser.add_argument(
"--ylab", default=None, help="Y axis title."
)
plots_show_parser.add_argument(
"datafile", nargs="?", default=None, help="Metrics file to visualize",
)
plot_show_parser.set_defaults(func=CmdPlotShow)
plots_show_parser.set_defaults(func=CmdPlotsShow)

PLOT_DIFF_HELP = (
PLOTS_DIFF_HELP = (
"Plot differences in metrics between commits in the DVC "
"repository, or between the last commit and the workspace."
)
plot_diff_parser = plot_subparsers.add_parser(
plots_diff_parser = plots_subparsers.add_parser(
"diff",
parents=[parent_parser],
description=append_doc_link(PLOT_DIFF_HELP, "plot/diff"),
help=PLOT_DIFF_HELP,
description=append_doc_link(PLOTS_DIFF_HELP, "plots/diff"),
help=PLOTS_DIFF_HELP,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
plot_diff_parser.add_argument(
plots_diff_parser.add_argument(
"-t",
"--template",
nargs="?",
default=None,
help="File to be injected with data.",
)
plot_diff_parser.add_argument(
plots_diff_parser.add_argument(
"-d",
"--datafile",
nargs="?",
default=None,
help="Metrics file to visualize",
)
plot_diff_parser.add_argument(
plots_diff_parser.add_argument(
"-f", "--file", default=None, help="Name of the generated file."
)
plot_diff_parser.add_argument(
plots_diff_parser.add_argument(
"-s",
"--select",
default=None,
help="Choose which field(s) or JSONPath to include in the plot.",
)
plot_diff_parser.add_argument(
plots_diff_parser.add_argument(
"-x", default=None, help="Field name for x axis."
)
plot_diff_parser.add_argument(
plots_diff_parser.add_argument(
"-y", default=None, help="Field name for y axis."
)
plot_diff_parser.add_argument(
plots_diff_parser.add_argument(
"--stdout",
action="store_true",
default=False,
help="Print plot specification to stdout.",
)
plot_diff_parser.add_argument(
plots_diff_parser.add_argument(
"--no-csv-header",
action="store_true",
default=False,
help="Provided CSV ot TSV datafile does not have a header.",
)
plot_diff_parser.add_argument(
plots_diff_parser.add_argument(
"--no-html",
action="store_true",
default=False,
help="Do not wrap Vega plot JSON with HTML.",
)
plot_diff_parser.add_argument("--title", default=None, help="Plot title.")
plot_diff_parser.add_argument("--xlab", default=None, help="X axis title.")
plot_diff_parser.add_argument("--ylab", default=None, help="Y axis title.")
plot_diff_parser.add_argument(
plots_diff_parser.add_argument("--title", default=None, help="Plot title.")
plots_diff_parser.add_argument(
"--xlab", default=None, help="X axis title."
)
plots_diff_parser.add_argument(
"--ylab", default=None, help="Y axis title."
)
plots_diff_parser.add_argument(
"revisions", nargs="*", default=None, help="Git commits to plot from",
)
plot_diff_parser.set_defaults(func=CmdPlotDiff)
plots_diff_parser.set_defaults(func=CmdPlotsDiff)
4 changes: 2 additions & 2 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Repo(object):
from dvc.repo.get import get
from dvc.repo.get_url import get_url
from dvc.repo.update import update
from dvc.repo.plot import plot
from dvc.repo.plots import plot

def __init__(self, root_dir=None):
from dvc.state import State
Expand Down Expand Up @@ -426,7 +426,7 @@ def stages(self):

@cached_property
def plot_templates(self):
from dvc.repo.plot.template import PlotTemplates
from .plots.template import PlotTemplates

return PlotTemplates(self.dvc_dir)

Expand Down
9 changes: 5 additions & 4 deletions dvc/repo/plot/__init__.py β†’ dvc/repo/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

from dvc.exceptions import DvcException
from dvc.repo import locked
from dvc.repo.plot.data import PlotData
from dvc.repo.plot.template import NoDataForTemplateError, Template

from .data import PlotData
from .template import NoDataForTemplateError, Template

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -82,7 +83,7 @@ def fill_template(

template_data = {}
for template_datafile in template_datafiles:
from dvc.repo.plot.data import _load_from_revisions
from .data import _load_from_revisions

plot_datas = _load_from_revisions(repo, template_datafile, revisions)
tmp_data = []
Expand Down Expand Up @@ -126,7 +127,7 @@ def plot(
repo, datafile=None, template=None, revisions=None, embed=False, **kwargs
):
if revisions is None:
from dvc.repo.plot.data import WORKSPACE_REVISION_NAME
from .data import WORKSPACE_REVISION_NAME

revisions = [WORKSPACE_REVISION_NAME]

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class DefaultScatterTemplate(Template):


class PlotTemplates:
TEMPLATES_DIR = "plot"
TEMPLATES_DIR = "plots"
TEMPLATES = [
DefaultLinearTemplate,
DefaultConfusionTemplate,
Expand Down
8 changes: 4 additions & 4 deletions scripts/completion/dvc.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# - https://stackoverflow.com/questions/12933362

_dvc_commands='add cache checkout commit config destroy diff fetch get-url get gc \
import-url import init install lock list metrics move params pipeline plot pull push \
import-url import init install lock list metrics move params pipeline plots pull push \
remote remove repro root run status unlock unprotect update version'

_dvc_options='-h --help -V --version'
Expand Down Expand Up @@ -53,9 +53,9 @@ _dvc_pipeline='list show'
_dvc_pipeline_list=''
_dvc_pipeline_show='-c --commands -o --outs --ascii --dot --tree -l --locked'
_dvc_pipeline_show_COMPGEN=_dvc_compgen_DVCFiles
_dvc_plot='show diff'
_dvc_plot_show='-t --template -f --file -s --select -x -y --stdout --no-csv-header --no-html --title --xlab --ylab'
_dvc_plot_diff='-t --template -d --datafile -f --file -s --select -x -y --stdout --no-csv-header --no-html --title --xlab --ylab'
_dvc_plots='show diff'
_dvc_plots_show='-t --template -f --file -s --select -x -y --stdout --no-csv-header --no-html --title --xlab --ylab'
_dvc_plots_diff='-t --template -d --datafile -f --file -s --select -x -y --stdout --no-csv-header --no-html --title --xlab --ylab'
_dvc_pull='-j --jobs -r --remote -a --all-branches -T --all-tags -f --force -d --with-deps -R --recursive'
_dvc_pull_COMPGEN=_dvc_compgen_DVCFiles
_dvc_push='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -R --recursive'
Expand Down
6 changes: 3 additions & 3 deletions scripts/completion/dvc.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ _dvc_commands() {
"pipeline:Manage pipelines."
"pull:Pull data files from a DVC remote storage."
"push:Push data files to a DVC remote storage."
"plot:Generate plot for metrics structured as JSON, CSV or TSV."
"plots:Generate plot for metrics structured as JSON, CSV or TSV."
"remote:Manage remote storage configuration."
"remove:Remove outputs of DVC-file."
"repro:Check for changes and reproduce DVC-file and dependencies."
Expand Down Expand Up @@ -213,7 +213,7 @@ _dvc_push=(
"*:Stages:_files -g '(*.dvc|Dvcfile)'"
)

_dvc_plot=(
_dvc_plots=(
"1:Sub command:(show diff)"
)

Expand Down Expand Up @@ -323,7 +323,7 @@ case $words[1] in
pipeline) _arguments $_dvc_global_options $_dvc_pipeline ;;
pull) _arguments $_dvc_global_options $_dvc_pull ;;
push) _arguments $_dvc_global_options $_dvc_push ;;
plot) _arguments $_dvc_global_options $_dvc_plot ;;
plots) _arguments $_dvc_global_options $_dvc_plots ;;
remote) _arguments $_dvc_global_options $_dvc_remote ;;
remove) _arguments $_dvc_global_options $_dvc_remove ;;
repro) _arguments $_dvc_global_options $_dvc_repro ;;
Expand Down
Empty file added tests/func/plots/__init__.py
Empty file.
12 changes: 6 additions & 6 deletions tests/func/test_plot.py β†’ tests/func/plots/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
from bs4 import BeautifulSoup
from funcy import first

from dvc.repo.plot import NoDataOrTemplateProvided
from dvc.repo.plot.data import (
from dvc.repo.plots import NoDataOrTemplateProvided
from dvc.repo.plots.data import (
NoMetricInHistoryError,
PlotData,
PlotMetricTypeError,
)
from dvc.repo.plot.template import (
from dvc.repo.plots.template import (
NoDataForTemplateError,
NoFieldInDataError,
TemplateNotFoundError,
Expand Down Expand Up @@ -244,7 +244,7 @@ def test_plot_multiple_revs_default(tmp_dir, scm, dvc):


def test_plot_multiple_revs(tmp_dir, scm, dvc):
shutil.copy(tmp_dir / ".dvc" / "plot" / "default.json", "template.json")
shutil.copy(tmp_dir / ".dvc" / "plots" / "default.json", "template.json")

metric_1 = [{"y": 2}, {"y": 3}]
_write_json(tmp_dir, metric_1, "metric.json")
Expand Down Expand Up @@ -324,7 +324,7 @@ def test_throw_on_no_metric_at_all(tmp_dir, scm, dvc, caplog):
def custom_template(tmp_dir, dvc):
custom_template = tmp_dir / "custom_template.json"
shutil.copy(
tmp_dir / ".dvc" / "plot" / "default.json", custom_template,
tmp_dir / ".dvc" / "plots" / "default.json", custom_template,
)
return custom_template

Expand Down Expand Up @@ -380,7 +380,7 @@ def test_custom_template_with_specified_data(

def test_plot_override_specified_data_source(tmp_dir, scm, dvc):
shutil.copy(
tmp_dir / ".dvc" / "plot" / "default.json",
tmp_dir / ".dvc" / "plots" / "default.json",
tmp_dir / "newtemplate.json",
)
_replace(
Expand Down