Skip to content

Commit

Permalink
file not found error fix if pybc.toml not exists (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
o-murphy authored Apr 11, 2024
1 parent 564a6f5 commit 2c3145c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
55 changes: 28 additions & 27 deletions py_ballisticcalc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,35 @@ def find_pybc_toml(start_dir=os.getcwd()):

if filepath is None:
if (filepath := find_pybc_toml()) is None:
find_pybc_toml(os.path.dirname(__file__))

logger.debug(f"Found {os.path.basename(filepath)} at {os.path.dirname(filepath)}")

with open(filepath, "rb") as fp:
_config = tomllib.load(fp)

if _pybc := _config.get('pybc'):
if preferred_units := _pybc.get('preferred_units'):
PreferredUnits.set(**preferred_units)
else:
logger.warning("Config has not `pybc.preferred_units` section")

if calculator := _pybc.get('calculator'):
if max_calc_step_size := calculator.get('max_calc_step_size'):
try:
_val = max_calc_step_size.get("value")
_units = Unit[max_calc_step_size.get("units")]
set_global_max_calc_step_size(_units(_val))
except (KeyError, TypeError, ValueError):
logger.warning("Wrong max_calc_step_size units or value")

if use_powder_sensitivity := calculator.get('use_powder_sensitivity'):
set_global_use_powder_sensitivity(use_powder_sensitivity)
filepath = find_pybc_toml(os.path.dirname(__file__))

if filepath is not None:
logger.debug(f"Found {os.path.basename(filepath)} at {os.path.dirname(filepath)}")

with open(filepath, "rb") as fp:
_config = tomllib.load(fp)

if _pybc := _config.get('pybc'):
if preferred_units := _pybc.get('preferred_units'):
PreferredUnits.set(**preferred_units)
else:
logger.warning("Config has not `pybc.preferred_units` section")

if calculator := _pybc.get('calculator'):
if max_calc_step_size := calculator.get('max_calc_step_size'):
try:
_val = max_calc_step_size.get("value")
_units = Unit[max_calc_step_size.get("units")]
set_global_max_calc_step_size(_units(_val))
except (KeyError, TypeError, ValueError):
logger.warning("Wrong max_calc_step_size units or value")

if use_powder_sensitivity := calculator.get('use_powder_sensitivity'):
set_global_use_powder_sensitivity(use_powder_sensitivity)
else:
logger.warning("Config has not `pybc.calculator` section")
else:
logger.warning("Config has not `pybc.calculator` section")
else:
logger.warning("Config has not `pybc` section")
logger.warning("Config has not `pybc` section")


def _basic_config(filename=None,
Expand Down
2 changes: 1 addition & 1 deletion py_ballisticcalc_exts/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "py_ballisticcalc.exts"
version = "2.0.0"
version = "2.0.1"

authors = [
{ name="o-murphy", email="[email protected]" },
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "py_ballisticcalc"
version = "2.0.0"
version = "2.0.1"

authors = [
{ name="o-murphy", email="[email protected]" },
Expand Down Expand Up @@ -54,6 +54,6 @@ exclude = ["py_ballisticcalc_exts*"]


[project.optional-dependencies]
exts = ['py_ballisticcalc.exts==2.0.0']
exts = ['py_ballisticcalc.exts==2.0.1']
lint = ['pylint', 'flake8']
charts = ['matplotlib', 'pandas']

0 comments on commit 2c3145c

Please sign in to comment.