Skip to content

Commit

Permalink
Merge pull request #38 from softwareengineerprogrammer/disable-forex-api
Browse files Browse the repository at this point in the history
Disable Forex API
  • Loading branch information
softwareengineerprogrammer authored Oct 15, 2024
2 parents 0338348 + 50d10f6 commit 450e84d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 3.6.1
current_version = 3.6.2
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion .cookiecutterrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ default_context:
sphinx_doctest: "no"
sphinx_theme: "sphinx-py3doc-enhanced-theme"
test_matrix_separate_coverage: "no"
version: 3.6.1
version: 3.6.2
version_manager: "bump2version"
website: "https://github.com/NREL"
year_from: "2023"
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ Free software: `MIT license <LICENSE>`__
:alt: Supported implementations
:target: https://pypi.org/project/geophires-x

.. |commits-since| image:: https://img.shields.io/github/commits-since/softwareengineerprogrammer/GEOPHIRES-X/v3.6.1.svg
.. |commits-since| image:: https://img.shields.io/github/commits-since/softwareengineerprogrammer/GEOPHIRES-X/v3.6.2.svg
:alt: Commits since latest release
:target: https://github.com/softwareengineerprogrammer/GEOPHIRES-X/compare/v3.6.1...main
:target: https://github.com/softwareengineerprogrammer/GEOPHIRES-X/compare/v3.6.2...main

.. |docs| image:: https://readthedocs.org/projects/GEOPHIRES-X/badge/?style=flat
:target: https://nrel.github.io/GEOPHIRES-X
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
year = '2024'
author = 'NREL'
copyright = f'{year}, {author}'
version = release = '3.6.1'
version = release = '3.6.2'

pygments_style = 'trac'
templates_path = ['./templates']
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def read(*names, **kwargs):

setup(
name='geophires-x',
version='3.6.1',
version='3.6.2',
license='MIT',
description='GEOPHIRES is a free and open-source geothermal techno-economic simulator.',
long_description='{}\n{}'.format(
Expand Down
19 changes: 15 additions & 4 deletions src/geophires_x/Parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from geophires_x.Units import *

_ureg = get_unit_registry()
_DISABLE_FOREX_API = True # See https://github.com/NREL/GEOPHIRES-X/issues/236#issuecomment-2414681434

class HasQuantity(ABC):

Expand Down Expand Up @@ -500,15 +501,19 @@ def ConvertUnits(ParamToModify, strUnit: str, model) -> str:

try:
# if we come here, we have a currency conversion to do (USD->EUR, etc.).

if _DISABLE_FOREX_API:
raise RuntimeError('Forex API disabled')

cr = CurrencyRates()
conv_rate = cr.get_rate(currShort, prefShort)
except BaseException as ex:
print(str(ex))
msg = (
f'Error: GEOPHIRES failed to convert your currency for {ParamToModify.Name} to something it '
f'understands. You gave {strUnit} - Are these currency units defined for forex-python? or perhaps the '
f'currency server is down? Please change your units to {ParamToModify.PreferredUnits.value} to '
f'continue. Cannot continue unless you do. Exiting.'
f'Error: GEOPHIRES failed to convert your currency for {ParamToModify.Name} to something it understands. '
f'You gave {strUnit} - conversion may be affected by https://github.com/NREL/GEOPHIRES-X/issues/236. '
f'Please change your units to {ParamToModify.PreferredUnits.value} '
f'to continue. Cannot continue unless you do. Exiting.'
)
print(msg)
model.logger.critical(str(ex))
Expand Down Expand Up @@ -710,6 +715,9 @@ def _parameter_with_currency_units_converted_back_to_preferred_units(param: Para
# start the currency conversion process
cc = CurrencyCodes()
try:
if _DISABLE_FOREX_API:
raise RuntimeError('Forex API disabled')

cr = CurrencyRates()
conv_rate = cr.get_rate(currType, prefType)
except BaseException as ex:
Expand Down Expand Up @@ -966,6 +974,9 @@ def ConvertOutputUnits(oparam: OutputParameter, newUnit: Units, model):

raise RuntimeError(msg)
try:
if _DISABLE_FOREX_API:
raise RuntimeError('Forex API disabled')

cr = CurrencyRates()
conv_rate = cr.get_rate(prefShort, currShort)
except BaseException as ex:
Expand Down
2 changes: 1 addition & 1 deletion src/geophires_x/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.6.1'
__version__ = '3.6.2'

0 comments on commit 450e84d

Please sign in to comment.