-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split install and configure commands #38
Merged
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ab34181
Split install and configure commands. Add option to specify config fi…
jayqi b3674a7
Update tests with different help text
jayqi 1e2ef93
Help text
jayqi 05637b5
Rename test_cli_install to test_cli_configure
jayqi a9bb3d6
Fix tests for configure command
jayqi ad5853c
New tests for install command
jayqi 0249bd5
Message about restarting
jayqi 0079dc3
Add warnings to configure command about installation
jayqi b17d70c
Replace pkg_resources.parse_version with lighter-weight packaging.ver…
jayqi ff79087
Fix arg ordering on install_sentinel
jayqi 22fcf2b
Change install_sentinel interface to not reproduce config fields
jayqi 5adeff1
Rename --config-file to --jupyter-config to be more clear
jayqi b253b89
codecov.yml to allow 2% decrease in coverage
jayqi d05b73f
Add patch coverage threshold
jayqi 7dfcecc
Patch JUPYTER_CONFIG_DIR env var instead of function in CLI tests
jayqi ebc2755
Update test names
jayqi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
codecov: | ||
require_ci_to_pass: yes | ||
|
||
coverage: | ||
precision: 1 | ||
round: down | ||
range: "70...100" | ||
status: | ||
project: # Coverage of whole project | ||
default: | ||
target: auto # Coverage target to pass; auto is base commit | ||
threshold: 2% # Allow coverage to drop by this much vs. base and still pass | ||
patch: # Coverage of lines in this change | ||
default: | ||
target: 80% # Coverage target to pass | ||
threshold: 20% # Allow coverage to drop by this much vs. base and still pass | ||
|
||
|
||
comment: | ||
layout: "diff,flags,tree" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
jupyter-contrib-nbextensions>=0.5.1 | ||
nbconvert>=5.6.1 | ||
packaging | ||
pydantic | ||
typer>=0.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
"""Tests for `nbautoexport` package.""" | ||
|
||
import json | ||
|
||
from typer.testing import CliRunner | ||
|
||
from nbautoexport import jupyter_config, nbautoexport | ||
from nbautoexport.nbautoexport import app | ||
from nbautoexport.sentinel import ( | ||
DEFAULT_CLEAN, | ||
DEFAULT_EXPORT_FORMATS, | ||
DEFAULT_ORGANIZE_BY, | ||
NbAutoexportConfig, | ||
SAVE_PROGRESS_INDICATOR_FILE, | ||
) | ||
|
||
|
||
def test_configure_defaults(tmp_path): | ||
result = CliRunner().invoke(app, ["configure", str(tmp_path)]) | ||
assert result.exit_code == 0 | ||
|
||
config = NbAutoexportConfig.parse_file( | ||
path=tmp_path / SAVE_PROGRESS_INDICATOR_FILE, content_type="application/json" | ||
) | ||
|
||
expected_config = NbAutoexportConfig() | ||
assert config == expected_config | ||
|
||
|
||
def test_configure_specified(tmp_path): | ||
export_formats = ["script", "html"] | ||
organize_by = "extension" | ||
clean = True | ||
assert export_formats != DEFAULT_EXPORT_FORMATS | ||
assert organize_by != DEFAULT_ORGANIZE_BY | ||
assert clean != DEFAULT_CLEAN | ||
|
||
cmd_list = ["configure", str(tmp_path)] | ||
for fmt in export_formats: | ||
cmd_list.extend(["-f", fmt]) | ||
cmd_list.extend(["-b", organize_by]) | ||
if clean: | ||
cmd_list.append("--clean") | ||
|
||
result = CliRunner().invoke(app, cmd_list) | ||
assert result.exit_code == 0 | ||
|
||
config = NbAutoexportConfig.parse_file( | ||
path=tmp_path / SAVE_PROGRESS_INDICATOR_FILE, content_type="application/json" | ||
) | ||
|
||
expected_config = NbAutoexportConfig( | ||
export_formats=export_formats, organize_by=organize_by, clean=clean | ||
) | ||
assert config == expected_config | ||
|
||
|
||
def test_invalid_export_format(): | ||
runner = CliRunner() | ||
result = runner.invoke(app, ["configure", "-f", "invalid-output-format"]) | ||
assert result.exit_code == 2 | ||
assert ( | ||
"Error: Invalid value for '--export-format' / '-f': invalid choice: invalid-output-format" | ||
in result.output | ||
) | ||
|
||
|
||
def test_invalid_organize_by(): | ||
runner = CliRunner() | ||
result = runner.invoke(app, ["configure", "-b", "invalid-organize-by"]) | ||
assert result.exit_code == 2 | ||
assert ( | ||
"Invalid value for '--organize-by' / '-b': invalid choice: invalid-organize-by" | ||
in result.output | ||
) | ||
|
||
|
||
def test_refuse_overwrite(tmp_path): | ||
(tmp_path / ".nbautoexport").touch() | ||
runner = CliRunner() | ||
result = runner.invoke(app, ["configure", str(tmp_path)]) | ||
assert result.exit_code == 1 | ||
assert "Detected existing autoexport configuration at" in result.output | ||
|
||
|
||
def test_force_overwrite(tmp_path): | ||
(tmp_path / ".nbautoexport").touch() | ||
runner = CliRunner() | ||
result = runner.invoke( | ||
app, ["configure", str(tmp_path), "-o", "-f", "script", "-f", "html", "-b", "notebook"] | ||
) | ||
assert result.exit_code == 0 | ||
with (tmp_path / ".nbautoexport").open("r") as fp: | ||
config = json.load(fp) | ||
|
||
expected_config = NbAutoexportConfig(export_formats=["script", "html"], organize_by="notebook") | ||
assert config == expected_config | ||
|
||
|
||
def test_install_no_jupyter_config_warning(tmp_path, monkeypatch): | ||
def mock_jupyter_config_dir(): | ||
return str(tmp_path) | ||
|
||
monkeypatch.setattr(jupyter_config, "jupyter_config_dir", mock_jupyter_config_dir) | ||
|
||
result = CliRunner().invoke(app, ["configure", str(tmp_path)]) | ||
assert result.exit_code == 0 | ||
assert "Warning: nbautoexport is not properly installed with Jupyter." in result.output | ||
jayqi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def test_install_no_initialize_warning(tmp_path, monkeypatch): | ||
def mock_jupyter_config_dir(): | ||
return str(tmp_path) | ||
|
||
monkeypatch.setattr(jupyter_config, "jupyter_config_dir", mock_jupyter_config_dir) | ||
|
||
(tmp_path / "jupyter_notebook_config.py").touch() | ||
|
||
result = CliRunner().invoke(app, ["configure", str(tmp_path)]) | ||
assert result.exit_code == 0 | ||
assert "Warning: nbautoexport is not properly installed with Jupyter." in result.output | ||
|
||
|
||
def test_install_oudated_initialize_warning(tmp_path, monkeypatch): | ||
def mock_jupyter_config_dir(): | ||
return str(tmp_path) | ||
|
||
monkeypatch.setattr(nbautoexport, "jupyter_config_dir", mock_jupyter_config_dir) | ||
|
||
jupyter_config_path = tmp_path / "jupyter_notebook_config.py" | ||
with jupyter_config_path.open("w") as fp: | ||
initialize_block = jupyter_config.version_regex.sub( | ||
"0", jupyter_config.post_save_hook_initialize_block | ||
) | ||
fp.write(initialize_block) | ||
|
||
result = CliRunner().invoke(app, ["configure", str(tmp_path)]) | ||
assert result.exit_code == 0 | ||
assert "Warning: nbautoexport initialize is an older version." in result.output | ||
|
||
|
||
def test_install_no_warning(tmp_path, monkeypatch): | ||
def mock_jupyter_config_dir(): | ||
return str(tmp_path) | ||
|
||
monkeypatch.setattr(jupyter_config, "jupyter_config_dir", mock_jupyter_config_dir) | ||
monkeypatch.setattr(nbautoexport, "jupyter_config_dir", mock_jupyter_config_dir) | ||
|
||
jupyter_config.install_post_save_hook(tmp_path / "jupyter_notebook_config.py") | ||
|
||
result = CliRunner().invoke(app, ["configure", str(tmp_path)]) | ||
assert result.exit_code == 0 | ||
assert "Warning:" not in result.output |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah just noticing that
typer
very nicely adjusts the width of these docstrings when they are printed out in the command line. Now the docstrings can be written with column width of 100 in the source code, but printed out to column width of 80 for the 0.1% of ppl who use ancient monitors.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this actually annoyed me recently for a different project where I wanted to put some ASCII art in my help string but
typer
totally destroyed it with formatting. 😂 😢