IN-CORE / pyincore

pyIncore is a component of IN-CORE. It is a python package consisting of two primary components: 1) a set of service classes to interact with the IN-CORE web services, and 2) IN-CORE analyses . The pyIncore allows users to apply various hazards to infrastructure in selected areas, propagating the effect of physical infrastructure damage and loss of functionality to social and economic impacts.
Mozilla Public License 2.0
25 stars 7 forks source link

458 check offline mode and disable method interact with services #476

Closed longshuicy closed 10 months ago

longshuicy commented 10 months ago

Wrote custom decorator to check "self.client.offline" flag. This allows the flexibility to add to only those methods interact with the services.


To test: You can either try the below one example

from pyincore import IncoreClient, SpaceService

if __name__ == "__main__":
    # client = IncoreClient(offline=True)
    client = IncoreClient()
    spacesvc_offline = SpaceService(client)
    metadata = spacesvc_offline.get_spaces()

you should see an error message

ValueError: Service is not available in offline mode.

For more comprehensive test, run some of the incore-docs notebooks E.g. in create_earthquake.ipynb change "offline=True" in client, and observe failure. E.g. try session4-building-dmg-recovery-local-data.ipynb, should pass with no issue

navarroc commented 10 months ago

Overall looks good, just some minor unused imports that should be removed. Should be good to merge after that.

longshuicy commented 10 months ago

Overall looks good, just some minor unused imports that should be removed. Should be good to merge after that.

I removed the unused imports and pep8 related issue in the files I touched. But I noticed there might be more. Maybe it's time we start to look into black formatter in the next release? https://black.readthedocs.io/en/stable/

Here is an clowder example of using black and github action to check that https://github.com/clowder-framework/clowder2/blob/main/.github/workflows/black.yml

navarroc commented 10 months ago

Overall looks good, just some minor unused imports that should be removed. Should be good to merge after that.

I removed the unused imports and pep8 related issue in the files I touched. But I noticed there might be more. Maybe it's time we start to look into black formatter in the next release? https://black.readthedocs.io/en/stable/

Here is an clowder example of using black and github action to check that https://github.com/clowder-framework/clowder2/blob/main/.github/workflows/black.yml

It might be good to do that after this release and clean things up.