Skip to content

Commit e53332b

Browse files
committed
fixing click commands for new folder structure
1 parent 53fc562 commit e53332b

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

pytheus/cli.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,29 @@ def run(filename, example):
4343
click.echo('ERROR:' + str(e))
4444
sys.exit(1)
4545

46+
4647
@cli.command()
4748
@click.argument('filename')
4849
@click.option('--pdf', default="", help='save output to pdf')
4950
def plot(filename, pdf):
5051
"""Plot a solution file."""
5152
try:
52-
plotFromFile(filename, outfile = pdf)
53+
plotFromFile(filename, outfile=pdf)
5354
except IOError as e:
5455
click.echo('ERROR:' + str(e))
5556
sys.exit(1)
5657

5758

5859
@cli.command()
59-
@click.option('-d', '--which-directory',default = None,
60+
@click.option('-d', '--which-directory', default=None,
6061
help='choose folder to analyze')
61-
@click.option('-one', '--all-weights-plus-minus-one', is_flag=True,
62+
@click.option('-one', '--all-weights-plus-minus-one', is_flag=True,
6263
show_default=True,
6364
help='map all weights to plus minus one')
6465
@click.option('-pm', '--create-perfect-machting-pdf', is_flag=True,
6566
show_default=True,
6667
help='bool if create pdf with all pms')
67-
@click.option('-i', '--which-infos', default = ['norm', 'ent', 'k'],
68+
@click.option('-i', '--which-infos', default=['norm', 'ent', 'k'],
6869
multiple=True,
6970
show_default=True,
7071
help='list of which infos appear in info plot')
@@ -75,7 +76,7 @@ def analyze(which_directory, all_weights_plus_minus_one,
7576
get_analyse(which_directory,
7677
all_weights_plus_minus_one=all_weights_plus_minus_one,
7778
create_perfect_machting_pdf=create_perfect_machting_pdf,
78-
which_infos= which_infos)
79+
which_infos=which_infos)
7980
except IOError as e:
8081
click.echo('ERROR:' + str(e))
8182
sys.exit(1)
@@ -86,5 +87,10 @@ def list():
8687
"""List all included examples."""
8788
configs_dir = pkg_resources.resource_filename(pytheus.__name__, 'graphs')
8889
files = sorted(os.listdir(configs_dir))
89-
for file in files:
90-
click.echo(file.replace('.json', ''))
90+
91+
walk = os.walk(configs_dir)
92+
for root, dirs, files in walk:
93+
for file in files:
94+
if file.startswith('config'):
95+
click.echo(
96+
print(root.split('/')[-1]))

pytheus/main.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,21 @@ def read_config(is_example, filename):
405405
''''
406406
read config json and output cnfg dict
407407
'''
408-
# check if filename ends in json, add extension if needed
409-
if not filename.endswith('.json'):
410-
filename += '.json'
408+
411409
# option for running files from example folder
412410
if is_example:
413411
examples_dir = pkg_resources.resource_filename(pytheus.__name__, "graphs")
414-
filename = Path(examples_dir) / filename
412+
for root, subdirs, files in os.walk(examples_dir):
413+
if root.split('/')[-1] == filename:
414+
for file in files:
415+
if file.startswith('config'):
416+
filename = root+'/'+file
417+
break
418+
419+
# check if filename ends in json, add extension if needed
420+
if not filename.endswith('.json'):
421+
filename += '.json'
422+
415423
# error if file does not exist
416424
if not os.path.exists(filename) or os.path.isdir(filename):
417425
raise IOError(f'File does not exist: {filename}')

0 commit comments

Comments
 (0)