diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 812f24b..abbf001 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,25 +1,25 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v6.0.0 hooks: - id: check-yaml exclude: "mkdocs.yml" - id: end-of-file-fixer exclude: "(.*tests/data/.*/.*.md)" - id: trailing-whitespace - exclude: "(.*tests/data/.*/.*.md)" + exclude: "(.*tests/data/.*/.*.md)|(tests/__snapshots__/.*.ambr)" - id: debug-statements - repo: https://github.com/PyCQA/autoflake rev: v2.3.1 hooks: - id: autoflake - repo: https://github.com/psf/black - rev: 24.8.0 + rev: 25.11.0 hooks: - id: black language_version: python3.11 - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.6.3 + rev: v0.14.4 hooks: - id: ruff - repo: local diff --git a/docs/examples/example.md b/docs/examples/example.md index 966b7db..f12b683 100644 --- a/docs/examples/example.md +++ b/docs/examples/example.md @@ -253,12 +253,12 @@ raise NotImplementedError ``` ::: {.cell-output .cell-output-error} - NotImplementedError: + NotImplementedError: [0;31m---------------------------------------------------------------------------[0m [0;31mNotImplementedError[0m Traceback (most recent call last) Cell [0;32mIn[24], line 1[0m [0;32m----> 1[0m [38;5;28;01mraise[39;00m [38;5;167;01mNotImplementedError[39;00m - [0;31mNotImplementedError[0m: + [0;31mNotImplementedError[0m: ::: :::: diff --git a/docs/examples/matplotlib_example.qmd b/docs/examples/matplotlib_example.qmd index 8b5122c..183cef1 100644 --- a/docs/examples/matplotlib_example.qmd +++ b/docs/examples/matplotlib_example.qmd @@ -34,4 +34,4 @@ ax.set(xticklabels=[], zticklabels=[]) plt.show() -``` \ No newline at end of file +``` diff --git a/docs/examples/mermaid_example.qmd b/docs/examples/mermaid_example.qmd index d067810..70326c2 100644 --- a/docs/examples/mermaid_example.qmd +++ b/docs/examples/mermaid_example.qmd @@ -7,4 +7,4 @@ graph TD; A-->C; B-->D; C-->D; -``` \ No newline at end of file +``` diff --git a/docs/examples/mkdocstrings_example.qmd b/docs/examples/mkdocstrings_example.qmd new file mode 100644 index 0000000..dfa4d27 --- /dev/null +++ b/docs/examples/mkdocstrings_example.qmd @@ -0,0 +1,18 @@ + +# This is a simple example that uses mkdocstrings + +You can take a look at the .qmd that generated this docs +from: + +[https://github.com/jspaezp/mkquartodocs/tree/main/docs](https://github.com/jspaezp/mkquartodocs/tree/main/docs) + +## Docs for math.sqrt + +::: math.sqrt + +```{python} +import math + +print(f"The quare root of 16 is {math.sqrt(16)}") + +``` diff --git a/docs/javascripts/tablesort.js b/docs/javascripts/tablesort.js index c916015..2e9fd4e 100644 --- a/docs/javascripts/tablesort.js +++ b/docs/javascripts/tablesort.js @@ -3,4 +3,4 @@ document$.subscribe(function() { tables.forEach(function(table) { new Tablesort(table) }) - }) \ No newline at end of file + }) diff --git a/mkdocs.yml b/mkdocs.yml index 015a3a0..e2f83fc 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -13,21 +13,24 @@ nav: - 'Simple dataframe execution': 'examples/dataframe_example.qmd' - 'Simple mermaid execution': 'examples/mermaid_example.qmd' - 'Simple matplotlib execution': 'examples/matplotlib_example.qmd' + - 'Mkdocstrings Integration': 'examples/mkdocstrings_example.qmd' theme: name: material plugins: - - search - - mkquartodocs: - # keep_output: true - force_rebuild: true +- mkdocstrings: + default_handler: python +- search +- mkquartodocs: + # keep_output: true + force_rebuild: true markdown_extensions: - - pymdownx.highlight: - anchor_linenums: true - - pymdownx.superfences +- pymdownx.highlight: + anchor_linenums: true +- pymdownx.superfences extra_javascript: - - https://unpkg.com/tablesort@5.3.0/dist/tablesort.min.js - - javascripts/tablesort.js +- https://unpkg.com/tablesort@5.3.0/dist/tablesort.min.js +- javascripts/tablesort.js diff --git a/mkquartodocs/extension.py b/mkquartodocs/extension.py index 0ef8352..ccaa519 100644 --- a/mkquartodocs/extension.py +++ b/mkquartodocs/extension.py @@ -39,6 +39,18 @@ # ``` {.python .cell-code} CODEBLOCK_REGEX: Final = re.compile(r"^(`{3,})\s?{\.(\w+) .*}") +# mkdocstrings syntax normalization: +# Quarto wraps markdown divs (including mkdocstrings `::: module.path` syntax) +# in extra colons when rendering nested structures. For example: +# Source .qmd: `::: pathlib.Path` +# Quarto output: `::::: pathlib.Path` (5 colons instead of 3) +# mkdocstrings expects exactly 3 colons, so we need to normalize any colon-fences +# that don't match Quarto cell patterns back to 3 colons. +# This regex matches lines with 3+ colons that aren't Quarto cell syntax: +# - Matches: `::::: module.path` (mkdocstrings), `:::::` (closing fence) +# - Doesn't match: `:::: {.cell ...}` (has braces), handled by other regexes +MKDOCSTRINGS_NORMALIZE_REGEX: Final = re.compile(r"^(:{3,})(\s+(?!{).*)?$") + # https://squidfunk.github.io/mkdocs-material/reference/admonitions/#supported-types # ???+ means a collapsable block rendered open by default TYPE_MAPPING: Final = { @@ -71,11 +83,7 @@ class FileContent: lines: list[str] def get_line_content(self, cursor: Cursor) -> str: - try: - line = self.lines[cursor.line] - except IndexError: - breakpoint() - # Return line content from the cursor column + line = self.lines[cursor.line] return line[cursor.col :] def _trim_line( @@ -138,7 +146,7 @@ class BlockContext: end: Cursor | UnknownEnd def __post_init__(self): - log.info(f"BlockContext: {self}") + log.debug(f"BlockContext: {self}") def get_content(self, file_content: FileContent) -> str: return file_content.get_lines_content(self.start, self.end) @@ -430,16 +438,41 @@ def run(self, lines): else: line = file_content.get_line_content(cursor) + # Normalize mkdocstrings syntax that Quarto wrapped in extra colons + # This only affects lines that didn't match any Quarto block patterns + if match := MKDOCSTRINGS_NORMALIZE_REGEX.match(line): + # Double-check this isn't a Quarto pattern (shouldn't be, but be safe) + if not ( + CELL_REGEX.match(line) + or CELL_ELEM_REGEX.match(line) + or CELL_ELEM_ALT_REGEX.match(line) + ): + rest = match.group(2) or "" + line = ":::" + rest + log.debug( + f"Normalized mkdocstrings: {match.group(0).strip()!r} -> {line.strip()!r}" + ) outs.append(line) cursor = cursor.advance_line(1) if any(x.startswith(":::") for x in outs): - # the ':::' is used in quarto to denote blocks but also used in - # mkdocstrings as a special 'domain-specific-syntax' ... so we need - # to remove them .... it also points to a bug in the preprocessor - # that let them go through ... - bads = [x for x in outs if x.startswith(":::")] - raise ValueError(f"Cell data contains admonition: {bads}") + # Check if these are unprocessed Quarto cell blocks (which would be a bug) + # vs. mkdocstrings syntax or other valid uses of ::: (which should be allowed) + potential_bugs = [] + for x in outs: + if x.startswith(":::"): + # Check if it looks like Quarto cell syntax that escaped processing + if ( + CELL_REGEX.match(x) + or CELL_ELEM_REGEX.match(x) + or CELL_ELEM_ALT_REGEX.match(x) + ): + potential_bugs.append(x) + + if potential_bugs: + raise ValueError( + f"Unprocessed Quarto cell syntax found: {potential_bugs}" + ) return outs diff --git a/mkquartodocs/logging.py b/mkquartodocs/logging.py index ea1afd0..06d6319 100644 --- a/mkquartodocs/logging.py +++ b/mkquartodocs/logging.py @@ -24,8 +24,6 @@ import logging from typing import Any, MutableMapping, Tuple -from mkdocs.utils import warning_filter - class LoggerAdapter(logging.LoggerAdapter): """A logger adapter to prefix messages.""" @@ -63,5 +61,4 @@ def get_logger(name: str) -> LoggerAdapter: A logger configured to work well in MkDocs. """ logger = logging.getLogger(f"mkdocs.plugins.{name}") - logger.addFilter(warning_filter) return LoggerAdapter(name.split(".", 1)[0], logger) diff --git a/pyproject.toml b/pyproject.toml index 4ec9cee..ae9ab1d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "mkquartodocs" -version = "0.6.0" +version = "0.7.0" description = "" authors = [ { name = "J. Sebastian Paez", email = "jspaezp@users.noreply.github.com" }, @@ -23,6 +23,8 @@ check = [ "pytest-datadir>=1.3.1", "pytest>=8.3.1", "pytest-cov>=4.0.0", + "syrupy>=4.0.0", + "pyyaml>=6.0.0", "mdformat>=0.7.16", "mdformat-black>=0.1.1", "mdformat-config>=0.1.3", diff --git a/tests/__snapshots__/test_main.ambr b/tests/__snapshots__/test_main.ambr new file mode 100644 index 0000000..fdc7a63 --- /dev/null +++ b/tests/__snapshots__/test_main.ambr @@ -0,0 +1,5056 @@ +# serializer version: 1 +# name: test_build[docs_assets][docs_assets] + dict({ + 'site/index.html': ''' + + +
+ + + + + + + +++https://github.com/quarto-dev/quarto-cli/issues/10626
+
Right now mermaid diagrams are not rendered correctly on 1.5 So 1.6 + pre-release is needed.
+<figure class=''>{=html}
{width="2.13in"
+ height="2.9in"}
</figure>{=html}
print("Hello")
+
+
+ Hello
+
+ <figure class=''>{=html}
{width="2.13in"
+ height="2.9in"}
</figure>{=html}
<figure class=''>{=html}
{width="2.13in"
+ height="2.9in"}
</figure>{=html}
This is a simple quarto document.
+print("Hello from Quarto!")
+
+
+ Hello from Quarto!
+
+ This is a regular markdown file with mkdocstrings syntax.
+ + +
+ Bases: PurePath
PurePath subclass that can make system calls.
+Path represents a filesystem path but unlike PurePath, also offers + methods to do system calls on path objects. Depending on your system, + instantiating a Path will return either a PosixPath or a WindowsPath + object. You can also instantiate a PosixPath or WindowsPath directly, + but cannot instantiate a WindowsPath on a POSIX system or vice versa.
+ + + + + + +python3.12/pathlib.py825 + 826 + 827 + 828 + 829 + 830 + 831 + 832 + 833 + 834 + 835 + 836 + 837 + 838 + 839 + 840 + 841 + 842 + 843 + 844 + 845 + 846 + 847 + 848 + 849 + 850 + 851 + 852 + 853 + 854 + 855 + 856 + 857 + 858 + 859 + 860 + 861 + 862 + 863 + 864 + 865 + 866 + 867 + 868 + 869 + 870 + 871 + 872 + 873 + 874 + 875 + 876 + 877 + 878 + 879 + 880 + 881 + 882 + 883 + 884 + 885 + 886 + 887 + 888 + 889 + 890 + 891 + 892 + 893 + 894 + 895 + 896 + 897 + 898 + 899 + 900 + 901 + 902 + 903 + 904 + 905 + 906 + 907 + 908 + 909 + 910 + 911 + 912 + 913 + 914 + 915 + 916 + 917 + 918 + 919 + 920 + 921 + 922 + 923 + 924 + 925 + 926 + 927 + 928 + 929 + 930 + 931 + 932 + 933 + 934 + 935 + 936 + 937 + 938 + 939 + 940 + 941 + 942 + 943 + 944 + 945 + 946 + 947 + 948 + 949 + 950 + 951 + 952 + 953 + 954 + 955 + 956 + 957 + 958 + 959 + 960 + 961 + 962 + 963 + 964 + 965 + 966 + 967 + 968 + 969 + 970 + 971 + 972 + 973 + 974 + 975 + 976 + 977 + 978 + 979 + 980 + 981 + 982 + 983 + 984 + 985 + 986 + 987 + 988 + 989 + 990 + 991 + 992 + 993 + 994 + 995 + 996 + 997 + 998 + 999 + 1000 + 1001 + 1002 + 1003 + 1004 + 1005 + 1006 + 1007 + 1008 + 1009 + 1010 + 1011 + 1012 + 1013 + 1014 + 1015 + 1016 + 1017 + 1018 + 1019 + 1020 + 1021 + 1022 + 1023 + 1024 + 1025 + 1026 + 1027 + 1028 + 1029 + 1030 + 1031 + 1032 + 1033 + 1034 + 1035 + 1036 + 1037 + 1038 + 1039 + 1040 + 1041 + 1042 + 1043 + 1044 + 1045 + 1046 + 1047 + 1048 + 1049 + 1050 + 1051 + 1052 + 1053 + 1054 + 1055 + 1056 + 1057 + 1058 + 1059 + 1060 + 1061 + 1062 + 1063 + 1064 + 1065 + 1066 + 1067 + 1068 + 1069 + 1070 + 1071 + 1072 + 1073 + 1074 + 1075 + 1076 + 1077 + 1078 + 1079 + 1080 + 1081 + 1082 + 1083 + 1084 + 1085 + 1086 + 1087 + 1088 + 1089 + 1090 + 1091 + 1092 + 1093 + 1094 + 1095 + 1096 + 1097 + 1098 + 1099 + 1100 + 1101 + 1102 + 1103 + 1104 + 1105 + 1106 + 1107 + 1108 + 1109 + 1110 + 1111 + 1112 + 1113 + 1114 + 1115 + 1116 + 1117 + 1118 + 1119 + 1120 + 1121 + 1122 + 1123 + 1124 + 1125 + 1126 + 1127 + 1128 + 1129 + 1130 + 1131 + 1132 + 1133 + 1134 + 1135 + 1136 + 1137 + 1138 + 1139 + 1140 + 1141 + 1142 + 1143 + 1144 + 1145 + 1146 + 1147 + 1148 + 1149 + 1150 + 1151 + 1152 + 1153 + 1154 + 1155 + 1156 + 1157 + 1158 + 1159 + 1160 + 1161 + 1162 + 1163 + 1164 + 1165 + 1166 + 1167 + 1168 + 1169 + 1170 + 1171 + 1172 + 1173 + 1174 + 1175 + 1176 + 1177 + 1178 + 1179 + 1180 + 1181 + 1182 + 1183 + 1184 + 1185 + 1186 + 1187 + 1188 + 1189 + 1190 + 1191 + 1192 + 1193 + 1194 + 1195 + 1196 + 1197 + 1198 + 1199 + 1200 + 1201 + 1202 + 1203 + 1204 + 1205 + 1206 + 1207 + 1208 + 1209 + 1210 + 1211 + 1212 + 1213 + 1214 + 1215 + 1216 + 1217 + 1218 + 1219 + 1220 + 1221 + 1222 + 1223 + 1224 + 1225 + 1226 + 1227 + 1228 + 1229 + 1230 + 1231 + 1232 + 1233 + 1234 + 1235 + 1236 + 1237 + 1238 + 1239 + 1240 + 1241 + 1242 + 1243 + 1244 + 1245 + 1246 + 1247 + 1248 + 1249 + 1250 + 1251 + 1252 + 1253 + 1254 + 1255 + 1256 + 1257 + 1258 + 1259 + 1260 + 1261 + 1262 + 1263 + 1264 + 1265 + 1266 + 1267 + 1268 + 1269 + 1270 + 1271 + 1272 + 1273 + 1274 + 1275 + 1276 + 1277 + 1278 + 1279 + 1280 + 1281 + 1282 + 1283 + 1284 + 1285 + 1286 + 1287 + 1288 + 1289 + 1290 + 1291 + 1292 + 1293 + 1294 + 1295 + 1296 + 1297 + 1298 + 1299 + 1300 + 1301 + 1302 + 1303 + 1304 + 1305 + 1306 + 1307 + 1308 + 1309 + 1310 + 1311 + 1312 + 1313 + 1314 + 1315 + 1316 + 1317 + 1318 + 1319 + 1320 + 1321 + 1322 + 1323 + 1324 + 1325 + 1326 + 1327 + 1328 + 1329 + 1330 + 1331 + 1332 + 1333 + 1334 + 1335 + 1336 + 1337 + 1338 + 1339 + 1340 + 1341 + 1342 + 1343 + 1344 + 1345 + 1346 + 1347 + 1348 + 1349 + 1350 + 1351 + 1352 + 1353 + 1354 + 1355 + 1356 + 1357 + 1358 + 1359 + 1360 + 1361 + 1362 + 1363 + 1364 + 1365 + 1366 + 1367 + 1368 + 1369 + 1370 + 1371 + 1372 + 1373 + 1374 + 1375 + 1376 + 1377 + 1378 + 1379 + 1380 + 1381 + 1382 + 1383 + 1384 + 1385 + 1386 + 1387 + 1388 + 1389 + 1390 + 1391 + 1392 + 1393 + 1394 + 1395 + 1396 + 1397 + 1398 + 1399 + 1400 + 1401 + 1402 + 1403 + 1404 + 1405 + 1406 + 1407 + 1408 + 1409 + 1410 + 1411 | |
absolute()
+
+ Return an absolute version of this path by prepending the current + working directory. No normalization or symlink resolution is performed.
+Use resolve() to get the canonical path to a file.
+ +python3.12/pathlib.py1205 + 1206 + 1207 + 1208 + 1209 + 1210 + 1211 + 1212 + 1213 + 1214 + 1215 + 1216 + 1217 + 1218 + 1219 + 1220 + 1221 + 1222 + 1223 + 1224 + 1225 + 1226 + 1227 | |
chmod(mode, *, follow_symlinks=True)
+
+ Change the permissions of the path, like os.chmod().
+ +python3.12/pathlib.py1324 + 1325 + 1326 + 1327 + 1328 | |
cwd()
+
+
+ classmethod
+
+
+ Return a new path pointing to the current working directory.
+ +python3.12/pathlib.py1189 + 1190 + 1191 + 1192 + 1193 + 1194 + 1195 + 1196 | |
exists(*, follow_symlinks=True)
+
+ Whether this path exists.
+This method normally follows symlinks; to check whether a symlink exists, + add the argument follow_symlinks=False.
+ +python3.12/pathlib.py853 + 854 + 855 + 856 + 857 + 858 + 859 + 860 + 861 + 862 + 863 + 864 + 865 + 866 + 867 + 868 + 869 | |
expanduser()
+
+ Return a new path with expanded ~ and ~user constructs + (as returned by os.path.expanduser)
+ +python3.12/pathlib.py1399 + 1400 + 1401 + 1402 + 1403 + 1404 + 1405 + 1406 + 1407 + 1408 + 1409 + 1410 + 1411 | |
glob(pattern, *, case_sensitive=None)
+
+ Iterate over this subtree and yield all existing files (of any + kind, including directories) matching the given relative pattern.
+ +python3.12/pathlib.py1082 + 1083 + 1084 + 1085 + 1086 + 1087 + 1088 + 1089 + 1090 + 1091 + 1092 + 1093 + 1094 + 1095 + 1096 | |
group()
+
+ Return the group name of the file gid.
+ +python3.12/pathlib.py1266 + 1267 + 1268 + 1269 + 1270 + 1271 + 1272 + 1273 + 1274 + 1275 | |
hardlink_to(target)
+
+ Make this path a hard link pointing to the same file as target.
+Note the order of arguments (self, target) is the reverse of os.link's.
+ +python3.12/pathlib.py1389 + 1390 + 1391 + 1392 + 1393 + 1394 + 1395 + 1396 + 1397 | |
home()
+
+
+ classmethod
+
+
+ Return a new path pointing to the user's home directory (as + returned by os.path.expanduser('~')).
+ +python3.12/pathlib.py1198 + 1199 + 1200 + 1201 + 1202 + 1203 | |
is_block_device()
+
+ Whether this path is a block device.
+ +python3.12/pathlib.py931 + 932 + 933 + 934 + 935 + 936 + 937 + 938 + 939 + 940 + 941 + 942 + 943 + 944 + 945 | |
is_char_device()
+
+ Whether this path is a character device.
+ +python3.12/pathlib.py947 + 948 + 949 + 950 + 951 + 952 + 953 + 954 + 955 + 956 + 957 + 958 + 959 + 960 + 961 | |
is_dir()
+
+ Whether this path is a directory.
+ +python3.12/pathlib.py871 + 872 + 873 + 874 + 875 + 876 + 877 + 878 + 879 + 880 + 881 + 882 + 883 + 884 + 885 | |
is_fifo()
+
+ Whether this path is a FIFO.
+ +python3.12/pathlib.py963 + 964 + 965 + 966 + 967 + 968 + 969 + 970 + 971 + 972 + 973 + 974 + 975 + 976 + 977 | |
is_file()
+
+ Whether this path is a regular file (also True for symlinks pointing + to regular files).
+ +python3.12/pathlib.py887 + 888 + 889 + 890 + 891 + 892 + 893 + 894 + 895 + 896 + 897 + 898 + 899 + 900 + 901 + 902 | |
is_junction()
+
+ Whether this path is a junction.
+ +python3.12/pathlib.py925 + 926 + 927 + 928 + 929 | |
is_mount()
+
+ Check if this path is a mount point
+ +python3.12/pathlib.py904 + 905 + 906 + 907 + 908 | |
is_socket()
+
+ Whether this path is a socket.
+ +python3.12/pathlib.py979 + 980 + 981 + 982 + 983 + 984 + 985 + 986 + 987 + 988 + 989 + 990 + 991 + 992 + 993 | |
is_symlink()
+
+ Whether this path is a symbolic link.
+ +python3.12/pathlib.py910 + 911 + 912 + 913 + 914 + 915 + 916 + 917 + 918 + 919 + 920 + 921 + 922 + 923 | |
iterdir()
+
+ Yield path objects of the directory contents.
+The children are yielded in arbitrary order, and the + special entries '.' and '..' are not included.
+ +python3.12/pathlib.py1051 + 1052 + 1053 + 1054 + 1055 + 1056 + 1057 + 1058 | |
lchmod(mode)
+
+ Like chmod(), except if the path points to a symlink, the symlink's + permissions are changed, rather than its target's.
+ +python3.12/pathlib.py1330 + 1331 + 1332 + 1333 + 1334 + 1335 | |
lstat()
+
+ Like stat(), except if the path points to a symlink, the symlink's + status information is returned, rather than its target's.
+ +python3.12/pathlib.py843 + 844 + 845 + 846 + 847 + 848 | |
mkdir(mode=511, parents=False, exist_ok=False)
+
+ Create a new directory at this given path.
+ +python3.12/pathlib.py1307 + 1308 + 1309 + 1310 + 1311 + 1312 + 1313 + 1314 + 1315 + 1316 + 1317 + 1318 + 1319 + 1320 + 1321 + 1322 | |
open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)
+
+ Open the file pointed by this path and return a file object, as + the built-in open() function does.
+ +python3.12/pathlib.py1006 + 1007 + 1008 + 1009 + 1010 + 1011 + 1012 + 1013 + 1014 | |
owner()
+
+ Return the login name of the file owner.
+ +python3.12/pathlib.py1256 + 1257 + 1258 + 1259 + 1260 + 1261 + 1262 + 1263 + 1264 | |
read_bytes()
+
+ Open the file in bytes mode, read it, and close the file.
+ +python3.12/pathlib.py1016 + 1017 + 1018 + 1019 + 1020 + 1021 | |
read_text(encoding=None, errors=None)
+
+ Open the file in text mode, read it, and close the file.
+ +python3.12/pathlib.py1023 + 1024 + 1025 + 1026 + 1027 + 1028 + 1029 | |
readlink()
+
+ Return the path to which the symbolic link points.
+ +python3.12/pathlib.py1277 + 1278 + 1279 + 1280 + 1281 + 1282 + 1283 | |
rename(target)
+
+ Rename this path to the target path.
+The target path may be absolute or relative. Relative paths are + interpreted relative to the current working directory, not the + directory of the Path object.
+Returns the new Path instance pointing to the target path.
+ +python3.12/pathlib.py1354 + 1355 + 1356 + 1357 + 1358 + 1359 + 1360 + 1361 + 1362 + 1363 + 1364 + 1365 | |
replace(target)
+
+ Rename this path to the target path, overwriting if that path exists.
+The target path may be absolute or relative. Relative paths are + interpreted relative to the current working directory, not the + directory of the Path object.
+Returns the new Path instance pointing to the target path.
+ +python3.12/pathlib.py1367 + 1368 + 1369 + 1370 + 1371 + 1372 + 1373 + 1374 + 1375 + 1376 + 1377 + 1378 | |
resolve(strict=False)
+
+ Make the path absolute, resolving all symlinks on the way and also + normalizing it.
+ +python3.12/pathlib.py1229 + 1230 + 1231 + 1232 + 1233 + 1234 + 1235 + 1236 + 1237 + 1238 + 1239 + 1240 + 1241 + 1242 + 1243 + 1244 + 1245 + 1246 + 1247 + 1248 + 1249 + 1250 + 1251 + 1252 + 1253 + 1254 | |
rglob(pattern, *, case_sensitive=None)
+
+ Recursively yield all existing files (of any kind, including + directories) matching the given relative pattern, anywhere in + this subtree.
+ +python3.12/pathlib.py1098 + 1099 + 1100 + 1101 + 1102 + 1103 + 1104 + 1105 + 1106 + 1107 + 1108 + 1109 + 1110 + 1111 | |
rmdir()
+
+ Remove this directory. The directory must be empty.
+ +python3.12/pathlib.py1348 + 1349 + 1350 + 1351 + 1352 | |
samefile(other_path)
+
+ Return whether other_path is the same or not as this file + (as returned by os.path.samefile()).
+ +python3.12/pathlib.py995 + 996 + 997 + 998 + 999 + 1000 + 1001 + 1002 + 1003 + 1004 | |
stat(*, follow_symlinks=True)
+
+ Return the result of the stat() system call on this path, like + os.stat() does.
+ +python3.12/pathlib.py836 + 837 + 838 + 839 + 840 + 841 | |
symlink_to(target, target_is_directory=False)
+
+ Make this path a symlink pointing to the target path. + Note the order of arguments (link, target) is the reverse of os.symlink.
+ +python3.12/pathlib.py1380 + 1381 + 1382 + 1383 + 1384 + 1385 + 1386 + 1387 | |
touch(mode=438, exist_ok=True)
+
+ Create this file with the given access mode, if it doesn't exist.
+ +python3.12/pathlib.py1285 + 1286 + 1287 + 1288 + 1289 + 1290 + 1291 + 1292 + 1293 + 1294 + 1295 + 1296 + 1297 + 1298 + 1299 + 1300 + 1301 + 1302 + 1303 + 1304 + 1305 | |
unlink(missing_ok=False)
+
+ Remove this file or link. + If the path is a directory, use rmdir() instead.
+ +python3.12/pathlib.py1337 + 1338 + 1339 + 1340 + 1341 + 1342 + 1343 + 1344 + 1345 + 1346 | |
walk(top_down=True, on_error=None, follow_symlinks=False)
+
+ Walk the directory tree from this directory, similar to os.walk().
+ +python3.12/pathlib.py1113 + 1114 + 1115 + 1116 + 1117 + 1118 + 1119 + 1120 + 1121 + 1122 + 1123 + 1124 + 1125 + 1126 + 1127 + 1128 + 1129 + 1130 + 1131 + 1132 + 1133 + 1134 + 1135 + 1136 + 1137 + 1138 + 1139 + 1140 + 1141 + 1142 + 1143 + 1144 + 1145 + 1146 + 1147 + 1148 + 1149 + 1150 + 1151 + 1152 + 1153 + 1154 + 1155 + 1156 | |
write_bytes(data)
+
+ Open the file in bytes mode, write to it, and close the file.
+ +python3.12/pathlib.py1031 + 1032 + 1033 + 1034 + 1035 + 1036 + 1037 + 1038 | |
write_text(data, encoding=None, errors=None, newline=None)
+
+ Open the file in text mode, write to it, and close the file.
+ +python3.12/pathlib.py1040 + 1041 + 1042 + 1043 + 1044 + 1045 + 1046 + 1047 + 1048 + 1049 | |
The above line uses mkdocstrings syntax to document the pathlib.Path class.
print("Hello")
+
+ import warnings
+ warnings.warn("This is a warning")
+
+
+ Hello
+
+ /var/folders/42/tyvw22cj7t35kbjs0frhf_vw0000gp/T/ipykernel_XXXXX/1292902873.py:4: UserWarning: This is a warning
+ warnings.warn("This is a warning")
+
+ raise NotImplementedError("This is an error")
+
+
+ NotImplementedError: This is an error
+ [31m---------------------------------------------------------------------------[39m
+ [31mNotImplementedError[39m Traceback (most recent call last)
+ [36mCell[39m[36m [39m[32mIn[2][39m[32m, line 1[39m
+ [32m----> [39m[32m1[39m [38;5;28;01mraise[39;00m [38;5;167;01mNotImplementedError[39;00m([33m"[39m[33mThis is an error[39m[33m"[39m)
+
+ [31mNotImplementedError[39m: This is an error
+
+ | a |
| 1 |
| 2 |
| 3 |
| a |
| 1 |
| 2 |
| 3 |