NREL / buildstockbatch

Other
22 stars 14 forks source link

Refactor to use src layout #473

Closed lixiliu closed 3 weeks ago

lixiliu commented 1 month ago

Describe the bug After creating a venv and installing in it BuildStockBatch, I ran into ModuleNotFound error on installed packages (e.g., pandas, boto3) when simply calling buildstock_local --help. This problem went away after I deactivated and reactivated the env.

A person who helped me debug suggest that it could due to the flat layout of the code base. I could not use the env right after the installation because ipython was running from a different environment (where the packages were not installed) rather than from the env I just created.

In any case, we should consider following the src layout instead. https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/

rajeee commented 4 weeks ago

I didn't encounter any issues when following the instruction here: https://buildstockbatch.readthedocs.io/en/stable/installation.html

Both conda or venv environment works. Can you provide more detailed step by step reproduction instruction?

lixiliu commented 3 weeks ago

I can't reproduce the same error because I have accidentally installed some packages in my base environment, and it is making buildstock_local --help to work right after installation. But remnant of the issue can be seen here (see the second to the last line of the printout on "bad_interpreter").

(base)  ✘ lliu2@lliu2-37164s  ~/Documents/GitHub/buildstockbatch   develop  python -m venv ~/envs/bsb 
(base)  lliu2@lliu2-37164s  ~/Documents/GitHub/buildstockbatch   develop  source ~/envs/bsb/bin/activate       
(bsb) (base)  lliu2@lliu2-37164s  ~/Documents/GitHub/buildstockbatch   develop  python -m pip install -e ".[dev]"    
### package being installed (not copying the output here)...
Successfully built buildstockbatch

(bsb) (base)  lliu2@lliu2-37164s  ~/Documents/GitHub/buildstockbatch   develop  buildstock_local -h                  
zsh: /Users/lliu2/.local/bin/buildstock_local: bad interpreter: /Users/lliu2/micromamba/envs/bsb/bin/python: no such file or directory

     _ __         _     __,              _ __
    ( /  )    o  //   /(    _/_       / ( /  )     _/_    /
     /--< , ,,  // __/  `.  /  __ _, /<  /--< __,  /  _, /
    /___/(_/_(_(/_(_/_(___)(__(_)(__/ |_/___/(_/(_(__(__/ /_
      Executing BuildStock projects with grace since 2018

It's clear that buildstock_local is looking for packages from certain paths. And the bad_interpreter error goes away when I deactivate and reactivate the env:

(bsb) (base)  lliu2@lliu2-37164s  ~/Documents/GitHub/buildstockbatch   develop  deactivate                       
(base)  lliu2@lliu2-37164s  ~/Documents/GitHub/buildstockbatch   develop  source ~/envs/bsb/bin/activate   
(bsb) (base)  lliu2@lliu2-37164s  ~/Documents/GitHub/buildstockbatch   develop  buildstock_local -h           

     _ __         _     __,              _ __
    ( /  )    o  //   /(    _/_       / ( /  )     _/_    /
     /--< , ,,  // __/  `.  /  __ _, /<  /--< __,  /  _, /
    /___/(_/_(_(/_(_/_(___)(__(_)(__/ |_/___/(_/(_(__(__/ /_
      Executing BuildStock projects with grace since 2018
lixiliu commented 3 weeks ago

Maybe it's not worth tracking this down at the moment. I'll be good to close the issue.

afontani commented 3 weeks ago

Currently cannot reproduce. There might be some benefits to having a src layout. We will revisit in the future.