Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions frictionless/console/commands/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import List

import typer
from rich.console import Console
from rich.progress import track

from ...exception import FrictionlessException
Expand All @@ -12,6 +11,7 @@
from ...system import system
from .. import common, helpers
from ..console import console
from ..helpers import output_console


@console.command(name="convert")
Expand Down Expand Up @@ -51,8 +51,6 @@ def console_convert(
"""
Convert data table
"""
console = Console()

# Setup system
if trusted:
system.trusted = trusted
Expand Down Expand Up @@ -115,7 +113,7 @@ def console_convert(
raise FrictionlessException(note)

# Convert resource
console.rule("[bold]Convert")
output_console.rule("[bold]Convert")
# TODO: replace dummy progress bar a normal one
for stage in track(["start", "end"], description="Converting..."):
if stage == "end":
Expand All @@ -128,5 +126,5 @@ def console_convert(
raise typer.Exit(code=1)

# Print result
console.rule("[bold]Result")
console.print(f"Succesefully converted to [bold]{to_path}[/bold]")
output_console.rule("[bold]Result")
output_console.print(f"Succesefully converted to [bold]{to_path}[/bold]")
12 changes: 5 additions & 7 deletions frictionless/console/commands/describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import List

import typer
from rich.console import Console
from rich.table import Table

from ...dialect import Dialect
Expand All @@ -14,6 +13,7 @@
from ...system import system
from .. import common, helpers
from ..console import console
from ..helpers import output_console

DEFAULT_MAX_FIELDS = 10

Expand Down Expand Up @@ -64,8 +64,6 @@ def console_describe(
Based on the inferred data source type it will return resource or package descriptor.
Default output format is YAML with a front matter.
"""
console = Console()

# Setup system
if trusted:
system.trusted = trusted
Expand Down Expand Up @@ -137,7 +135,7 @@ def console_describe(
raise typer.Exit()

# Default mode
console.rule("[bold]Dataset")
output_console.rule("[bold]Dataset")
assert isinstance(metadata, (Resource, Package))
resources = [metadata] if isinstance(metadata, Resource) else metadata.resources
view = Table(title="dataset")
Expand All @@ -158,8 +156,8 @@ def console_describe(
row.append(str(resource.fields or ""))
row.append(str(resource.rows or ""))
view.add_row(*row, style=style)
console.print(view)
console.rule("[bold]Tables")
output_console.print(view)
output_console.rule("[bold]Tables")
for resource in resources:
if isinstance(resource, TableResource):
view = Table(title=resource.name)
Expand All @@ -172,4 +170,4 @@ def console_describe(
if len(labels) > DEFAULT_MAX_FIELDS:
row.append("...")
view.add_row(*row)
console.print(view)
output_console.print(view)
13 changes: 6 additions & 7 deletions frictionless/console/commands/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import TYPE_CHECKING, List, Optional

import typer
from rich.console import Console
from rich.table import Table

from ...exception import FrictionlessException
Expand All @@ -14,6 +13,7 @@
from ...system import system
from .. import common, helpers
from ..console import console
from ..helpers import output_console

if TYPE_CHECKING:
from ... import types
Expand Down Expand Up @@ -77,7 +77,6 @@ def console_extract(
Based on the inferred data source type it will return resource or package data.
Default output format is tabulated with a front matter. Output will be utf-8 encoded.
"""
console = Console()
name = name or resource_name

# Setup system
Expand Down Expand Up @@ -215,7 +214,7 @@ def console_extract(
raise typer.Exit()

# Default mode
console.rule("[bold]Dataset")
output_console.rule("[bold]Dataset")
view = Table(title="dataset")
view.add_column("name")
view.add_column("type")
Expand All @@ -224,13 +223,13 @@ def console_extract(
style = "sky_blue1" if resource.tabular else ""
row = [resource.name, resource.type, resource.path]
view.add_row(*row, style=style)
console.print(view)
output_console.print(view)

console.rule("[bold]Tables")
output_console.rule("[bold]Tables")
for title, items in data.items():
# Empty
if not items:
helpers.print_panel(console, note="No rows found", title="Empty")
helpers.print_panel(note="No rows found", title="Empty")
continue

# General
Expand All @@ -252,4 +251,4 @@ def console_extract(
if len(labels) > DEFAULT_MAX_FIELDS:
row.append("...")
view.add_row(*row)
console.print(view)
output_console.print(view)
10 changes: 4 additions & 6 deletions frictionless/console/commands/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from typing import List

import typer
from rich.console import Console

from ...resource import Resource
from ...system import system
from .. import common, helpers
from ..console import console
from ..helpers import output_console


@console.command(name="index")
Expand All @@ -29,7 +29,6 @@ def console_index(
standards: str = common.standards,
):
"""Index a tabular data resource"""
console = Console()

# Setup system
if trusted:
Expand All @@ -45,7 +44,7 @@ def console_index(
raise typer.Exit(code=1)

# Index resource
console.rule("[bold]Index")
output_console.rule("[bold]Index")
try:
# Create resource
resource = Resource(
Expand All @@ -61,7 +60,6 @@ def console_index(
for resource in resources:
names.extend(
helpers.index_resource(
console,
resource=resource,
database=database,
fast=fast,
Expand All @@ -75,5 +73,5 @@ def console_index(
raise typer.Exit(code=1)

# Print result
console.rule("[bold]Result")
console.print(f"Succesefully indexed [bold]{len(names)}[/] tables")
output_console.rule("[bold]Result")
output_console.print(f"Succesefully indexed [bold]{len(names)}[/] tables")
8 changes: 3 additions & 5 deletions frictionless/console/commands/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from typing import List

import typer
from rich.console import Console

from ...resource import Resource
from ...system import system
from .. import common, helpers
from ..console import console
from ..helpers import output_console


# TODO: figure out how we can reduce duplication among commands like this: query/etc
Expand All @@ -28,7 +28,6 @@ def console_inspect(
standards: str = common.standards,
):
"""Query data"""
console = Console()

# Setup system
if trusted:
Expand All @@ -44,7 +43,7 @@ def console_inspect(
raise typer.Exit(code=1)

# Index resource
console.rule("[bold]Index")
output_console.rule("[bold]Index")
try:
# Create resource
resource = Resource(
Expand All @@ -65,7 +64,6 @@ def console_inspect(
for resource in resources:
names.extend(
helpers.index_resource(
console,
resource=resource,
database=database,
fast=True,
Expand All @@ -84,5 +82,5 @@ def console_inspect(
raise typer.Exit(1)

# Enter database
console.rule("[bold]Inspect")
output_console.rule("[bold]Inspect")
os.system(f"datasette {database}")
8 changes: 3 additions & 5 deletions frictionless/console/commands/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from typing import List

import typer
from rich.console import Console
from rich.table import Table

from ...helpers import to_json, to_yaml
from ...resource import Resource
from ...system import system
from .. import common, helpers
from ..console import console
from ..helpers import output_console


@console.command(name="list")
Expand Down Expand Up @@ -55,8 +55,6 @@ def console_describe(
"""
List a data source.
"""
console = Console()

# Setup system
if trusted:
system.trusted = trusted
Expand Down Expand Up @@ -133,7 +131,7 @@ def console_describe(
raise typer.Exit()

# Default mode
console.rule("[bold]Dataset")
output_console.rule("[bold]Dataset")
view = Table(title="dataset")
view.add_column("name")
view.add_column("type")
Expand All @@ -142,4 +140,4 @@ def console_describe(
style = "sky_blue1" if resource.tabular else ""
row = [resource.name, resource.type, resource.path]
view.add_row(*row, style=style)
console.print(view)
output_console.print(view)
9 changes: 4 additions & 5 deletions frictionless/console/commands/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import List

import typer
from rich.console import Console
from rich.progress import track
from rich.prompt import Prompt

Expand All @@ -14,6 +13,7 @@
from ...system import system
from .. import common, helpers
from ..console import console
from ..helpers import output_console


@console.command(name="publish")
Expand All @@ -32,7 +32,6 @@ def console_publish(
standards: str = common.standards,
):
"""Script data"""
console = Console()
portals = platform.frictionless_portals

# Setup system
Expand Down Expand Up @@ -60,7 +59,7 @@ def console_publish(
package = Package(title=title, resources=resources)

# Publish package
console.rule("[bold]Publish")
output_console.rule("[bold]Publish")
adapter = system.create_adapter(target, packagify=True)
if not isinstance(adapter, portals.ckan.CkanAdapter):
raise FrictionlessException("Currently only CKAN publishing is supported")
Expand All @@ -75,5 +74,5 @@ def console_publish(
raise typer.Exit(code=1)

# Print result
console.rule("[bold]Result")
console.print(f"Succesefully published to [bold]{target}[/bold]")
output_console.rule("[bold]Result")
output_console.print(f"Succesefully published to [bold]{target}[/bold]")
8 changes: 3 additions & 5 deletions frictionless/console/commands/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from typing import List

import typer
from rich.console import Console

from ...resource import Resource
from ...system import system
from .. import common, helpers
from ..console import console
from ..helpers import output_console


@console.command(name="query")
Expand All @@ -27,7 +27,6 @@ def console_query(
standards: str = common.standards,
):
"""Query data"""
console = Console()

# Setup system
if trusted:
Expand All @@ -43,7 +42,7 @@ def console_query(
raise typer.Exit(code=1)

# Index resource
console.rule("[bold]Index")
output_console.rule("[bold]Index")
try:
# Create resource
resource = Resource(
Expand All @@ -64,7 +63,6 @@ def console_query(
for resource in resources:
names.extend(
helpers.index_resource(
console,
resource=resource,
database=database,
fast=True,
Expand All @@ -83,5 +81,5 @@ def console_query(
raise typer.Exit(1)

# Enter database
console.rule("[bold]Query")
output_console.rule("[bold]Query")
os.system(f"sqlite3 {database}")
Loading
Loading