initc3 / HoneyBadgerMPC

Robust MPC-based confidentiality layer for blockchains
GNU General Public License v3.0
131 stars 64 forks source link

FileNotFoundError: 'honeybadgermpc/logging.yaml' #377

Open sbellem opened 4 years ago

sbellem commented 4 years ago

This happens when trying to build the docs but could probably happen in other contexts as the problem stems from:

https://github.com/initc3/HoneyBadgerMPC/blob/6aec65f9a1e430316077bc98d548bda42571b4b3/honeybadgermpc/__init__.py#L10

Error trace when building the docs:

$ make -C docs html
WARNING: autodoc: failed to import module 'honeybadgermpc'; the following exception was raised:         
Traceback (most recent call last):                                                                      
  File "/opt/venv/lib/python3.7/site-packages/sphinx/ext/autodoc/importer.py", line 32, in import_module
    return importlib.import_module(modname)                                                                                            
  File "/opt/venv/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)                                         
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import           
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load               
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked  
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked              
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module        
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed       
  File "/usr/src/HoneyBadgerMPC/honeybadgermpc/__init__.py", line 12, in <module>    
    with open("honeybadgermpc/logging.yaml", "r") as f:                                                                        
FileNotFoundError: [Errno 2] No such file or directory: 'honeybadgermpc/logging.yaml'

This can be fixed by specifying a path with respect to the module (file) the code is in:

# honeybadgermpc/__init__.py
from pathlib import Path

CURRENT_DIR = Path(__file__).parent
ROOT_DIR = CURRENT_DIR.parent

# with open("honeybadgermpc/logging.yaml", "r") as f:
with open(CURRENT_DIR / "logging.yaml", "r") as f:
    os.makedirs(ROOT_DIR / "benchmark-logs", exist_ok=True)
sbellem commented 4 years ago

Re-opening as the problem still occurs when the project is not installed in development/editable mode, which means without the --editable or -e option with pip for instance. In other words, if the project is installed with pip install . or python setup.py install the problem will happen.

To properly resolve the issue, we should look into putting the logging config file under the home directory such as ~/.hbmpc/logging.yml or ~/.config/hbmpc/logging.yml. This means that when the project is installed (via pip for instance), the config file would get copied to a chosen location, such as ~/.config/hbmpc/logging.yml.

If that is not too much work, it may perhaps be worthwhile to have a general config file, e.g.: ~/.hbmpc/config.yml which contains the logging configuration as well as other configurable elements.

Resources