Skip to content

Commit

Permalink
Fixes #36
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed May 19, 2020
1 parent c5f1d36 commit a314bc1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
24 changes: 17 additions & 7 deletions jupyter_conda/envmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ def get_info(env):

return {"environments": envs_list}

async def update_env(self, env: str, file_content: str, file_name: str = "environment.yml") -> Dict[str, str]:
async def update_env(
self, env: str, file_content: str, file_name: str = "environment.yml"
) -> Dict[str, str]:
"""Update a environment from a file.
Args:
Expand Down Expand Up @@ -512,8 +514,9 @@ async def list_available(self) -> Dict[str, List[Dict[str, str]]]:
try: # Skip if file is not accessible
with open(path) as f:
channeldata = json.load(f)
except OSError as err:
self.log.info("[jupyter_conda] Error: {}".format(str(err)))
except (json.JSONDecodeError, OSError, ValueError) as err:
self.log.info("[jupyter_conda] {!s} skipped".format(path))
self.log.debug(str(err))
else:
pkg_info.update(channeldata["packages"])
else:
Expand All @@ -527,13 +530,20 @@ async def list_available(self) -> Dict[str, List[Dict[str, str]]]:
)
except Exception as e:
self.log.info(
"[jupyter_conda] Error getting {}/channeldata.json: {}".format(
channel, str(e)
)
"[jupyter_conda] {}/channeldata.json skipped.".format(channel)
)
self.log.debug(str(e))
else:
channeldata = response.body.decode("utf-8")
pkg_info.update(json.loads(channeldata)["packages"])
try:
pkg_info.update(json.loads(channeldata)["packages"])
except (json.JSONDecodeError, ValueError) as error:
self.log.info(
"[jupyter_conda] {}/channeldata.json skipped.".format(
channel
)
)
self.log.debug(str(error))

# Example structure channeldata['packages'] for channeldata_version == 1
# "tmpc0d7d950": {
Expand Down
25 changes: 9 additions & 16 deletions jupyter_conda/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async def get(self):
self.finish(tornado.escape.json_encode(list_envs))

@tornado.web.authenticated
async def post(self):
def post(self):
"""`POST /environments` creates an environment.
Method of creation depends on the request data (first find is used):
Expand Down Expand Up @@ -220,7 +220,7 @@ class EnvironmentHandler(EnvBaseHandler):
"""Environment handler."""

@tornado.web.authenticated
async def delete(self, env: str):
def delete(self, env: str):
"""`DELETE /environments/<env>` deletes an environment."""
idx = self._stack.put(self.env_manager.delete_env, env)

Expand Down Expand Up @@ -263,7 +263,6 @@ async def get(self, env: str):
self.finish(tornado.escape.json_encode(packages))

@tornado.web.authenticated
@tornado.gen.coroutine
def patch(self, env: str):
"""`PATCH /environments/<env>` update an environment.
Expand All @@ -286,7 +285,7 @@ class PackagesEnvironmentHandler(EnvBaseHandler):
"""Handle actions on environment packages."""

@tornado.web.authenticated
async def delete(self, env: str):
def delete(self, env: str):
"""`DELETE /environments/<env>/packages` delete some packages.
Request json body:
Expand All @@ -300,7 +299,7 @@ async def delete(self, env: str):
self.redirect_to_task(idx)

@tornado.web.authenticated
async def patch(self, env: str):
def patch(self, env: str):
"""`PATCH /environments/<env>/packages` update some packages.
If no packages are provided, update all possible packages.
Expand All @@ -316,7 +315,7 @@ async def patch(self, env: str):
self.redirect_to_task(idx)

@tornado.web.authenticated
async def post(self, env: str):
def post(self, env: str):
"""`POST /environments/<env>/packages` install some packages.
Packages can be installed in development mode. In that case,
Expand Down Expand Up @@ -366,11 +365,8 @@ async def get(self):
with open(cache_file) as cache:
cache_data = cache.read()
except OSError as e:
logger.info(
"[jupyter_conda] No available packages list in cache {!s}.".format(
e
)
)
logger.info("[jupyter_conda] No available packages list in cache.")
logger.debug(str(e))

async def update_available(
env_manager: EnvManager, cache_file: str, return_packages: bool = True
Expand All @@ -380,11 +376,8 @@ async def update_available(
with open(cache_file, "w+") as cache:
json.dump(answer, cache)
except (ValueError, OSError) as e:
logger.info(
"[jupyter_conda] Fail to cache available packages {!s}.".format(
e
)
)
logger.info("[jupyter_conda] Fail to cache available packages.")
logger.debug(str(e))
else:
# Change rights to ensure every body can update the cache
os.chmod(
Expand Down

0 comments on commit a314bc1

Please sign in to comment.