Skip to content

Commit 991d6e1

Browse files
StanFromIrelandpaulrosswillingchugovkezio-melotti
committed
Add structure.md doc
Co-Authored-By: Paul Ross <apaulross@gmail.com> Co-Authored-By: Carol Willing <carolcode@willingconsulting.com> Co-Authored-By: Hugo van Kemenade <hugovk@users.noreply.github.com> Co-Authored-By: Ezio Melotti <ezio.melotti@gmail.com> Co-Authored-By: Adam Turner <9087854+aa-turner@users.noreply.github.com> Co-Authored-By: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
1 parent aea5531 commit 991d6e1

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

InternalDocs/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ it is not, please report that through the
1111
[issue tracker](https://github.com/python/cpython/issues).
1212

1313

14+
General Resources
15+
---
16+
17+
- [Source Code Structure](structure.md)
18+
1419
Compiling Python Source Code
1520
---
1621

InternalDocs/structure.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# CPython source code
2+
3+
This section gives an overview of CPython's code structure and provides
4+
a summary of file locations for modules and built-ins.
5+
6+
7+
## Source code layout
8+
9+
For a Python module, the typical layout is:
10+
11+
* `Lib/<module>.py`
12+
* `Modules/_<module>.c` (if there's also a C accelerator module)
13+
* `Lib/test/test_<module>.py`
14+
* `Doc/library/<module>.rst`
15+
16+
For an extension module, the typical layout is:
17+
18+
* `Modules/<module>module.c`
19+
* `Lib/test/test_<module>.py`
20+
* `Doc/library/<module>.rst`
21+
22+
For builtin types, the typical layout is:
23+
24+
* `Objects/<builtin>object.c`
25+
* `Lib/test/test_<builtin>.py`
26+
* [`Doc/library/stdtypes.rst`](../Doc/library/stdtypes.rst)
27+
28+
For builtin functions, the typical layout is:
29+
30+
* [`Python/bltinmodule.c`](../Python/bltinmodule.c)
31+
* [`Lib/test/test_builtin.py`](../Lib/test/test_builtin.py)
32+
* [`Doc/library/functions.rst`](../Doc/library/functions.rst)
33+
34+
Some exceptions to these layouts are:
35+
36+
* built-in type `int` is at [`Objects/longobject.c`](../Objects/longobject.c)
37+
* built-in type `str` is at [`Objects/unicodeobject.c`](../Objects/unicodeobject.c)
38+
* built-in module `sys` is at [`Python/sysmodule.c`](../Python/sysmodule.c)
39+
* built-in module `marshal` is at [`Python/marshal.c`](../Python/marshal.c)
40+
* Windows-only module `winreg` is at [`PC/winreg.c`](../PC/winreg.c)
41+
42+
43+
## Additional references
44+
45+
The CPython code base is constantly changing and evolving.
46+
Here's a sample of references about CPython's architecture aimed at
47+
building your understanding of CPython internals and its evolution:
48+
49+
50+
### Current references
51+
52+
| Title | Brief | Author | Version |
53+
|------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------|------------------|---------|
54+
| [A guide from parser to objects, observed using GDB](https://hackmd.io/s/ByMHBMjFe) | Code walk from Parser, AST, Sym Table and Objects | Louie Lu | 3.7.a0 |
55+
| [Green Tree Snakes](https://greentreesnakes.readthedocs.io/en/latest/) | The missing Python AST docs | Thomas Kluyver | 3.6 |
56+
| [Yet another guided tour of CPython](https://paper.dropbox.com/doc/Yet-another-guided-tour-of-CPython-XY7KgFGn88zMNivGJ4Jzv) | A guide for how CPython REPL works | Guido van Rossum | 3.5 |
57+
| [Python Asynchronous I/O Walkthrough](https://www.youtube.com/playlist?list=PLpEcQSRWP2IjVRlTUptdD05kG-UkJynQT) | How CPython async I/O, generator and coroutine works | Philip Guo | 3.5 |
58+
| [Coding Patterns for Python Extensions](https://pythonextensionpatterns.readthedocs.io/en/latest/) | Reliable patterns of coding Python Extensions in C | Paul Ross | 3.9+ |
59+
| [Your Guide to the CPython Source Code](https://realpython.com/cpython-source-code-guide/) | Your Guide to the CPython Source Code | Anthony Shaw | 3.8 |
60+
61+
62+
### Historical references
63+
64+
| Title | Brief | Author | Version |
65+
|---------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------|-----------------|---------|
66+
| [Python's Innards Series](https://tech.blog.aknin.name/category/my-projects/pythons-innards/) | ceval, objects, pystate and miscellaneous topics | Yaniv Aknin | 3.1 |
67+
| [Eli Bendersky's Python Internals](https://eli.thegreenplace.net/tag/python-internals) | Objects, Symbol tables and miscellaneous topics | Eli Bendersky | 3.x |
68+
| [A guide from parser to objects, observed using Eclipse](https://docs.google.com/document/d/1nzNN1jeNCC_bg1LADCvtTuGKvcyMskV1w8Ad2iLlwoI/) | Code walk from Parser, AST, Sym Table and Objects | Prashanth Raghu | 2.7.12 |
69+
| [CPython internals: A ten-hour codewalk through the Python interpreter source code](https://www.youtube.com/playlist?list=PLzV58Zm8FuBL6OAv1Yu6AwXZrnsFbbR0S) | Code walk from source code to generators | Philip Guo | 2.7.8 |

0 commit comments

Comments
 (0)