Skip to content

Commit b99bf50

Browse files
committed
xrefs refactor
1 parent 5acf0bd commit b99bf50

File tree

9 files changed

+214
-181
lines changed

9 files changed

+214
-181
lines changed
File renamed without changes.
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "9e0ff8c8-2e08-4144-bb1c-31ae032ad693",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"from pathlib import Path\n",
11+
"\n",
12+
"base_online = Path('../../online/')\n",
13+
"base_vol = Path('../../vol2/')\n",
14+
"cap_n = 9\n",
15+
"cap = f'cap{cap_n:02d}.adoc'\n",
16+
"\n",
17+
"def cap_vol(cap: int) -> int:\n",
18+
" return ((cap - 1) // 8) + 1\n",
19+
"\n",
20+
"def cap_adoc(cap: int) -> str:\n",
21+
" return f'cap{cap:02d}.adoc'\n",
22+
"\n",
23+
"def path_adoc(cap: int) -> Path:\n",
24+
" vol = cap_vol(cap)\n",
25+
" return Path(f'../../vol{vol}/') / cap_adoc(cap)\n",
26+
"\n",
27+
"print(path_adoc(9))"
28+
]
29+
},
30+
{
31+
"cell_type": "code",
32+
"execution_count": null,
33+
"id": "7c21a3dd-ed66-4587-aa51-a443365d346d",
34+
"metadata": {},
35+
"outputs": [],
36+
"source": [
37+
"other_vols = {}\n",
38+
"\n",
39+
"for cap_n in list(range(1, 9)) + list(range(17, 25)):\n",
40+
" with open(base_online / cap_adoc(cap_n)) as fp:\n",
41+
" lines = fp.readlines()\n",
42+
" for line in lines:\n",
43+
" if line.startswith('[[ch_'):\n",
44+
" ident = line.split(']]')[0][2:]\n",
45+
" other_vols[ident] = (cap_vol(cap_n), cap_n)\n",
46+
"\n",
47+
"other_vols"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": null,
53+
"id": "546fd140-6977-469a-8e32-c7497f09dc27",
54+
"metadata": {},
55+
"outputs": [],
56+
"source": [
57+
"# duas xrefs:\n",
58+
"# A maior parte do <<ch_type_hints_def>> e do <<ch_more_types>>\n",
59+
"\n",
60+
"for cap_n in range(9, 17):\n",
61+
" with open(path_adoc(cap_n)) as fp:\n",
62+
" adoc = fp.read()\n",
63+
" for ident, (vol, cap) in other_vols.items():\n",
64+
" xref = f'<<{ident}>>'\n",
65+
" adoc = adoc.replace(xref, f'https://fpy.li/{cap}[«Capítulo {cap}»] (vol.{vol})')\n",
66+
"\n",
67+
" with open(path_adoc(cap_n), 'wt', encoding='utf8') as fp:\n",
68+
" fp.write(adoc)"
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": 1,
74+
"id": "87de0cb0-4e90-43af-9eb0-f72874f2cc2a",
75+
"metadata": {},
76+
"outputs": [],
77+
"source": [
78+
"from xvol_xrefs import replace_xrefs_to_vols"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": 2,
84+
"id": "552c2fa0-ff72-404b-a7b1-868273c38cb9",
85+
"metadata": {},
86+
"outputs": [
87+
{
88+
"name": "stdout",
89+
"output_type": "stream",
90+
"text": [
91+
"<<prop_validation_sec>>\t https://pythonfluente.com/2/#prop_validation_sec[«Seção 22.4»] (vol.3)\n",
92+
"<<numeric_tower_warning_sec>>\t https://pythonfluente.com/2/#numeric_tower_warning_sec[«Seção 8.5.7.1»] (vol.1)\n",
93+
"<<methods_are_descriptors_sec>>\t https://pythonfluente.com/2/#methods_are_descriptors_sec[«Seção 23.4»] (vol.3)\n",
94+
"<<ex_vector2d>>\t https://pythonfluente.com/2/#ex_vector2d[«Seção 23.4»] (vol.3)\n",
95+
"<<arrays_sec>>\t https://pythonfluente.com/2/#arrays_sec[«Seção 2.10.1»] (vol.1)\n",
96+
"<<memoryview_sec>>\t https://pythonfluente.com/2/#memoryview_sec[«Seção 2.10.2»] (vol.1)\n",
97+
"<<what_is_hashable_sec>>\t https://pythonfluente.com/2/#what_is_hashable_sec[«Seção 3.4.1»] (vol.1)\n",
98+
"<<keyword_class_patterns_sec>>\t https://pythonfluente.com/2/#keyword_class_patterns_sec[«Seção 5.8.2»] (vol.1)\n",
99+
"<<conseq_dict_internal_sec>>\t https://pythonfluente.com/2/#conseq_dict_internal_sec[«Seção 3.9»] (vol.1)\n",
100+
"<<caching_properties_sec>>\t https://pythonfluente.com/2/#caching_properties_sec[«Seção 22.3.5»] (vol.3)\n",
101+
"<<del_sec>>\t https://pythonfluente.com/2/#del_sec[«Seção 6.6»] (vol.1)\n",
102+
"<<numpy_sec>>\t https://pythonfluente.com/2/#numpy_sec[«Seção 2.10.3»] (vol.1)\n",
103+
"<<dataclass_further_sec>>\t https://pythonfluente.com/2/#dataclass_further_sec[«Seção 5.10»] (vol.1)\n",
104+
"<<ex_pythonic_deck>>\t https://pythonfluente.com/2/#ex_pythonic_deck[«Seção 5.10»] (vol.1)\n",
105+
"<<protocols_in_fn_sec>>\t https://pythonfluente.com/2/#protocols_in_fn_sec[«Seção 8.5.10»] (vol.1)\n",
106+
"<<slice_objects_sec>>\t https://pythonfluente.com/2/#slice_objects_sec[«Seção 2.7.2»] (vol.1)\n",
107+
"<<metaprog_part>>\t https://pythonfluente.com/2/#metaprog_part[«V—Metaprogramação»] (vol.3)\n",
108+
"<<map_filter_reduce_sec>>\t https://pythonfluente.com/2/#map_filter_reduce_sec[«Seção 7.3.1»] (vol.1)\n",
109+
"<<operator_module_sec>>\t https://pythonfluente.com/2/#operator_module_sec[«Seção 7.8.1»] (vol.1)\n",
110+
"<<stdlib_generators_sec>>\t https://pythonfluente.com/2/#stdlib_generators_sec[«Seção 17.9»] (vol.3)\n",
111+
"<<types_defined_by_ops_sec>>\t https://pythonfluente.com/2/#types_defined_by_ops_sec[«Seção 8.4»] (vol.1)\n",
112+
"<<iter_func_sec>>\t https://pythonfluente.com/2/#iter_func_sec[«Seção 17.3»] (vol.3)\n",
113+
"<<mapping_uml>>\t https://pythonfluente.com/2/#mapping_uml[«Seção 17.3»] (vol.3)\n",
114+
"<<set_uml>>\t https://pythonfluente.com/2/#set_uml[«Seção 17.3»] (vol.3)\n",
115+
"<<set_ops_sec>>\t https://pythonfluente.com/2/#set_ops_sec[«Seção 3.11.1»] (vol.1)\n",
116+
"<<type_hint_abc_sec>>\t https://pythonfluente.com/2/#type_hint_abc_sec[«Seção 8.5.7»] (vol.1)\n",
117+
"<<ex_bingo_callable>>\t https://pythonfluente.com/2/#ex_bingo_callable[«Seção 8.5.7»] (vol.1)\n",
118+
"<<defensive_argument>>\t https://pythonfluente.com/2/#defensive_argument[«Seção 8.5.7»] (vol.1)\n",
119+
"<<consistent_with_sec>>\t https://pythonfluente.com/2/#consistent_with_sec[«Seção 8.5.1.1»] (vol.1)\n",
120+
"<<noreturn_sec>>\t https://pythonfluente.com/2/#noreturn_sec[«Seção 8.5.12»] (vol.1)\n",
121+
"<<ex_top_protocol_test>>\t https://pythonfluente.com/2/#ex_top_protocol_test[«Seção 8.5.12»] (vol.1)\n",
122+
"<<inconsistent_missing_sec>>\t https://pythonfluente.com/2/#inconsistent_missing_sec[«Seção 3.5.3»] (vol.1)\n",
123+
"<<ex_strkeydict>>\t https://pythonfluente.com/2/#ex_strkeydict[«Seção 3.5.3»] (vol.1)\n",
124+
"<<anatomy_of_classes_sec>>\t https://pythonfluente.com/2/#anatomy_of_classes_sec[«Seção 24.2»] (vol.3)\n",
125+
"<<arbitrary_arguments_sec>>\t https://pythonfluente.com/2/#arbitrary_arguments_sec[«Seção 8.6»] (vol.1)\n",
126+
"<<bounded_typevar_sec>>\t https://pythonfluente.com/2/#bounded_typevar_sec[«Seção 8.5.9.2»] (vol.1)\n",
127+
"<<mapping_type_sec>>\t https://pythonfluente.com/2/#mapping_type_sec[«Seção 8.5.6»] (vol.1)\n",
128+
"<<builders_compared_tbl>>\t https://pythonfluente.com/2/#builders_compared_tbl[«Seção 8.5.6»] (vol.1)\n",
129+
"<<ex_tcp_mojifinder_main>>\t https://pythonfluente.com/2/#ex_tcp_mojifinder_main[«Seção 8.5.6»] (vol.1)\n",
130+
"<<ex_checked_class_top>>\t https://pythonfluente.com/2/#ex_checked_class_top[«Seção 8.5.6»] (vol.1)\n",
131+
"<<callable_variance_sec>>\t https://pythonfluente.com/2/#callable_variance_sec[«Seção 8.5.11.1»] (vol.1)\n",
132+
"<<generic_classic_coroutine_types_sec>>\t https://pythonfluente.com/2/#generic_classic_coroutine_types_sec[«Seção 17.13.3»] (vol.3)\n",
133+
"<<classic_coroutines_sec>>\t https://pythonfluente.com/2/#classic_coroutines_sec[«Seção 17.13»] (vol.3)\n",
134+
"<<ex_primes_procs_top>>\t https://pythonfluente.com/2/#ex_primes_procs_top[«Seção 17.13»] (vol.3)\n",
135+
"<<data_model_emulating_sec>>\t https://pythonfluente.com/2/#data_model_emulating_sec[«Seção 1.3.1»] (vol.1)\n"
136+
]
137+
}
138+
],
139+
"source": [
140+
"repls = replace_xrefs_to_vols()"
141+
]
142+
},
143+
{
144+
"cell_type": "code",
145+
"execution_count": 4,
146+
"id": "bd8f090f-e95d-4005-96ce-160387d3db63",
147+
"metadata": {},
148+
"outputs": [
149+
{
150+
"name": "stdout",
151+
"output_type": "stream",
152+
"text": [
153+
"<<ex_vector2d>> https://pythonfluente.com/2/#ex_vector2d\n",
154+
"<<ex_pythonic_deck>> https://pythonfluente.com/2/#ex_pythonic_deck\n",
155+
"<<metaprog_part>> https://pythonfluente.com/2/#metaprog_part\n",
156+
"<<mapping_uml>> https://pythonfluente.com/2/#mapping_uml\n",
157+
"<<set_uml>> https://pythonfluente.com/2/#set_uml\n",
158+
"<<ex_bingo_callable>> https://pythonfluente.com/2/#ex_bingo_callable\n",
159+
"<<defensive_argument>> https://pythonfluente.com/2/#defensive_argument\n",
160+
"<<ex_top_protocol_test>> https://pythonfluente.com/2/#ex_top_protocol_test\n",
161+
"<<ex_strkeydict>> https://pythonfluente.com/2/#ex_strkeydict\n",
162+
"<<builders_compared_tbl>> https://pythonfluente.com/2/#builders_compared_tbl\n",
163+
"<<ex_tcp_mojifinder_main>> https://pythonfluente.com/2/#ex_tcp_mojifinder_main\n",
164+
"<<ex_checked_class_top>> https://pythonfluente.com/2/#ex_checked_class_top\n",
165+
"<<ex_primes_procs_top>> https://pythonfluente.com/2/#ex_primes_procs_top\n"
166+
]
167+
}
168+
],
169+
"source": [
170+
"for repl in repls:\n",
171+
" xref, rest = repl.split('\\t')\n",
172+
" url = rest.split('[')[0]\n",
173+
" if not xref.endswith('_sec>>'):\n",
174+
" print(xref, url)"
175+
]
176+
},
177+
{
178+
"cell_type": "code",
179+
"execution_count": null,
180+
"id": "fd9a3167-fa6c-4f18-99ac-1fcf3bf19a3a",
181+
"metadata": {},
182+
"outputs": [],
183+
"source": []
184+
}
185+
],
186+
"metadata": {
187+
"kernelspec": {
188+
"display_name": "Python 3 (ipykernel)",
189+
"language": "python",
190+
"name": "python3"
191+
},
192+
"language_info": {
193+
"codemirror_mode": {
194+
"name": "ipython",
195+
"version": 3
196+
},
197+
"file_extension": ".py",
198+
"mimetype": "text/x-python",
199+
"name": "python",
200+
"nbconvert_exporter": "python",
201+
"pygments_lexer": "ipython3",
202+
"version": "3.14.0"
203+
}
204+
},
205+
"nbformat": 4,
206+
"nbformat_minor": 5
207+
}
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def replace_xrefs_to_vols():
146146
with open(html_path) as fp:
147147
html = fp.read()
148148
root = BeautifulSoup(html, 'html.parser')
149+
replacements = []
149150
for xref in list_invalid_xrefs():
150151
if xref.startswith('ch_'):
151152
chapter = CHAPTER_NUMBER[xref]
@@ -161,14 +162,16 @@ def replace_xrefs_to_vols():
161162
chapter = numbers[0]
162163
volume = (chapter - 1) // 8 + 1
163164
text = f'Seção {number_str}'
164-
elif xref.startswith('ex_'):
165165

166-
else:
167-
raise ValueError(f'unexpected xref: {xref!r}')
166+
#else:
167+
# raise ValueError(f'unexpected xref: {xref!r}')
168168
link = BASE_URL + '#' + xref
169169
#print(f'<<{xref}>>', f'{text} &#91;vol.{volume}, fpy.li{SHORT_URLS[link]}&#93;')
170170
# https://fpy.li/24[«Capítulo 24»] (vol.3)
171-
print(f'<<{xref}>>', f'{link}{text}»] (vol.{volume})')
171+
repl = f'<<{xref}>>\t {link}{text}»] (vol.{volume})'
172+
print(repl)
173+
replacements.append(repl)
174+
return replacements
172175

173176

174177
if __name__ == '__main__':

0 commit comments

Comments
 (0)