Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ddkohler committed Feb 19, 2024
1 parent 2c4de2c commit fd0ddc5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 41 deletions.
1 change: 0 additions & 1 deletion WrightTools/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from . import _tree
from . import _units
from . import _wt5
30 changes: 0 additions & 30 deletions WrightTools/cli/_tree.py

This file was deleted.

18 changes: 10 additions & 8 deletions WrightTools/cli/_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@


import click
import WrightTools as wt
from WrightTools import __version__ as __wt_version__
from WrightTools.units import is_valid_conversion, get_valid_conversions, convert
from WrightTools.exceptions import UnitsError


# --- define --------------------------------------------------------------------------------------


@click.command()
@click.version_option(wt.__version__)
@click.command(name="convert", help="convert numbers to different units.")
@click.version_option(__wt_version__, package_name="WrightTools")
@click.argument("number", type=float, nargs=1)
@click.argument("unit", nargs=1)
@click.argument("destination_unit", default=None, nargs=-1)
Expand All @@ -33,14 +35,14 @@ def fmt(new):

if len(destination_unit): # units provided
destination_unit = destination_unit[0]
if not wt.units.is_valid_conversion(unit, destination_unit):
raise wt.exceptions.UnitsError(wt.units.get_valid_conversions(unit), destination_unit)
new = wt.units.convert(number, unit, destination_unit)
if not is_valid_conversion(unit, destination_unit):
raise UnitsError(get_valid_conversions(unit), destination_unit)
new = convert(number, unit, destination_unit)
print(f"{number} {unit} = {fmt(new)} {destination_unit}")
else:
valid_units = wt.units.get_valid_conversions(unit)
valid_units = get_valid_conversions(unit)
for d_unit in valid_units:
new = wt.units.convert(number, unit, d_unit)
new = convert(number, unit, d_unit)
print(f"{fmt(new)} {d_unit}")


Expand Down
20 changes: 19 additions & 1 deletion WrightTools/cli/_wt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,29 @@


@click.group()
@click.version_option(wt.__version__)
@click.version_option(wt.__version__, prog_name="WrightTools")
def cli():
pass


@cli.command(name="tree", help="Print a given data tree.")
@click.argument("path", nargs=1)
@click.option(
"--internal_path", default="/", help="specify a path internal to the file. Defaults to root"
)
@click.option("--depth", "-d", "-L", type=int, default=9, help="Depth to print.")
@click.option("--verbose", "-v", is_flag=True, default=False, help="Print a more detailed tree.")
def tree(path, internal_path, depth=9, verbose=False):
# open the object
obj = wt.open(path)[internal_path]

if isinstance(obj, wt.Data):
obj.print_tree(verbose=verbose)
else:
obj.print_tree(verbose=verbose, depth=depth)



@cli.command(name="load", help="Open a python cli with the object pre-loaded.")
@click.argument("path")
def load(path):
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def read(fname):
keywords="spectroscopy science multidimensional visualization",
entry_points={
"console_scripts": [
"wt-tree=WrightTools.cli._tree:cli",
"wt5=WrightTools.cli._wt5:cli",
"wt-convert=WrightTools.cli._units:cli",
]
Expand Down

0 comments on commit fd0ddc5

Please sign in to comment.