Skip to content

Commit

Permalink
first attempt at getting the demos files to download with proper vers…
Browse files Browse the repository at this point in the history
…ion and without overriding local files
  • Loading branch information
robinsteuteville committed Oct 12, 2023
1 parent 178448c commit c9de773
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions python/fastsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,39 @@ def package_root() -> Path:

__version__ = get_distribution("fastsim").version

#download demo files
import fastsim
import os
import pathlib
import fnmatch
import requests

p = 'https://github.com/NREL/fastsim/tree/' + fastsim.__version__ + '/python/fastsim/demos'
d = pathlib.Path(__file__).parent
has_demos = False
demos_dir = ''
for dir in os.walk(d):
if fnmatch.fnmatch(dir[0], '*demos'):
has_demos = True
demos_dir = dir[0]
break
if has_demos:
#the problem is I can't figure out how to list the contents of the online demos file
for f in p.get_dir_contents():
already_downloaded = False
for file in demos_dir.glob('*demo*.py'):
#need a way to get the "basename" for the online demos files as well for this to work
if f == os.path.basename(file.replace('\\', '/')): #necessary to ensure command works on all operating systems
already_downloaded = True
print('{} = {} already downloaded'.format(file, f)) #placeholder until I figure out how to download the file
break
if already_downloaded == False:
#download file
print('{} != {} needs downloading'.format(file, f)) #placeholder under I figure out how to download the folder
else:
#just download demos folder
print('demos folder needs downloading')

__doc__ += "\nhttps://pypi.org/project/fastsim/"
__doc__ += "\nhttps://www.nrel.gov/transportation/fastsim.html"

Expand Down
2 changes: 1 addition & 1 deletion python/fastsim/demos/run_all.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pathlib

p = pathlib.Path('run_all.py').parent
p = pathlib.Path(__file__).parent

for file in p.glob('*demo*.py'):
with open(file) as f:
Expand Down

0 comments on commit c9de773

Please sign in to comment.