Skip to content
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

Add recipe for xrst (extract rst files and run sphinx) #25198

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
87 changes: 87 additions & 0 deletions recipes/xrst/2024.0.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
diff --git a/pyproject.toml b/pyproject.toml
index a5d37a9..81c5145 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -30,7 +30,7 @@ classifiers = [
dependencies = [
'sphinx', 'toml', 'sphinx-copybutton', # required
'pytest', # need for testing xrst
- 'pyenchant', 'pyspellchecker', # need the one you use
+ 'pyspellchecker', # need the one you use
'furo', 'sphinx-rtd-theme', 'sphinx-book-theme', # need the ones you use
]
# END_DEPENDENCIES
diff --git a/pytest/test_rst.py b/pytest/test_rst.py
index b159f9e..39b0647 100644
--- a/pytest/test_rst.py
+++ b/pytest/test_rst.py
@@ -6,6 +6,9 @@ import os
import re
import subprocess
# ----------------------------------------------------------------------------
+pattern_return_newline = re.compile( r'\r\n' )
+pattern_include_backslash = re.compile( r'\.\. literalinclude:: .*\\' )
+# ----------------------------------------------------------------------------
def get_index_page_name() :
file_obj = open('.readthedocs.yaml', 'r')
file_data = file_obj.read()
@@ -86,6 +89,22 @@ def run_test() :
rst_file_obj.close()
check_file_obj.close()
#
+ # rst_data
+ # dos2unix: relpace \r\n by \n
+ replace = r'\n'
+ rst_data = pattern_return_newline.sub(replace, rst_data)
+ #
+ # rst_data
+ # relpace \ in file names by /
+ m_obj = pattern_include_backslash.search(rst_data)
+ while m_obj != None :
+ start = m_obj.start()
+ end = m_obj.end()
+ text = m_obj.group(0)
+ replace = text.replace( '\\' , '/' )
+ rst_data = check_data[:start] + replace + rst_data[end:]
+ m_obj = pattern_include_backslash.search(rst_data)
+ #
if rst_data == check_data :
print( f'{rst_name}: OK' )
else :
diff --git a/setup.py b/setup.py
index 446c6b0..2a56f82 100644
--- a/setup.py
+++ b/setup.py
@@ -27,7 +27,7 @@ setup(
install_requires = [
'sphinx', 'toml', 'sphinx-copybutton', # required
'pytest', # need for testing xrst
- 'pyenchant', 'pyspellchecker', # need the one you use
+ 'pyspellchecker', # need the one you use
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since deps are specified in the meta.yaml it's not necessary to patch them in the setup.py... unless it's to enable pip check to work.

'furo', 'sphinx-rtd-theme', 'sphinx-book-theme', # need the ones you use
],
entry_points = {
diff --git a/tox.ini b/tox.ini
index 8a2e158..4b5ffc8 100644
--- a/tox.ini
+++ b/tox.ini
@@ -12,6 +12,5 @@ deps =
pytest
toml
pyspellchecker
- pyenchant
#
commands = pytest -s pytest
diff --git a/xrst.toml b/xrst.toml
index 0e52cbf..c26094d 100644
--- a/xrst.toml
+++ b/xrst.toml
@@ -34,7 +34,7 @@ overline = [ false, false, false, false, false, ]
# -----------------------------------------------------------------------------
# BEGIN_SPELL_PACKAGE
[spell_package]
-data = 'pyenchant'
+data = 'pyspellchecker'
# END_SPELL_PACKAGE
# -----------------------------------------------------------------------------
# BEGIN_INPUT_FILES
95 changes: 95 additions & 0 deletions recipes/xrst/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# See meta.yaml in
# https://github.com/conda-forge/staged-recipes/blob/main/recipes/example
#
# Note that the example above suggests that one use SPDX identifies for the
# license field but this is not yet supported by conda build or conda-verfity;
# see https://github.com/conda/conda/issues/5280
# This project uses the SPDX identifier GPL-3.0-or-later; see
# https://spdx.org/licenses/GPL-3.0-or-later.html
#
# Remove pyenchant from requirements because the conda version does not work:
# https://github.com/conda-forge/pyenchant-feedstock/issues/1
#
# Warnings when in recipes we execute: conda build xrst
# 1. DeprecationWarning: conda_build.cli.main_build.main is deprecated
# and will be removed in 24.1.0. Use `conda build` instead.
# (We get this warning even though we am using `conda build`.)
# 2. No numpy version specified in conda_build_config.yaml.
# Falling back to default numpy value of 1.22.
# (We have not specified a conda_build_config.yaml file for this project.)
# 3. C1115 Found invalid license "GPL-3.0-or-later" in info/index.json
# (See the comments above about SPDX identifiers.)
#
# Warnings when in recipes we execute: conda-verify xrst
# 1. WARNING: Setting build platform. ...
# (We are not setting a specific build platform.)
# 2. WARNING: Setting build arch. ...
# (We are not setting noarch and not a specific build arch.)
# 3. C2122 Found invalid license family "GPL-3.0-or-later"
# (See the comments above about SPDX identifiers.)
#
#
{% set name = "xrst" %}
{% set version = "2024.0.0" %}
{% set home = "https://github.com/bradbell/xrst" %}

package:
name: {{ name }}
version: {{ version }}

source:
url: {{ home }}/archive/{{ version }}.tar.gz
sha256: 60020376af6bf100194ced85ea19534084e858a80a03162e533ad84506900073
#
# This patch should not be necessary once version advances to 2024.0.1
patches:
- {{ version }}.patch

build:
entry_points:
- xrst = xrst:run_xrst
noarch: python
script: {{ PYTHON }} -m pip install . -vv --no-deps --no-build-isolation
number: 0

requirements:
host:
- python
- setuptools
- setuptools-scm
- pip
run:
- python >=3.8
- sphinx
- toml
- sphinx-copybutton
- pytest
- pyspellchecker
- furo
- sphinx_rtd_theme
- sphinx-book-theme

test:
source_files:
- pytest/test_rst.py
imports:
- xrst
commands:
# pip check
# Cannot use pip to check install becasue it has a pyenchant requirement.
# This should be fixed once version advances to 2024.0.1.
#
- xrst --version
requires:
- pip

about:
home: {{ home }}
summary: Extract RST files from source code and run Sphinx
license: GPL-3.0-or-later
license_file: gpl-3.0.txt
doc_url: https://xrst.readthedocs.io

extra:
recipe-maintainers:
- bradbell
37 changes: 37 additions & 0 deletions recipes/xrst/run_test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
rem
rem name, version
set name=%PKG_NAME%
set version=%PKG_VERSION%
rem
rem url
set home="https://github.com/bradbell/%name%"
set url="%home%/archive/%version%.tar.gz"
rem
rem xrst-%version%.tar.gz
curl -LJO %url%
rem
rem xrst-%version%
rem we get a copy of the original source because it has an automated test.
tar -xzf xrst-%version%.tar.gz
cd xrst-%version%
rem
rem xrst-%version%\pytest\test_rst.py
rem It is hard to use PREFIX here becasue dos uses \ for directory separator.
rem Using xrst.exe (instead of xrst) ensures we are running installed version
rem and not the version in this source.
sed -e "s|'python3' *,.*|'xrst.exe', '--suppress_spell_warnings', |" ^
..\pytest\test_rst.py > pytest\test_rst.py
rem
rem xrst-%version%\xrst.toml
sed -i -e "s|pyenchant|pyspellchecker|" xrst.toml
rem
rem pytest
pytest -s pytest
IF %ERRORLEVEL% NEQ 0 (
CD ..
ECHO run_test.bat Error
exit /B 1
)
CD ..
ECHO run_test.bat: OK

36 changes: 36 additions & 0 deletions recipes/xrst/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#! /usr/bin/env bash
set -e -u
#
# prefix, name, version
prefix=$PREFIX
name=$PKG_NAME
version=$PKG_VERSION
#
# url
home="https://github.com/bradbell/$name"
url="$home/archive/$version.tar.gz"
#
# xrst-$version.tar.gz
curl -LJO $url
#
# xrst-$version
# We get a copy of the original source becasue it has an automated test.
tar -xzf xrst-$version.tar.gz
cd xrst-$version
#
# xrst-$version/pytest/test_rst.py
# Use prefix here ensures we are running the installed version and not
# the version in this source.
sed -i \
-e "s|'python3' *,.*|'$prefix/bin/xrst', '--suppress_spell_warnings', |" \
pytest/test_rst.py
#
# xrst-$version/xrst.toml
sed -i -e 's|pyenchant|pyspellchecker|' xrst.toml
#
# pytest
pytest -s pytest
#
echo 'run_test.sh: OK'
exit 0