Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 14, 2023
1 parent c844729 commit d9188b7
Show file tree
Hide file tree
Showing 26 changed files with 183 additions and 218 deletions.
2 changes: 1 addition & 1 deletion binder/cli-simple/simple_output.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# papermill documentation build configuration file, created by
# sphinx-quickstart on Mon Jan 15 09:50:01 2018.
Expand Down
6 changes: 3 additions & 3 deletions papermill/abs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from azure.identity import EnvironmentCredential


class AzureBlobStore(object):
class AzureBlobStore:
"""
Represents a Blob of storage on Azure
Expand All @@ -20,7 +20,7 @@ class AzureBlobStore(object):

def _blob_service_client(self, account_name, sas_token=None):
blob_service_client = BlobServiceClient(
account_url="{account}.blob.core.windows.net".format(account=account_name),
account_url=f"{account_name}.blob.core.windows.net",
credential=sas_token or EnvironmentCredential(),
)

Expand All @@ -34,7 +34,7 @@ def _split_url(self, url):
"""
match = re.match(r"abs://(.*)\.blob\.core\.windows\.net\/(.*?)\/([^\?]*)\??(.*)$", url)
if not match:
raise Exception("Invalid azure blob url '{0}'".format(url))
raise Exception(f"Invalid azure blob url '{url}'")
else:
params = {
"account": match.group(1),
Expand Down
4 changes: 2 additions & 2 deletions papermill/adl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from azure.datalake.store import core, lib


class ADL(object):
class ADL:
"""
Represents an Azure Data Lake
Expand All @@ -23,7 +23,7 @@ def __init__(self):
def _split_url(cls, url):
match = re.match(r'adl://(.*)\.azuredatalakestore\.net\/(.*)$', url)
if not match:
raise Exception("Invalid ADL url '{0}'".format(url))
raise Exception(f"Invalid ADL url '{url}'")
else:
return (match.group(1), match.group(2))

Expand Down
1 change: 0 additions & 1 deletion papermill/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Main `papermill` interface."""

import os
Expand Down
12 changes: 6 additions & 6 deletions papermill/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .utils import merge_kwargs, remove_args, nb_kernel_name, nb_language


class PapermillEngines(object):
class PapermillEngines:
"""
The holder which houses any engine registered with the system.
Expand All @@ -40,7 +40,7 @@ def get_engine(self, name=None):
"""Retrieves an engine by name."""
engine = self._engines.get(name)
if not engine:
raise PapermillException("No engine named '{}' found".format(name))
raise PapermillException(f"No engine named '{name}' found")
return engine

def execute_notebook_with_engine(self, engine_name, nb, kernel_name, **kwargs):
Expand Down Expand Up @@ -78,7 +78,7 @@ def wrapper(self, *args, **kwargs):
return wrapper


class NotebookExecutionManager(object):
class NotebookExecutionManager:
"""
Wrapper for execution state of a notebook.
Expand Down Expand Up @@ -213,7 +213,7 @@ def cell_start(self, cell, cell_index=None, **kwargs):
"""
if self.log_output:
ceel_num = cell_index + 1 if cell_index is not None else ''
logger.info('Executing Cell {:-<40}'.format(ceel_num))
logger.info(f'Executing Cell {ceel_num:-<40}')

cell.metadata.papermill['start_time'] = self.now().isoformat()
cell.metadata.papermill["status"] = self.RUNNING
Expand Down Expand Up @@ -251,7 +251,7 @@ def cell_complete(self, cell, cell_index=None, **kwargs):

if self.log_output:
ceel_num = cell_index + 1 if cell_index is not None else ''
logger.info('Ending Cell {:-<43}'.format(ceel_num))
logger.info(f'Ending Cell {ceel_num:-<43}')
# Ensure our last cell messages are not buffered by python
sys.stdout.flush()
sys.stderr.flush()
Expand Down Expand Up @@ -322,7 +322,7 @@ def __del__(self):
self.cleanup_pbar()


class Engine(object):
class Engine:
"""
Base class for engines.
Expand Down
5 changes: 1 addition & 4 deletions papermill/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


class AwsError(Exception):
"""Raised when an AWS Exception is encountered."""

Expand Down Expand Up @@ -29,7 +26,7 @@ def __init__(self, cell_index, exec_count, source, ename, evalue, traceback):
self.evalue = evalue
self.traceback = traceback

super(PapermillExecutionError, self).__init__(*args)
super().__init__(*args)

def __str__(self):
# Standard Behavior of an exception is to produce a string representation of its arguments
Expand Down
4 changes: 1 addition & 3 deletions papermill/execute.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import nbformat
from pathlib import Path

Expand Down Expand Up @@ -85,7 +83,7 @@ def execute_notebook(
logger.info("Output Notebook: %s" % get_pretty_path(output_path))
with local_file_io_cwd():
if cwd is not None:
logger.info("Working directory: {}".format(get_pretty_path(cwd)))
logger.info(f"Working directory: {get_pretty_path(cwd)}")

nb = load_notebook_node(input_path)

Expand Down
3 changes: 1 addition & 2 deletions papermill/inspection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Deduce parameters of a notebook from the parameters cell."""
import click
from pathlib import Path
Expand Down Expand Up @@ -68,7 +67,7 @@ def display_notebook_help(ctx, notebook_path, parameters):
nb = _open_notebook(notebook_path, parameters)
click.echo(ctx.command.get_usage(ctx))
pretty_path = get_pretty_path(notebook_path)
click.echo("\nParameters inferred for notebook '{}':".format(pretty_path))
click.echo(f"\nParameters inferred for notebook '{pretty_path}':")

if not any_tagged_cell(nb, "parameters"):
click.echo("\n No cell tagged 'parameters'")
Expand Down
44 changes: 19 additions & 25 deletions papermill/iorw.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import os
import sys
import json
Expand Down Expand Up @@ -84,7 +82,7 @@ def fallback_gs_is_retriable(e):
FileNotFoundError = IOError


class PapermillIO(object):
class PapermillIO:
'''
The holder which houses any io system registered with the system.
This object is used in a singleton manner to save and load particular
Expand Down Expand Up @@ -156,9 +154,7 @@ def get_handler(self, path, extensions=None):
fnmatch.fnmatch(os.path.basename(path).split('?')[0], '*' + ext)
for ext in extensions
):
warnings.warn(
"The specified file ({}) does not end in one of {}".format(path, extensions)
)
warnings.warn(f"The specified file ({path}) does not end in one of {extensions}")

local_handler = None
for scheme, handler in self._handlers:
Expand All @@ -169,14 +165,12 @@ def get_handler(self, path, extensions=None):
return handler

if local_handler is None:
raise PapermillException(
"Could not find a registered schema handler for: {}".format(path)
)
raise PapermillException(f"Could not find a registered schema handler for: {path}")

return local_handler


class HttpHandler(object):
class HttpHandler:
@classmethod
def read(cls, path):
return requests.get(path, headers={'Accept': 'application/json'}).text
Expand All @@ -195,16 +189,16 @@ def pretty_path(cls, path):
return path


class LocalHandler(object):
class LocalHandler:
def __init__(self):
self._cwd = None

def read(self, path):
try:
with chdir(self._cwd):
with io.open(path, 'r', encoding="utf-8") as f:
with open(path, encoding="utf-8") as f:
return f.read()
except IOError as e:
except OSError as e:
try:
# Check if path could be a notebook passed in as a
# string
Expand All @@ -222,8 +216,8 @@ def write(self, buf, path):
with chdir(self._cwd):
dirname = os.path.dirname(path)
if dirname and not os.path.exists(dirname):
raise FileNotFoundError("output folder {} doesn't exist.".format(dirname))
with io.open(path, 'w', encoding="utf-8") as f:
raise FileNotFoundError(f"output folder {dirname} doesn't exist.")
with open(path, 'w', encoding="utf-8") as f:
f.write(buf)

def pretty_path(self, path):
Expand All @@ -236,7 +230,7 @@ def cwd(self, new_path):
return old_cwd


class S3Handler(object):
class S3Handler:
@classmethod
def read(cls, path):
return "\n".join(S3().read(path))
Expand All @@ -254,7 +248,7 @@ def pretty_path(cls, path):
return path


class ADLHandler(object):
class ADLHandler:
def __init__(self):
self._client = None

Expand All @@ -277,7 +271,7 @@ def pretty_path(self, path):
return path


class ABSHandler(object):
class ABSHandler:
def __init__(self):
self._client = None

Expand All @@ -300,7 +294,7 @@ def pretty_path(self, path):
return path


class GCSHandler(object):
class GCSHandler:
RATE_LIMIT_RETRIES = 3
RETRY_DELAY = 1
RETRY_MULTIPLIER = 1
Expand Down Expand Up @@ -339,7 +333,7 @@ def retry_write():
try:
message = e.message
except AttributeError:
message = "Generic exception {} raised".format(type(e))
message = f"Generic exception {type(e)} raised"
if gs_is_retriable(e):
raise PapermillRateLimitException(message)
# Reraise the original exception without retries
Expand All @@ -351,7 +345,7 @@ def pretty_path(self, path):
return path


class HDFSHandler(object):
class HDFSHandler:
def __init__(self):
self._client = None

Expand All @@ -375,7 +369,7 @@ def pretty_path(self, path):
return path


class GithubHandler(object):
class GithubHandler:
def __init__(self):
self._client = None

Expand Down Expand Up @@ -408,7 +402,7 @@ def pretty_path(self, path):
return path


class StreamHandler(object):
class StreamHandler:
'''Handler for Stdin/Stdout streams'''

def read(self, path):
Expand All @@ -429,7 +423,7 @@ def pretty_path(self, path):
return path


class NotebookNodeHandler(object):
class NotebookNodeHandler:
'''Handler for input_path of nbformat.NotebookNode object'''

def read(self, path):
Expand All @@ -445,7 +439,7 @@ def pretty_path(self, path):
return 'NotebookNode object'


class NoIOHandler(object):
class NoIOHandler:
'''Handler for output_path of None - intended to not write anything'''

def read(self, path):
Expand Down
2 changes: 1 addition & 1 deletion papermill/parameterize.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def parameterize_path(path, parameters):
try:
return path.format(**parameters)
except KeyError as key_error:
raise PapermillMissingParameterException("Missing parameter {}".format(key_error))
raise PapermillMissingParameterException(f"Missing parameter {key_error}")


def parameterize_notebook(
Expand Down
Loading

0 comments on commit d9188b7

Please sign in to comment.