Skip to content

Commit

Permalink
Merge pull request #104 from chmp/feature/cleanup
Browse files Browse the repository at this point in the history
Feature/cleanup
  • Loading branch information
chmp authored Jan 16, 2024
2 parents 973ae19 + e6f6dea commit 85682ed
Show file tree
Hide file tree
Showing 15 changed files with 2,532 additions and 1,288 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@
"name": "Test",
"on": {
"workflow_dispatch": {},
"pull_request": {
"branches": [
"main"
],
"types": [
"ready_for_review",
"synchronize"
]
}
"pull_request": {}
},
"jobs": {
"build": {
Expand All @@ -30,13 +22,21 @@
"name": "Install dependencies",
"run": "python -m pip install --upgrade pip\npip install -r requirements-dev.txt\npip install -e ."
},
{
"name": "Check format",
"run": "python -m ruff format --check ."
},
{
"name": "Check lints",
"run": "python -m ruff check ."
},
{
"name": "Tests",
"run": "pytest"
"run": "python -m pytest"
},
{
"name": "Integration tests",
"run": "pytest --nbval-lax --nbval-current-env Example.ipynb tests/Test*.ipynb"
"run": "python -m pytest --nbval-lax --nbval-current-env Example.ipynb tests/Test*.ipynb"
}
]
}
Expand Down
10 changes: 10 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

Note: development is tracked on the [`develop` branch](https://github.com/chmp/ipytest/tree/develop).

## `0.14.0`

- Removed support for Python 3.7 since reached its end of life
- Updated the dev-requirements
- Remove deprecated API (`ipytest.clean_tests`, `%%pytest`, `%%pytest[clean]`)

## `0.13.3`

- Include License.md file in sdist for condaforge

## `0.13.2`

- Fix assertion rewriting for python==3.11 ([issue][issue-93])
Expand Down
2 changes: 1 addition & 1 deletion License.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The MIT License (MIT)
Copyright (c) 2015 - 2023 Christopher Prohm
Copyright (c) 2015 - 2024 Christopher Prohm

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Expand Down
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ See [`ipytest.config`][ipytest.config] for details.

[ipytest.ipytest]: #ipytest-

<!-- minidoc "function": "ipytest._impl.pytest_magic", "header": false, "header_depth": 3 -->
<!-- minidoc "function": "ipytest._impl.ipytest_magic", "header": false, "header_depth": 3 -->
IPython magic to first execute the cell, then execute [`ipytest.run()`][ipytest.run].

**Note:** the magics are only available after running
Expand Down Expand Up @@ -354,7 +354,7 @@ Please create an issue, if I missed a packaged or mischaracterized any package.

```
The MIT License (MIT)
Copyright (c) 2015 - 2023 Christopher Prohm
Copyright (c) 2015 - 2024 Christopher Prohm
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Expand Down
3 changes: 1 addition & 2 deletions ipytest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ._config import autoconfig, config
from ._impl import Error, clean, clean_tests, force_reload, reload, run
from ._impl import Error, clean, force_reload, reload, run

# the pytest exit code
exit_code = None
Expand All @@ -10,7 +10,6 @@
"run",
"config",
"clean",
"clean_tests",
"force_reload",
"reload",
"Error",
Expand Down
75 changes: 2 additions & 73 deletions ipytest/_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Add syntatic sugar for configuration"""
import inspect
import sys
import warnings

default_clean = "[Tt]est*"
Expand Down Expand Up @@ -166,85 +165,15 @@ def configure_rewrite_asserts(enable):
def configure_magics(enable):
from IPython import get_ipython

from ._impl import pytest_magic
from ._impl import ipytest_magic

if enable:
shell = get_ipython()
shell.register_magic_function(pytest_magic, "cell", "ipytest")
shell.register_magic_function(_deprecated_pytest_magic, "cell", "run_pytest")
shell.register_magic_function(
_deprecated_pytest_clean_magic,
"cell",
"run_pytest[clean]",
)
get_ipython().register_magic_function(ipytest_magic, "cell", "ipytest")

else:
warnings.warn("IPython does not support de-registering magics.")


def _deprecated_pytest_magic(line, cell):
print(
"%%run_pytest[clean] and %%run_pytest are deprecated in favor of "
"%%ipytest. %%ipytest will clean tests, evaluate the cell and then "
"run pytest. To disable cleaning, configure ipytest with "
"ipytest.config(clean=False).",
file=sys.stderr,
)
import shlex

from IPython import get_ipython

from ._impl import run

try:
get_ipython().run_cell(cell)

except TypeError as e:
if "raw_cell" in str(e):
raise RuntimeError(
"The ipytest magic cannot evaluate the cell. Most likely you "
"are running a modified ipython version. Consider using "
"`ipytest.run` and `ipytest.clean_tests` directly.",
) from e

raise e

run(*shlex.split(line))


def _deprecated_pytest_clean_magic(line, cell):
print(
"%%run_pytest[clean] and %%run_pytest are deprecated in favor of "
"%%ipytest. %%ipytest will clean tests, evaluate the cell and then "
"run pytest. To disable cleaning, configure ipytest with "
"ipytest.config(clean=False).",
file=sys.stderr,
)
import shlex

from IPython import get_ipython

from ._impl import clean_tests, run

if current_config["clean"] is not False:
clean_tests(current_config["clean"])

try:
get_ipython().run_cell(cell)

except TypeError as e:
if "raw_cell" in str(e):
raise RuntimeError(
"The ipytest magic cannot evaluate the cell. Most likely you "
"are running a modified ipython version. Consider using "
"`ipytest.run` and `ipytest.clean_tests` directly.",
) from e

raise e

run(*shlex.split(line))


def collect_args():
frame = inspect.currentframe()
frame = frame.f_back
Expand Down
12 changes: 2 additions & 10 deletions ipytest/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __str__(self):
return f"ipytest failed with exit_code {self.args[0]}"


def pytest_magic(line, cell, module=None):
def ipytest_magic(line, cell, module=None):
"""IPython magic to first execute the cell, then execute [`ipytest.run()`][ipytest.run].
**Note:** the magics are only available after running
Expand Down Expand Up @@ -164,7 +164,7 @@ def pytest_magic(line, cell, module=None):

# NOTE equivalent to @no_var_expand but does not require an IPython import
# See also: IPython.core.magic.no_var_expand
pytest_magic._ipython_magic_no_var_expand = True
ipytest_magic._ipython_magic_no_var_expand = True


def clean(pattern=default, *, module=None):
Expand Down Expand Up @@ -202,14 +202,6 @@ def clean(pattern=default, *, module=None):
del items[key]


def clean_tests(pattern=default, *, module=None):
print(
"ipytest.clean_tests is deprecated in favor of ipytest.clean",
file=sys.stderr,
)
clean(pattern, module=module)


def reload(*mods):
"""Reload all modules passed as strings.
Expand Down
4 changes: 1 addition & 3 deletions minidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,7 @@ def header_to_link(header: str) -> str:
header = header.replace(c, "")

header = header.replace(" ", "-")
header = header.lower()

return header
return header.lower()


def splice_docs(readme: List[str], docs: List[str]) -> Iterable[str]:
Expand Down
Loading

0 comments on commit 85682ed

Please sign in to comment.