Skip to content

Commit

Permalink
split all deps and make smart check for missing dep
Browse files Browse the repository at this point in the history
  • Loading branch information
brisvag committed Aug 4, 2023
1 parent 3f0339c commit 8c22737
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 16 deletions.
83 changes: 70 additions & 13 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,83 @@ setup_requires =
setuptools_scm
install_requires =
click
numpy
mrcfile
scikit_image
numpy
pandas
rich
rich
scipy
eulerangles
starfile>=0.4.6
sh

[options.extras_require]
batch_warp =
GPUtil
mdocfile
topaz-em
aretomo =
%(batch_warp)s
csplot =
plotly
magicgui
IPython
fix_filament_ids =
starfile
generate_tilt_angles =
starfile
cryosparc =
%(csplot)s
%(fix_filament_ids)s
%(generate_tilt_angles)s
center_filament =
scikit-image
classify_densities =
matplotlib
plotly
pandas
pyqt5
GPUtil
edt
create_mask =
edt
extract_z_snapshots =
napari[pyqt5]
cryohub
cryotypes
flip_z =
starfile
eulerangles
image =
%(center_filament)s
%(classify_densities)s
%(create_mask)s
%(extract_z_snapshots)s
%(flip_z)s
align_filament_particles =
starfile
relion =
%(align_filament_particles)s
fix_mdoc =
mdocfile
rich
topaz-em
merge_star =
starfile
offset_angle =
mdocfile
prepare_isonet =
starfile
spoof_mdoc =
mdocfile
summarize =
tabulate
cryohub
napari
sh
matplotlib
warp =
%(fix_mdoc)s
%(merge_star)s
%(offset_angle)s
%(prepare_isonet)s
%(spoof_mdoc)s
%(summarize)s
all =
%(aretomo)s
%(cryosparc)s
%(image)s
%(relion)s
%(warp)s

[options.entry_points]
console_scripts =
Expand Down
20 changes: 17 additions & 3 deletions stemia/utils/click.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ def func(**kwargs):
return func


def try_subcommand(sub):
cb = sub.callback

def wrap(*args, **kwargs):
try:
cb(*args, **kwargs)
except ModuleNotFoundError as e:
print(f'{e.args[0]}. Install missing dependencies with:\n'
f' [bold]pip install "stemia\[{sub.name}]"[/]')

sub.callback = wrap
return sub


def add_subcommands(cli, base_dir, base_package):
"""
Recursively add subcommands to a cli by walking the package tree and looking for
Expand All @@ -66,18 +80,18 @@ def add_subcommands(cli, base_dir, base_package):
# get the cli if it exists
if hasattr(module, 'cli'):
module.cli.name = name
cli.add_command(module.cli, name=name)
cli.add_command(try_subcommand(module.cli), name=name)
has_subcommands = True
# go deeper if needed
elif is_pkg:
def subcli():
pass
subcli.__doc__ = module.__doc__
subcli = click.group()(subcli)
has_subcommands = add_subcommands(subcli, source / name, full_name)
has_subcommands = add_subcommands(try_subcommand(subcli), source / name, full_name)
if has_subcommands:
subcli.name = name
cli.add_command(subcli, name=name)
cli.add_command(try_subcommand(subcli), name=name)

# add shell scripts
for file in source.glob('*.sh'):
Expand Down

0 comments on commit 8c22737

Please sign in to comment.