Skip to content

Commit

Permalink
Fix test requirements (#919)
Browse files Browse the repository at this point in the history
* Require pandoc==2.16.2 for testing
* Regenerate the pandoc versions of the sample notebooks
the representation for code cells has changed from ` ``` {.python}` to ` ``` python`
* Some tests require a python kernel
  • Loading branch information
mwouts authored Feb 9, 2022
1 parent 1d0e817 commit 923de7e
Show file tree
Hide file tree
Showing 25 changed files with 90 additions and 60 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Jupytext ChangeLog

**Changed**
- We have updated the pre-commit hooks and in particular we switched to the first stable version of `black==22.1.0`.
- We require `pandoc==2.16.2` for testing. The representation for code cells changed from ` ``` {.python}` to ` ``` python` in that version of Pandoc ([#906](https://github.com/mwouts/jupytext/issues/906)). We don't use `pandoc>=2.17` in tests at the moment because of the introduction of cell ids that cannot be filtered.


1.13.6 (2022-01-11)
Expand Down
2 changes: 1 addition & 1 deletion environment-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies:
- autopep8
- black
- isort>=5.3.0
- pandoc>=2.11.4
- pandoc==2.16.2
- sphinx-gallery<0.8
- pre-commit
- gitpython
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies:
- pip
- setuptools
- twine
- pandoc>=2.11.4
- pandoc==2.16.2
# make html in docs folder
- sphinx
- tox-conda
Expand Down
16 changes: 12 additions & 4 deletions jupytext/pandoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ def pandoc(args, filein=None, fileout=None):
return out.decode("utf-8")


def is_pandoc_available(min_version="2.7.2"):
def is_pandoc_available(min_version="2.7.2", max_version=None):
"""Is Pandoc>=2.7.2 available?"""
try:
raise_if_pandoc_is_not_available(min_version=min_version)
raise_if_pandoc_is_not_available(
min_version=min_version, max_version=max_version
)
return True
except PandocError:
return False


def raise_if_pandoc_is_not_available(min_version="2.7.2"):
def raise_if_pandoc_is_not_available(min_version="2.7.2", max_version=None):
"""Raise with an informative error message if pandoc is not available"""
try:
from pkg_resources import parse_version
Expand All @@ -61,7 +63,13 @@ def raise_if_pandoc_is_not_available(min_version="2.7.2"):
if parse_version(version) < parse_version(min_version):
raise PandocError(
f"The Pandoc Markdown format requires 'pandoc>={min_version}', "
f"but pandoc version {version} was not found"
f"but pandoc version {version} was found"
)

if max_version and parse_version(version) > parse_version(max_version):
raise PandocError(
f"The Pandoc Markdown format requires 'pandoc<={max_version}', "
f"but pandoc version {version} was found"
)

return version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ This notebook shows the use of R cells to generate plots
:::

::: {.cell .code}
``` {.python}
``` python
%load_ext rpy2.ipython
```
:::

::: {.cell .code}
``` {.python}
``` python
%%R
suppressMessages(require(tidyverse))
```
:::

::: {.cell .code}
``` {.python}
``` python
%%R
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color=Species)) + geom_point()
```
Expand All @@ -39,7 +39,7 @@ The default plot dimensions are not good for us, so we use the -w and -h paramet
:::

::: {.cell .code}
``` {.python}
``` python
%%R -w 400 -h 240
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color=Species)) + geom_point()
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jupyter:
---

::: {.cell .code}
``` {.python}
``` python
%load_ext rpy2.ipython
import pandas as pd

Expand All @@ -25,7 +25,7 @@ df = pd.DataFrame(
:::

::: {.cell .code}
``` {.python}
``` python
%%R -i df
library("ggplot2")
ggplot(data = df) + geom_point(aes(x = X, y = Y, color = Letter, size = Z))
Expand Down
22 changes: 11 additions & 11 deletions tests/notebooks/mirror/ipynb_to_pandoc/World population.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using the [wbdata](https://github.com/OliverSherouse/wbdata) python package
:::

::: {.cell .code}
``` {.python}
``` python
import pandas as pd
import wbdata as wb

Expand All @@ -34,7 +34,7 @@ the World Bank site.
:::

::: {.cell .code}
``` {.python}
``` python
wb.search_indicators('Population, total') # SP.POP.TOTL
# wb.search_indicators('area')
# => https://data.worldbank.org/indicator is easier to use
Expand All @@ -46,7 +46,7 @@ Now we download the population data
:::

::: {.cell .code}
``` {.python}
``` python
indicators = {'SP.POP.TOTL': 'Population, total',
'AG.SRF.TOTL.K2': 'Surface area (sq. km)',
'AG.LND.TOTL.K2': 'Land area (sq. km)',
Expand All @@ -61,7 +61,7 @@ World is one of the countries
:::

::: {.cell .code}
``` {.python}
``` python
data.loc['World']
```
:::
Expand All @@ -71,7 +71,7 @@ Can we classify over continents?
:::

::: {.cell .code}
``` {.python}
``` python
data.loc[(slice(None), '2017-01-01'), :]['Population, total'].dropna(
).sort_values().tail(60).index.get_level_values('country')
```
Expand All @@ -82,7 +82,7 @@ Extract zones manually (in order of increasing population)
:::

::: {.cell .code}
``` {.python}
``` python
zones = ['North America', 'Middle East & North Africa',
'Latin America & Caribbean', 'Europe & Central Asia',
'Sub-Saharan Africa', 'South Asia',
Expand All @@ -95,7 +95,7 @@ And extract population information (and check total is right)
:::

::: {.cell .code}
``` {.python}
``` python
population = data.loc[zones]['Population, total'].swaplevel().unstack()
population = population[zones]
assert all(data.loc['World']['Population, total'] == population.sum(axis=1))
Expand All @@ -107,13 +107,13 @@ assert all(data.loc['World']['Population, total'] == population.sum(axis=1))
:::

::: {.cell .code}
``` {.python}
``` python
import matplotlib.pyplot as plt
```
:::

::: {.cell .code}
``` {.python}
``` python
plt.clf()
plt.figure(figsize=(10, 5), dpi=100)
plt.stackplot(population.index, population.values.T / 1e9)
Expand All @@ -135,7 +135,7 @@ now we just do a stacked bar plot.
:::

::: {.cell .code}
``` {.python}
``` python
import plotly.offline as offline
import plotly.graph_objs as go

Expand All @@ -144,7 +144,7 @@ offline.init_notebook_mode()
:::

::: {.cell .code}
``` {.python}
``` python
bars = [go.Bar(x=population.index, y=population[zone], name=zone)
for zone in zones]
fig = go.Figure(data=bars,
Expand Down
2 changes: 1 addition & 1 deletion tests/notebooks/mirror/ipynb_to_pandoc/cat_variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jupyter:
---

::: {.cell .code}
``` {.python}
``` python
cat = 42
```
:::
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jupyter:
---

::: {.cell .code}
``` {.python}
``` python
%%time

print('asdf')
Expand All @@ -21,6 +21,6 @@ Thanks for jupytext!
:::

::: {.cell .code}
``` {.python}
``` python
```
:::
4 changes: 2 additions & 2 deletions tests/notebooks/mirror/ipynb_to_pandoc/frozen_cell.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jupyter:
---

::: {.cell .code}
``` {.python}
``` python
# This is an unfrozen cell. Works as usual.
print("I'm a regular cell so I run and print!")
```
:::

::: {.cell .code deletable="false" editable="false" run_control="{\"frozen\":true}"}
``` {.python}
``` python
# This is an frozen cell
print("I'm frozen so Im not executed :(")
```
Expand Down
6 changes: 3 additions & 3 deletions tests/notebooks/mirror/ipynb_to_pandoc/ir_notebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ This is a jupyter notebook that uses the IR kernel.
:::

::: {.cell .code}
``` {.R}
``` R
sum(1:10)
```
:::

::: {.cell .code}
``` {.R}
``` R
plot(cars)
```
:::

::: {.cell .code}
``` {.R}
``` R
```
:::
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jupyter:
---

::: {.cell .code}
``` {.julia}
``` julia
# IJulia rocks! So does Plotly. Check it out

using Plotly
Expand All @@ -21,7 +21,7 @@ Plotly.signin(username, api_key)
:::

::: {.cell .code}
``` {.julia}
``` julia
# Following data taken from http://julialang.org/ frontpage
benchmarks = ["fib", "parse_int", "quicksort3", "mandel", "pi_sum", "rand_mat_stat", "rand_mat_mul"]
platforms = ["Fortran", "Julia", "Python", "R", "Matlab", "Mathematica", "Javascript", "Go"]
Expand Down Expand Up @@ -70,7 +70,7 @@ display("text/html", s)
:::

::: {.cell .code}
``` {.julia}
``` julia
# checkout https://plot.ly/api/ for more Julia examples!
# But to show off some other Plotly features:
x = 1:1500
Expand Down
6 changes: 3 additions & 3 deletions tests/notebooks/mirror/ipynb_to_pandoc/jupyter.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This notebook is a simple jupyter notebook. It only has markdown and code cells.
:::

::: {.cell .code}
``` {.python}
``` python
a = 1
b = 2
a + b
Expand All @@ -27,13 +27,13 @@ Now we return a few tuples
:::

::: {.cell .code}
``` {.python}
``` python
a, b
```
:::

::: {.cell .code}
``` {.python}
``` python
a, b, a+b
```
:::
Expand Down
6 changes: 3 additions & 3 deletions tests/notebooks/mirror/ipynb_to_pandoc/jupyter_again.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jupyter:
---

::: {.cell .code}
``` {.python}
``` python
c = '''
title: "Quick test"
output:
Expand All @@ -23,14 +23,14 @@ editor_options:
:::

::: {.cell .code}
``` {.python}
``` python
import yaml
print(yaml.dump(yaml.load(c)))
```
:::

::: {.cell .code}
``` {.python}
``` python
?next
```
:::
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jupyter:
---

::: {.cell .code}
``` {.python}
``` python
1+2+3
```
:::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ editor_options:
:::

::: {.cell .code}
``` {.python}
``` python
1+2+3
```
:::

::: {.cell .code}
``` {.python}
``` python
```
:::
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jupyter:
---

::: {.cell .code}
``` {.python}
``` python
```
:::
Loading

0 comments on commit 923de7e

Please sign in to comment.