Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 3cdbcb6

Browse files
authored
Merge pull request #1277 from bjones1/subchap-num-fix
Subchap num fix
2 parents e60c737 + d93ac1c commit 3cdbcb6

2 files changed

Lines changed: 25 additions & 14 deletions

File tree

runestone/chapterdb/dbchapterinfo.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
# You should have received a copy of the GNU General Public License
1414
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1515
#
16+
# **************************************************************
17+
# |docname| - Record chapter info in the database during a build
18+
# **************************************************************
1619

1720
__author__ = "bmiller"
1821

19-
import os.path
22+
from typing import Sequence
2023
from collections import OrderedDict
2124
import docutils
22-
import pdb
2325
from sphinx.util import logging
2426

2527
logger = logging.getLogger(__name__)
@@ -43,7 +45,6 @@ def env_updated(app, doctree, docname):
4345
"""
4446
This may be the best place to walk the completed document with TOC
4547
"""
46-
# pdb.set_trace()
4748
# ``docname`` is stored with Unix-style forward slashes, even on Windows. Therefore, we can't use ``os.path.basename`` or ``os.sep``.
4849
splits = docname.split("/")
4950
# If the docname is ``'index'``, then set ``chap_id`` to an empty string.
@@ -76,7 +77,6 @@ def env_updated(app, doctree, docname):
7677
secnum_str = ".".join(map(str, secnum_tuple)) + " " if secnum_tuple else ""
7778
# Prepend it to the title.
7879
title = secnum_str + section.next_node(docutils.nodes.Titular).astext()
79-
# pdb.set_trace()
8080

8181
if hasattr(app.env, "skipreading") and docname in app.env.skipreading:
8282
app.env.skips[(chap_id, subchap_id)] = True
@@ -106,11 +106,18 @@ def env_updated(app, doctree, docname):
106106
return []
107107

108108

109-
def make_subchap_num(sn_tuple):
110-
if not sn_tuple:
109+
# Given a sequence of section numbers, produce a single (orderable) int from the subchapter number and optionally the subsubchapter. Any finer divisions are ignored.
110+
def make_subchap_num(
111+
# A sequence of section numbers in the format ``(chapter, subchapter, optional_subsubchapter, ignored_stuff...)``.
112+
sn_seq: Sequence[int]
113+
# Returns subchapter*100 + optional_subsubchapter.
114+
) -> int:
115+
if not sn_seq or len(sn_seq) < 2:
111116
return 0
112117

113-
if len(sn_tuple) > 2:
114-
return sn_tuple[1] * 100 + sn_tuple[2]
115-
elif len(sn_tuple) == 2:
116-
return sn_tuple[1] * 100
118+
# Ignore the chapter number at ``sn_tuple[0]`` -- we're creating a subchapter number.
119+
ret = sn_seq[1] * 100
120+
# Include the subsubchapter number if it exists. Ignore everything else.
121+
if len(sn_seq) > 2:
122+
ret += sn_seq[2]
123+
return ret

runestone/server/componentdb.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def get_dburl(outer={}):
8484
# DAL uses "postgres:", while SQLAlchemy (and the PostgreSQL spec) uses "postgresql:". Fix.
8585
remove_prefix = "postgres://"
8686
if dburl.startswith(remove_prefix):
87-
dburl = "postgresql://" + dburl[len(remove_prefix):]
87+
dburl = "postgresql://" + dburl[len(remove_prefix) :]
8888
return dburl
8989

9090
raise RuntimeError("Cannot configure a Database URL!")
@@ -129,7 +129,9 @@ def setup(app):
129129
try:
130130
dburl = get_dburl()
131131
# SQLite doesn't support ``client_encoding``, while PostgreSQL does.
132-
encoding = dict(client_encoding="utf8") if dburl.startswith("postgresql") else {}
132+
encoding = (
133+
dict(client_encoding="utf8") if dburl.startswith("postgresql") else {}
134+
)
133135
engine = create_engine(dburl, convert_unicode=True, **encoding)
134136
Session = sessionmaker()
135137
engine.connect()
@@ -341,7 +343,7 @@ def addQuestionToDB(self):
341343
practice=practice,
342344
topic=topics,
343345
from_source=from_source,
344-
review_flag='F',
346+
review_flag="F",
345347
optional=optional,
346348
description=et,
347349
**meta_opts,
@@ -416,7 +418,9 @@ def addQNumberToDB(app, node, qnumber):
416418
questions.c.base_course == basecourse,
417419
)
418420
)
419-
.values(qnumber=qnumber,)
421+
.values(
422+
qnumber=qnumber,
423+
)
420424
)
421425
sess.execute(stmt)
422426

0 commit comments

Comments
 (0)