SAME-Project / same-project

https://sameproject.ml/
Apache License 2.0
19 stars 8 forks source link

Support %%bash magic and ! syntax #66

Open lukemarsden opened 2 years ago

lukemarsden commented 2 years ago

You can sneak a bash script into a notebook with %%bash magic at the top of a cell or ! inline on individual lines. Support these in SAME by porting them to subprocess calls or something. Examples from a notebook I'm porting:

if os.path.isdir(export_path):
  print('\nAlready saved a model, cleaning up\n')
  !rm -r {export_path}
%%bash
DATAFILE="https://d17h27t6h515a5.cloudfront.net/topher/2017/February/5898cd6f_traffic-signs-data/traffic-signs-data.zip"
if [ -d "/tmp/traffic-signs-data" ]; then
    echo "Data already downloaded"
else
    echo "Downloading data from $DATAFILE"
    mkdir /tmp/traffic-signs-data
    curl -s -o /tmp/traffic-signs-data/traffic-signs-data.zip $DATAFILE
    (cd /tmp/traffic-signs-data && unzip traffic-signs-data.zip && rm -f traffic-signs-data.zip)
    (mv /tmp/traffic-signs-data/* .)
fi