Skip to content

Commit

Permalink
remove telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
edublancas committed Sep 18, 2024
1 parent e1633df commit 373cac8
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 248 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.0.20dev

* Removes telemetry

## 0.0.19 (2022-08-30)
* Changes telemetry key

Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,3 @@ Whatever your skillset is, you can contribute to our mission. So whether you're

[Click here to know how you can contribute to Ploomber.](https://github.com/ploomber/contributing/blob/main/README.md)


## Telemetry

We collect anonymous statistics to understand and improve usage. For details, [see here](https://docs.ploomber.io/en/latest/community/user-stats.html)
39 changes: 18 additions & 21 deletions src/soorgeon/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,26 @@
import jupytext

from soorgeon.exceptions import BaseException
from soorgeon.telemetry import telemetry


def _jupytext_fmt(text, extension):
"""
Determine the jupytext fmt string to use based on the content and extension
"""
if extension != 'ipynb':
if extension != "ipynb":
fmt, _ = jupytext.guess_format(text, extension)
fmt_final = f'{extension}:{fmt}'
fmt_final = f"{extension}:{fmt}"
else:
fmt_final = '.ipynb'
fmt_final = ".ipynb"

return fmt_final


@telemetry.log_call('lint')
def lint(task_file):
with get_file(task_file, write=False, output_ext=".py") as path:
run_program(path, program='flake8', filename=task_file)
run_program(path, program="flake8", filename=task_file)


@telemetry.log_call('clean')
def basic_clean(task_file, program="black", string_normalization=True):
"""
Run basic clean (directly called by cli.clean())
Expand All @@ -47,10 +44,9 @@ def clean_py(task_file_py, filename, string_normalization=True):
mode = FileMode(string_normalization=string_normalization)

# reformat with black
black_result = format_file_in_place(task_file_py,
fast=True,
mode=mode,
write_back=WriteBack(1))
black_result = format_file_in_place(
task_file_py, fast=True, mode=mode, write_back=WriteBack(1)
)
if black_result:
click.echo(f"Reformatted {filename} with black.")

Expand All @@ -61,12 +57,12 @@ def run_program(task_file_py, program, filename):
(util method only called by basic_clean())
"""
if shutil.which(program) is None:
raise BaseException(f'{program} is missing, please install it with:\n'
f'pip install {program}\nand try again')
raise BaseException(
f"{program} is missing, please install it with:\n"
f"pip install {program}\nand try again"
)
# black
result = subprocess.run([program, task_file_py],
text=True,
capture_output=True)
result = subprocess.run([program, task_file_py], text=True, capture_output=True)

click.echo(result.stdout.replace(str(task_file_py), filename))
click.echo(result.stderr)
Expand All @@ -81,8 +77,7 @@ def get_file(task_file, write=False, output_ext=".ipynb"):

if create_temp:
nb = jupytext.reads(text)
temp_path = tempfile.NamedTemporaryFile(suffix=output_ext,
delete=False).name
temp_path = tempfile.NamedTemporaryFile(suffix=output_ext, delete=False).name
jupytext.write(nb, temp_path)
path = Path(temp_path)

Expand All @@ -93,9 +88,11 @@ def get_file(task_file, write=False, output_ext=".ipynb"):
yield path
finally:
if write:
jupytext.write(jupytext.read(path),
task_file,
fmt=_jupytext_fmt(text, task_file.suffix[1:]))
jupytext.write(
jupytext.read(path),
task_file,
fmt=_jupytext_fmt(text, task_file.suffix[1:]),
)

if create_temp:
Path(path).unlink()
132 changes: 69 additions & 63 deletions src/soorgeon/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from click.exceptions import ClickException
from papermill.exceptions import PapermillExecutionError
from os.path import abspath, dirname, splitext, join
from soorgeon.telemetry import telemetry
from soorgeon import __version__, export
from soorgeon import clean as clean_module

Expand All @@ -17,36 +16,36 @@ def cli():


@cli.command()
@click.argument('path', type=click.Path(exists=True))
@click.option('--log', '-l', default=None)
@click.argument("path", type=click.Path(exists=True))
@click.option("--log", "-l", default=None)
@click.option(
'--df-format',
'-d',
"--df-format",
"-d",
default=None,
type=click.Choice(('parquet', 'csv')),
help='Format for variables with the df prefix. Otherwise uses pickle')
@click.option('--product-prefix',
'-p',
default=None,
help='Prefix for all products')
@click.option('--single-task',
'-s',
is_flag=True,
help='Create a pipeline with a single task')
type=click.Choice(("parquet", "csv")),
help="Format for variables with the df prefix. Otherwise uses pickle",
)
@click.option("--product-prefix", "-p", default=None, help="Prefix for all products")
@click.option(
'--file-format',
'-f',
"--single-task", "-s", is_flag=True, help="Create a pipeline with a single task"
)
@click.option(
"--file-format",
"-f",
default=None,
type=click.Choice(("py", "ipynb")),
help=("Format for pipeline tasks, if empty keeps the same format " "as the input"),
)
@click.option(
"--serializer",
"-z",
default=None,
type=click.Choice(('py', 'ipynb')),
help=('Format for pipeline tasks, if empty keeps the same format '
'as the input'))
@click.option('--serializer',
'-z',
default=None,
type=click.Choice(('cloudpickle', 'dill')),
help='Serializer for non-picklable data')
def refactor(path, log, product_prefix, df_format, single_task, file_format,
serializer):
type=click.Choice(("cloudpickle", "dill")),
help="Serializer for non-picklable data",
)
def refactor(
path, log, product_prefix, df_format, single_task, file_format, serializer
):
"""
Refactor a monolithic notebook.
Expand All @@ -64,18 +63,20 @@ def refactor(path, log, product_prefix, df_format, single_task, file_format,
# apply black
clean_module.basic_clean(path, string_normalization=False)

export.refactor(path,
log,
product_prefix=product_prefix,
df_format=df_format,
single_task=single_task,
file_format=file_format,
serializer=serializer)
export.refactor(
path,
log,
product_prefix=product_prefix,
df_format=df_format,
single_task=single_task,
file_format=file_format,
serializer=serializer,
)

click.secho(f'Finished refactoring {path!r}, use Ploomber to continue.',
fg='green')
click.secho(f"Finished refactoring {path!r}, use Ploomber to continue.", fg="green")

click.echo("""
click.echo(
"""
Install dependencies (this will install ploomber):
$ pip install -r requirements.txt
Expand All @@ -91,7 +92,8 @@ def refactor(path, log, product_prefix, df_format, single_task, file_format,
* Documentation: https://docs.ploomber.io
* Jupyter integration: https://ploomber.io/s/jupyter
* Other editors: https://ploomber.io/s/editors
""")
"""
)


@cli.command()
Expand Down Expand Up @@ -126,9 +128,7 @@ def lint(filename):

@cli.command()
@click.argument("filename", type=click.Path(exists=True))
@click.argument("output_filename",
type=click.Path(exists=False),
required=False)
@click.argument("output_filename", type=click.Path(exists=False), required=False)
def test(filename, output_filename):
"""
check if a .py or .ipynb file runs.
Expand All @@ -149,61 +149,67 @@ def test(filename, output_filename):
output_filename = join(directory, f"{name}-soorgeon-test.ipynb")
else:
output_filename = join(directory, output_filename)
if extension.lower() == '.py':
if extension.lower() == ".py":
nb = jupytext.read(filename)
# convert ipynb to py and create a temp file in current directory
with tempfile.NamedTemporaryFile(suffix=".ipynb",
delete=True,
dir=directory) as temp_file:
with tempfile.NamedTemporaryFile(
suffix=".ipynb", delete=True, dir=directory
) as temp_file:
jupytext.write(nb, temp_file.name)
_test(temp_file.name, output_filename)
else:
_test(filename, output_filename)


@telemetry.log_call('test')
def _test(filename, output_filename):
CONTACT_MESSAGE = "An error happened when executing the notebook, " \
"contact us for help: https://ploomber.io/community"
CONTACT_MESSAGE = (
"An error happened when executing the notebook, "
"contact us for help: https://ploomber.io/community"
)
try:
pm.execute_notebook(filename, output_filename, kernel_name='python3')
pm.execute_notebook(filename, output_filename, kernel_name="python3")
except PapermillExecutionError as err:
error_traceback = err.traceback
error_suggestion_dict = {
"ModuleNotFoundError":
"Some packages are missing, please install them "
"ModuleNotFoundError": "Some packages are missing, please install them "
"with 'pip install {package-name}'\n",
"AttributeError":
"AttributeErrors might be due to changes in the libraries "
"AttributeError": "AttributeErrors might be due to changes in the libraries "
"you're using.\n",
"SyntaxError":
"There are syntax errors in the notebook.\n",
"SyntaxError": "There are syntax errors in the notebook.\n",
}
for error, suggestion in error_suggestion_dict.items():
if any(error in error_line for error_line in error_traceback):
click.secho(f"""\
click.secho(
f"""\
{error} encountered while executing the notebook: {err}
{suggestion}
Output notebook: {output_filename}\n""",
fg='red')
fg="red",
)
raise ClickException(CONTACT_MESSAGE)

click.secho(f"""\
click.secho(
f"""\
Error encountered while executing the notebook: {err}
Output notebook: {output_filename}\n""",
fg='red')
fg="red",
)
raise ClickException(CONTACT_MESSAGE)
except Exception as err:
# handling errors other than PapermillExecutionError
error_type = type(err).__name__
click.echo(f"""\
click.echo(
f"""\
{error_type} encountered while executing the notebook: {err}
Output notebook: {output_filename}""")
Output notebook: {output_filename}"""
)
raise ClickException(CONTACT_MESSAGE)
else:
click.secho(f"""\
click.secho(
f"""\
Finished executing {filename}, no error encountered.
Output notebook: {output_filename}\n""",
fg='green')
fg="green",
)
Loading

0 comments on commit 373cac8

Please sign in to comment.