Skip to content

Commit

Permalink
Merge pull request #1450 from emollier/python3.11
Browse files Browse the repository at this point in the history
Fix use of codecs.open with U flag in generate_examples
  • Loading branch information
mstimberg committed Jan 5, 2023
2 parents 638e3f9 + c442df5 commit 9e2906a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/testsuite.yml
Expand Up @@ -110,3 +110,40 @@ jobs:
coveralls --finish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

test_doc_build:
needs: get_python_versions
name: Test building the documentation
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: true

- name: Setup Conda and Python
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
auto-activate-base: false
channels: conda-forge,defaults
channel-priority: true
activate-environment: 'test_env'
python-version: "${{ needs.get_python_versions.outputs.max-python }}"

- name: Install dependencies
run: pip install -r rtd-requirements.txt

- name: Install brian2
run: pip install .

- name: Build HTML documentation
run: |
cd docs_sphinx
sphinx-build -b html . ../docs
env:
READTHEDOCS: True
9 changes: 4 additions & 5 deletions brian2/sphinxext/generate_examples.py
@@ -1,4 +1,3 @@
import codecs
import fnmatch
import glob
import os
Expand Down Expand Up @@ -71,7 +70,7 @@ def main(rootpath, destdir):
# We assume all files are encoded as UTF-8
examplescode = []
for fname in examplesfnames:
with codecs.open(fname, "rU", encoding="utf-8") as f:
with open(fname, encoding="utf-8") as f:
examplescode.append(f.read())
examplesdocs = []
examplesafterdoccode = []
Expand Down Expand Up @@ -157,7 +156,7 @@ def main(rootpath, destdir):
print("Found example image file", image)
output += f".. image:: ../resources/examples_images/{image}\n\n"

with codecs.open(os.path.join(destdir, exname + ".rst"), "w", "utf-8") as f:
with open(os.path.join(destdir, exname + ".rst"), "w", encoding="utf-8") as f:
f.write(output)

category_additional_files = defaultdict(list)
Expand All @@ -168,15 +167,15 @@ def main(rootpath, destdir):
relpath = ""
full_name = relpath.replace("/", ".").replace("\\", ".") + "." + file + ".rst"
category_additional_files[relpath].append((file, full_name))
with codecs.open(fname, "rU", encoding="utf-8") as f:
with open(fname, encoding="utf-8") as f:
print(fname)
content = f.read()
output = file + "\n" + "=" * len(file) + "\n\n"
output += ".. code:: none\n\n"
content_lines = ["\t" + l for l in content.split("\n")]
output += "\n".join(content_lines)
output += "\n\n"
with codecs.open(os.path.join(destdir, full_name), "w", "utf-8") as f:
with open(os.path.join(destdir, full_name), "w", encoding="utf-8") as f:
f.write(output)

mainpage_text = "Examples\n"
Expand Down

0 comments on commit 9e2906a

Please sign in to comment.