Skip to content

Commit 8f80825

Browse files
authored
Merge pull request #18 from openmc-data-storage/develop
now raising import errors
2 parents 59f4070 + 7c7abb9 commit 8f80825

File tree

7 files changed

+165
-74
lines changed

7 files changed

+165
-74
lines changed

.github/workflows/docker_ci_main.yml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,29 @@ on:
1212
jobs:
1313
build:
1414
runs-on: ubuntu-latest
15-
15+
container:
16+
image: openmc/openmc:develop
17+
1618
steps:
17-
- uses: actions/checkout@v1
18-
- name: Build and test with Docker
19+
- name: checkout repository
20+
uses: actions/checkout@v2
21+
22+
- name: Setup package
23+
run: |
24+
python setup.py install
25+
26+
- name: test test_command_line_usage.py
27+
run: |
28+
pytest tests/test_command_line_usage.py -v --cov=openmc_data_downloader --cov-report term --cov-report xml
29+
30+
- name: test test_functions.py
31+
run: |
32+
pytest tests/test_functions.py -v --cov=openmc_data_downloader --cov-report term --cov-report xml
33+
34+
- name: test test_use_in_openmc.py
35+
run: |
36+
pytest tests/test_use_in_openmc.py -v --cov=openmc_data_downloader --cov-report term --cov-report xml
37+
38+
- name: upload test results
1939
run: |
20-
mkdir share
21-
sudo apt-get install -y curl
22-
docker build -t openmc_data_downloader .
23-
docker run -v "$PWD/share:/share" openmc_data_downloader
2440
curl -s https://codecov.io/bash | bash
Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
# This workflows will upload a Python Package using Twine when a release is created
2-
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
1+
# This yml file will trigger a Github Actions event that builds and upload the
2+
# Python package to PiPy. This makes use of Twine and is triggered when a push
3+
# to the main branch occures. For more information see:
4+
# https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
5+
# and for details on the Autobump version section see:
6+
# https://github.com/grst/python-ci-versioneer
37

48
name: Upload Python Package
59

610
on:
11+
# allows us to run workflows manually
12+
workflow_dispatch:
713
release:
814
types: [created]
915

@@ -13,19 +19,33 @@ jobs:
1319
runs-on: ubuntu-latest
1420

1521
steps:
16-
- uses: actions/checkout@v2
17-
- name: Set up Python
18-
uses: actions/setup-python@v2
19-
with:
20-
python-version: '3.x'
21-
- name: Install dependencies
22-
run: |
23-
python -m pip install --upgrade pip
24-
pip install setuptools wheel twine
25-
- name: Build and publish
26-
env:
27-
TWINE_USERNAME: __token__
28-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
29-
run: |
30-
python setup.py sdist bdist_wheel
31-
twine upload dist/*
22+
- uses: actions/checkout@v2
23+
- name: Set up Python
24+
uses: actions/setup-python@v2
25+
with:
26+
python-version: '3.x'
27+
28+
- name: Autobump version
29+
run: |
30+
# from refs/tags/v1.2.3 get 1.2.3
31+
VERSION=$(echo $GITHUB_REF | sed 's#.*/v##')
32+
PLACEHOLDER='version="develop"'
33+
VERSION_FILE='setup.py'
34+
# Grep checks that the placeholder is in the file. If grep doesn't find
35+
# the placeholder then it exits with exit code 1 and github actions fails.
36+
grep "$PLACEHOLDER" "$VERSION_FILE"
37+
sed -i "s@$PLACEHOLDER@version=\"${VERSION}\"@g" "$VERSION_FILE"
38+
shell: bash
39+
40+
- name: Install dependencies
41+
run: |
42+
python -m pip install --upgrade pip
43+
pip install setuptools wheel twine
44+
45+
- name: Build and publish
46+
env:
47+
TWINE_USERNAME: __token__
48+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
49+
run: |
50+
python setup.py sdist bdist_wheel
51+
twine upload dist/*

Dockerfile

Lines changed: 0 additions & 12 deletions
This file was deleted.

openmc_data_downloader/utils.py

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11

22

33
import os
4+
import warnings
45
import xml.etree.ElementTree as ET
56
from pathlib import Path
6-
from typing import List, Union, Optional
7+
from typing import List, Optional, Union
78
from urllib.parse import urlparse
89
from urllib.request import urlopen
910

1011
import pandas as pd
1112

12-
from openmc_data_downloader import (
13-
NATURAL_ABUNDANCE,
14-
LIB_OPTIONS,
15-
PARTICLE_OPTIONS,
16-
SAB_OPTIONS,
17-
ISOTOPE_OPTIONS,
18-
xs_info,
19-
sab_info
20-
)
13+
from openmc_data_downloader import (ISOTOPE_OPTIONS, LIB_OPTIONS,
14+
NATURAL_ABUNDANCE, PARTICLE_OPTIONS,
15+
SAB_OPTIONS, sab_info, xs_info)
2116

2217
_BLOCK_SIZE = 16384
2318

@@ -37,12 +32,19 @@ def set_enviromental_varible(cross_section_xml_path: Union[Path, str]) -> None:
3732

3833

3934
def expand_materials_to_isotopes(materials: list):
35+
36+
if isinstance(materials, list):
37+
if len(materials) == 0:
38+
return []
39+
4040
try:
4141
import openmc
4242
except ImportError:
43-
print('openmc python package was not imported, '
44-
'expand_materials_to_isotopes can not be performed.')
45-
return None
43+
msg = (
44+
'import openmc failed. openmc python package could not be found '
45+
'and was not imported, the expand_materials_to_isotopes '
46+
'opperation can not be performed ithout openmc')
47+
raise ImportError(msg)
4648

4749
if isinstance(materials, openmc.Materials):
4850
iterable_of_materials = materials
@@ -72,12 +74,19 @@ def expand_materials_to_isotopes(materials: list):
7274

7375

7476
def expand_materials_to_sabs(materials: list):
77+
78+
if isinstance(materials, list):
79+
if len(materials) == 0:
80+
return []
81+
7582
try:
7683
import openmc
7784
except ImportError:
78-
print('openmc python package was not imported, '
79-
'expand_materials_to_isotopes can not be performed.')
80-
return None
85+
msg = (
86+
'import openmc failed. openmc python package could not be found '
87+
'and was not imported, the expand_materials_to_sabs '
88+
'opperation can not be performed ithout openmc')
89+
raise ImportError(msg)
8190

8291
if isinstance(materials, openmc.Materials):
8392
iterable_of_materials = materials
@@ -113,15 +122,15 @@ def just_in_time_library_generator(
113122
sab: List[str] = [],
114123
destination: Union[str, Path] = None,
115124
materials_xml: List[Union[str, Path]] = [],
116-
materials: list = [],
125+
materials: list = [], # also accepts a single openmc.Material
117126
particles: Optional[List[str]] = ['neutron', 'photon'],
118127
set_OPENMC_CROSS_SECTIONS: bool = True,
119128
) -> str:
120129

121130
# expands elements, materials xml into list of isotopes
122-
if len(elements) > 0:
123-
isotopes_from_elements = expand_elements_to_isotopes(elements)
124-
isotopes = list(set(isotopes + isotopes_from_elements))
131+
132+
isotopes_from_elements = expand_elements_to_isotopes(elements)
133+
isotopes = list(set(isotopes + isotopes_from_elements))
125134

126135
isotopes_from_material_xml = expand_materials_xml_to_isotopes(
127136
materials_xml)
@@ -156,7 +165,10 @@ def just_in_time_library_generator(
156165
cross_section_xml_path = create_cross_sections_xml(dataframe, destination)
157166

158167
if set_OPENMC_CROSS_SECTIONS is True:
159-
set_enviromental_varible(cross_section_xml_path)
168+
# making the cross section xml requires openmc and returns None if
169+
# openmc is not found.
170+
if cross_section_xml_path is not None:
171+
set_enviromental_varible(cross_section_xml_path)
160172
else:
161173
print('Set your $OPENMC_CROSS_SECTIONS enviromental varible to {} to '
162174
'use this custom library'.format(cross_section_xml_path))
@@ -239,8 +251,11 @@ def create_cross_sections_xml(dataframe, destination: Union[str, Path]) -> str:
239251
try:
240252
import openmc
241253
except ImportError:
242-
print('openmc python package was was found, cross_sections.xml can '
243-
'not be made.')
254+
msg = (
255+
'import openmc failed. openmc python package could not be found '
256+
'and was not imported, cross sections.xml can not be made'
257+
'without openmc')
258+
warnings.warn(msg)
244259
return None
245260

246261
library = openmc.data.DataLibrary()

setup.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="openmc_data_downloader",
8-
version="0.3.0",
8+
version="develop",
99
summary="Download cross section h5 files for use in OpenMC",
1010
author="Jonathan Shimwell",
1111
author_email="mail@jshimwell.com",
@@ -24,6 +24,17 @@
2424
"LICENSE",
2525
]
2626
},
27+
classifiers=[
28+
'Natural Language :: English',
29+
'Topic :: Scientific/Engineering',
30+
'Programming Language :: Python :: 3',
31+
'Programming Language :: Python :: 3.6',
32+
'Programming Language :: Python :: 3.7',
33+
'Programming Language :: Python :: 3.8',
34+
'Programming Language :: Python :: 3.9',
35+
'License :: OSI Approved :: MIT License',
36+
'Operating System :: OS Independent',
37+
],
2738
tests_require=["pytest-cov", "pytest-runner"],
2839
install_requires=[
2940
"pandas",

tests/test_command_line_usage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,6 @@ def test_sab_download_with_endf(self):
145145
assert Path('ENDFB-7.1-NNDC_O16.h5').is_file()
146146
assert Path('ENDFB-7.1-NNDC_O17.h5').is_file()
147147
assert Path('TENDL-2019_O18.h5').is_file()
148+
assert Path('ENDFB-7.1-NNDC_c_Be_in_BeO.h5').is_file()
148149
assert Path('materials.xml').is_file()
149-
assert len(list(Path('.').glob('*.h5'))) == 4
150+
assert len(list(Path('.').glob('*.h5'))) == 5

0 commit comments

Comments
 (0)