Skip to content

Commit

Permalink
Download single_pass_weld.wx directly in the tutorials (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
vhirtham authored Feb 17, 2022
1 parent 8a2ccec commit 9f2bc65
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 57 deletions.
39 changes: 0 additions & 39 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,45 +89,6 @@ def _copy_tut_files():
shutil.copy(f, tutorials_dir)


def download_tutorial_input_file():
from urllib.request import urlretrieve

url = "https://github.com/BAMWelDX/IIW2021_AA_CXII/blob/weldx_0.5.0/single_pass_weld.weldx?raw=true"
sha256sum = "29e4f11ef1185f818b4611860842ef52d386ad2866a2680257950f160e1e098a"

def hash_path(path):
import hashlib

h = hashlib.sha256()
with open(path, "rb") as fh:
h.update(fh.read())
return h.hexdigest()

dest = tutorials_dir / "single_pass_weld.wx"

# check if existing files matches desired one.
if dest.exists():
hash_local = hash_path(dest)
if hash_local == sha256sum:
logger.info(f"File %s already downloaded.", dest)
return

# does not exist or hash mismatched, so download it.
logger.info("trying to download: %s", url)
out_file, header = urlretrieve(url, dest)
sha256sum_actual = hash_path(out_file)
if not sha256sum_actual == sha256sum:
raise RuntimeError(
f"hash mismatch:\n actual = \t{sha256sum_actual}\n"
f"desired = \t{sha256sum}"
)

logger.info("download successful.")


download_tutorial_input_file()


# -- Project information -----------------------------------------------------
_now = datetime.datetime.now().year

Expand Down
16 changes: 7 additions & 9 deletions tutorials/01_01_introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,16 @@
"jupyter": {
"outputs_hidden": false
},
"pycharm": {
"name": "#%%\n"
},
"tags": [
"hide-cell"
]
"nbsphinx": "hidden",
"tags": []
},
"outputs": [],
"source": [
"import util\n",
"# download the example file for this tutorial\n",
"\n",
"from util import download_tutorial_input_file\n",
"\n",
"util.download_tutorial_input_file()"
"download_tutorial_input_file(print_status=False)"
]
},
{
Expand Down Expand Up @@ -194,7 +192,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
22 changes: 21 additions & 1 deletion tutorials/01_02_time_dependent_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@
"- Opening and navigating through WelDX files ([tutorial](01_01_introduction.ipynb))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"nbsphinx": "hidden",
"tags": []
},
"outputs": [],
"source": [
"# download the example file for this tutorial\n",
"\n",
"from util import download_tutorial_input_file\n",
"\n",
"download_tutorial_input_file(print_status=False)"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -430,7 +450,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.11"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
30 changes: 27 additions & 3 deletions tutorials/01_03_geometry.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"tags": []
},
"source": [
"# Groove based workpiece data and geometry\n",
"\n",
Expand All @@ -19,9 +21,31 @@
"- Opening and navigating through WelDX files ([tutorial](01_01_introduction.ipynb))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"nbsphinx": "hidden",
"tags": []
},
"outputs": [],
"source": [
"# download the example file for this tutorial\n",
"\n",
"from util import download_tutorial_input_file\n",
"\n",
"download_tutorial_input_file(print_status=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"tags": []
},
"source": [
"## Plotting the specimen's groove\n",
"\n",
Expand Down Expand Up @@ -367,7 +391,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
12 changes: 7 additions & 5 deletions tutorials/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
tutorials_dir = Path(__file__).parent.absolute()


def download_tutorial_input_file():
def download_tutorial_input_file(print_status=True):
from urllib.request import urlretrieve

url = (
Expand All @@ -27,17 +27,19 @@ def hash_path(path):
if dest.exists():
hash_local = hash_path(dest)
if hash_local == sha256sum:
print(f"File {dest} already downloaded.")
if print_status:
print(f"File {dest} already downloaded.")
return

# does not exist or hash mismatched, so download it.
print("trying to download: {url}")
if print_status:
print("trying to download: {url}")
out_file, _ = urlretrieve(url, dest) # skipcq: BAN-B310
sha256sum_actual = hash_path(out_file)
if sha256sum_actual != sha256sum:
raise RuntimeError(
f"hash mismatch:\n actual = \t{sha256sum_actual}\n"
f"desired = \t{sha256sum}"
)

print("download successful.")
if print_status:
print("download successful.")

0 comments on commit 9f2bc65

Please sign in to comment.