Skip to content

Commit 7825ca0

Browse files
author
boris
committedJan 23, 2021
Proofread blog posts
1 parent 7b1a389 commit 7825ca0

5 files changed

+42
-43
lines changed
 

‎_config.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# in the templates via {{ site.myvariable }}.
2020

2121
title: "RustPython"
22-
description: "An open source Python-3 (CPython >= 3.5.0) Interpreter written in Rust 🐍 😱 🤘"
22+
description: "An open source Python 3 (CPython >= 3.5.0) interpreter written in Rust 🐍 😱 🤘"
2323
# baseurl: "/" # the subpath of your site, e.g. /blog
2424
url: "https://rustpython.github.io" # the base hostname & protocol for your site, e.g. http://example.com
2525
github_username: RustPython
@@ -29,7 +29,7 @@ docs: https://github.com/RustPython/docs/
2929
gitter: https://gitter.im/rustpython/Lobby
3030
show_excerpts: true
3131
contributor_excerpt: "" # TODO: write something here, goes right under "Contributors" heading
32-
blog-intro: Create an issue if you read something wrong. Edit posts or create new ones via PR on <a target="_blank" href="https://github.com/RustPython/rustpython.github.io">github.com/RustPython/rustpython.github.io</a>
32+
blog-intro: Create an issue if you see something wrong. Edit posts or create new ones via PR on <a target="_blank" href="https://github.com/RustPython/rustpython.github.io">github.com/RustPython/rustpython.github.io</a>
3333

3434
navigation:
3535
- title: Blog

‎_posts/2020-03-12-thing-explainer-parser.markdown

+13-13
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ date: 2020-04-02 11:34:01 -0400
66

77
This post goes over the RustPython parser. You can see the source code at [RustPython/parser/](https://github.com/RustPython/RustPython/tree/master/parser).
88

9-
When you write code in python and run it, an interpreter, such as the RustPython interpreter, acts as the translator between you and your machine.
9+
When you write code in Python and run it, an interpreter, such as the RustPython interpreter, acts as the translator between you and your machine.
1010

11-
The interpreter has the job of turning your human code into byte code that a python virtual machine can run. Bytecode is an intermediate code between source code and machine code. This makes it portable across multiple hardware and operating systems. Bytecode "works" as long as you implement a virtual machine(vm) that can run it. There is a performance penalty for this flexibility. RustPython has a vm under [RustPython/vm/](https://github.com/RustPython/RustPython/tree/master/vm). Other posts, will go into the details of that vm but now let's figure out how to turn code into bytecode.
11+
The interpreter has the job of turning your human code into bytecode that a Python virtual machine can run. Bytecode is an intermediate code between source code and machine code. This makes it portable across multiple hardware and operating systems. Bytecode "works" as long as you implement a virtual machine (vm) that can run it. There is a performance penalty for this flexibility. RustPython has a vm under [RustPython/vm/](https://github.com/RustPython/RustPython/tree/master/vm). Other posts will go into the details of that vm but now let's figure out how to turn code into bytecode.
1212

1313

14-
## How does bytecode look like
14+
## What bytecode looks like
1515

16-
Seeing is believing. To see what bytecode looks like, you can use a Python module called [`dis`](https://docs.python.org/3/library/dis.html). dis stands for disassembler. You can write source code then see how its bytecode looks like. Here is an example:
16+
Seeing is believing. To see what bytecode looks like, you can use a Python module called [`dis`](https://docs.python.org/3/library/dis.html). "dis" is short of for _dis_assembler. You can write source code then see how its bytecode looks like. Here is an example:
1717

1818
![bytecode](/assets/media/bytecode.jpg)
1919

2020

21-
## How RustPython turns your code to bytecode
21+
## How RustPython turns your code into bytecode
2222

23-
Here are the main steps that RustPython currently does:
23+
Here are the main steps that RustPython currently goes through:
2424
- parse the line of source code into tokens
2525
- determine if the tokens have a valid syntax
2626
- create an Abstract Syntax Tree (AST)
@@ -31,7 +31,7 @@ This list of steps introduces some new concepts like: tokens and abstract syntax
3131

3232
### Step 1: parsing source code into tokens
3333

34-
The fastest way to understand what tokens are, is to see them. Conveniently, Python comes with a [tokenizer](https://docs.python.org/3/library/tokenize.html). Here is what happen if I run the tokenizer on the function that I created earlier.
34+
The fastest way to understand what tokens are, is to see them. Conveniently, Python comes with a [tokenizer](https://docs.python.org/3/library/tokenize.html). Here is what happens if I run the tokenizer on the function that I created above.
3535

3636
`$ python -m tokenize file.py`
3737

@@ -46,20 +46,20 @@ def add(x,y):
4646
![tokenzizing](/assets/media/tokenizing.jpg)
4747

4848

49-
A picture IS worth a thousand word 😛 Those are the tokens. They are the basic "units" in the programming language. They are the keywords and operators that you typed. Even new lines and identations count.
49+
A picture IS worth a thousand words 😛 Those are the tokens. They are the basic "units" of the programming language. They are the keywords and operators that you typed. Even new lines and identation count.
5050

5151
If you want to sound fancy:
5252
- The tokens are the basic "lexical components"
5353
- The parsing process is called "lexical analysis"
54-
- The thing that does the process is a "lexer"
54+
- The thing that does this is a "lexer"
5555

5656
Here is the link to the RustPython lexer.
5757

5858
**`RustPython/parser/lexer.rs`** >>
5959
[source code](https://github.com/RustPython/RustPython/blob/master/parser/src/lexer.rs)
6060

6161

62-
If you want dive into the details of lexical analysis, check out [Python in a nutshell / Lexical structure](https://learning.oreilly.com/library/view/python-in-a/9781491913833/ch03.html#python_language-id00003)
62+
If you want to dive into the details of lexical analysis, check out [Python in a nutshell / Lexical structure](https://learning.oreilly.com/library/view/python-in-a/9781491913833/ch03.html#python_language-id00003)
6363

6464

6565
### Step 2 : determine if the tokens are valid syntax
@@ -70,8 +70,8 @@ In the previous step, if you add random stuff to your function and tokenize it,
7070

7171
So don't hate on the whole interpreter when you get error messages! or at least don't hate on the tokenizer!
7272

73-
To determine if the tokens are valid syntax, first you need a definition of what a valid syntax is. Python has a defined "grammar" or set of rules. The official reference is on [this link](https://docs.python.org/3/reference/grammar.html). There, you will find a machine readable file. You may read a book to know the rules of python, but words are too "fluffy", an algorithm that verifies if rules are followed needs a very strict set of rules encoded in a file. [This video](https://www.youtube.com/watch?v=KGMFvy2d5OI) explains the Python grammar and the file's notation.
74-
As the presenter puts it, this is the spirit of the beast (python) and it is only ~10KB 😭 (compare that to the size of python books you had to read!)
73+
To determine if the tokens are valid syntax, first you need a definition of what a valid syntax is. Python has a defined "grammar" or set of rules. The official reference is on [this link](https://docs.python.org/3/reference/grammar.html). There, you will find a machine readable file. You may read a book to know the rules of Python, but words are too "fluffy", an algorithm that verifies if the rules are followed needs a very strict set of rules encoded in a file. [This video](https://www.youtube.com/watch?v=KGMFvy2d5OI) explains the Python grammar and the file's notation.
74+
As the presenter puts it, this is the spirit of the beast (Python) and it is only ~10KB 😭 (compare that to the size of the Python books you had to read!)
7575

7676
So, we have the rules or grammar of a programming language in a machine encoded format... now we need to write something that verifies that those rules were followed... This sounds like something that other people could use and like something that should exist as an open source project! 🤔
7777

@@ -91,7 +91,7 @@ You can do:
9191

9292
## Recap 🥴 🥵
9393

94-
As a recap, when you write a line of python code and "run it", here is what the RustPython interpreter does:
94+
As a recap, when you write a line of Python code and "run it", here is what the RustPython interpreter does:
9595

9696
**INPUT: your code** (in `file.py` or interactive shell)
9797
⬇️ parse the line of source code into tokens
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
11
---
22
layout: post
3-
title: "How to contribute to RustPython by CPython unittest"
3+
title: "How to contribute to RustPython using CPython's unit tests"
44
date: 2020-04-05 01:45:00 +0900
55
categories: [guideline, featured]
66
permalink: guideline/2020/04/04/how-to-contribute-by-cpython-unittest.html
77
---
88

9-
At the very end of 2019, we finally reached one of the short-term goals: CPython unittest support. Due to this enhancement, finding CPython compatibility is easier than before.
10-
Probably this will be the major source of contribution spots for the new contributors this year. Here is a simple guideline.
9+
At the very end of 2019, we finally reached one of our short-term goals: CPython `unittest` support which makes finding CPython compatibility errors easier than ever.
10+
This will probably be the major source of contributions for new contributors this year. Here is a simple guideline.
1111

1212
## Fix known compatibility bugs
1313
Let's find an incompatibility issue and fix it.
14-
15-
1. See `Lib/test` directory of the project. There are many `test_` prefixed files like `test_unicode.py`.
14+
1. Look at the `Lib/test` directory of the project. There are many `test_` prefixed files like `test_unicode.py`.
1615
2. Try to open one of them. It might look just fine at a glance - but search for `TODO: RUSTPYTHON` in the files. There are tons of skipped, marked as an expected failure or commented out tests.
17-
1. Alternatively, try looking at the [regression tests results]({% link pages/regression-tests-results.markdown %}) to find skipped or expected failure tests; some of them have
16+
1. Alternatively, try looking at the [regression test results]({% link pages/regression-tests-results.markdown %}) to find skipped or expected failure tests; some of them have
1817
notes for a way to resolve the issue.
19-
3. Choose one or two interesting bugs. Remove the test blocker - skip, expectedFailure or comments.
18+
3. Choose one or two interesting bugs. Remove the test blocker - `skip`, `expectedFailure` or comments.
2019
4. Try to fix them.
2120

22-
Here is a quick tip to run single unittest file.
21+
Here's how you run a single unittest file:
2322

24-
`$ RUSTPYTHONPATH=Lib cargo run --release Lib/test/test_unicode.py`
23+
` $ RUSTPYTHONPATH=Lib cargo run --release Lib/test/test_unicode.py`
2524

2625
## Add a new unittest file
27-
Because CPython unittest is not perfectly working in RustPython, we are doing this one by one with editings.
28-
1. Download CPython source code.
29-
2. Check out a specific version of CPython. For now, 3.8.2 is recommended. (We are testing against CPython 3.8 and 3.8.2 is the most recent version for now)
30-
3. Copy a file from CPython `Lib/test`
31-
4. Commit the file without editing. Specify copied CPython version to commit message.
26+
Because CPython unittest doesn't work work perfectly in RustPython, we are adding test files one by one. Here's how:
27+
1. Download the CPython source code with `git clone https://github.com/python/cpython.git`.
28+
2. Check out a specific version of CPython. We test against CPython 3.8, so the most recent release of 3.8 ([currently 3.8.7](https://www.python.org/doc/versions/)) is recommended.
29+
3. Copy a file from CPython's `Lib/test`
30+
4. Commit the file without editing it. Specify the CPython version you copied from in the commit message.
3231
5. Try to edit it until it runs without a crash or failure.
3332
6. Commit the changes to make it run. This is the core contribution.
3433

35-
Because RustPython is not perfect, "try to edit it until it runs" doesn't mean to make 100% successful running. The common editing methods here:
36-
1. At least it must be able to start to run the test. Fix the test code or bug until it runs at least a single unit of the test. Typically, unimplemented stdlib or missing files of unittest can make issues. Sometimes RustPython bugs make issues too.
37-
2. If any test is not loadable by `SyntaxError`, that part is required to be commented out.
38-
3. If any test leads to a crash of RustPython, this code is not possible to run. Mark the test to skip.
39-
4. If any test is run but fails, this is an incompatibility issue. Mark the test as an expected failure.
34+
Because RustPython is not perfect, "try to edit it until it runs" doesn't mean to make it run 100% of the tests successfully. The common methods to make the test file pass are:
35+
1. It must at least be able to start to run the tests. Fix the test code or bug until it runs at least a single unit of the test. Typically, unimplemented stdlib or missing files in `unittest` can cause issues. Sometimes RustPython bugs cause issues too.
36+
2. If any test can't be loaded because of a `SyntaxError`, you'll have to comment that part out.
37+
3. If any test leads to a crash of RustPython, this code can't be run. Mark the test with `@unittest.skip('TODO: RUSTPYTHON')` to skip it.
38+
4. If any test runs but fails, this is an incompatibility issue. Mark the test as an expected failure with `@unittest.expectedFailure`.
4039

41-
We prefer the reversed order of upper methods. The later the more strict so easy to detect any progress or regression.
42-
When we temporarily disable parts of unittest due to RustPython caveats, we mark them to find it out easily later. Please check the examples below or search for `TODO: RUSTPYTHON` in `Lib/test` directory to check actual usage.
40+
We prefer the reversed order of above methods. The later, the more strict, so it's easier to detect any progress or regression.
41+
When we temporarily disable parts of `unittest` due to RustPython caveats, we mark them to make it easier to find (and re-enable!) them later. Please see the examples below or search for `TODO: RUSTPYTHON` in the `Lib/test` directory to check actual usage.
4342

4443
Comment out:
4544
```python
@@ -48,18 +47,18 @@ Comment out:
4847
# def ... # commented out tests
4948
```
5049

51-
skip:
50+
`skip`:
5251
```python
5352
@unittest.skip("TODO: RUSTPYTHON")
5453
def ... # skipped tests
5554
```
5655

57-
expectedFailure:
56+
`expectedFailure`:
5857
```python
5958
# TODO: RUSTPYTHON
6059
@unittest.expectedFailure
6160
def ... # failed tests
6261
```
6362

6463
## Development guide
65-
For the general source of the development, please visit the [RustPython development guide](https://github.com/RustPython/RustPython/blob/master/DEVELOPMENT.md)
64+
For a general introduction to RustPython development, please visit the [RustPython development guide](https://github.com/RustPython/RustPython/blob/master/DEVELOPMENT.md)

‎index.markdown

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ installation:
2626

2727
goals:
2828
- goal:
29-
Full Python-3 environment entirely in Rust (not CPython bindings), with
29+
Full Python 3 environment entirely in Rust (not CPython bindings), with
3030
a clean implementation and no compatiblity hacks.
3131
# TODO: integrate this into the "goals" boxes
3232
progress:
@@ -53,10 +53,10 @@ There are many implementations of Python. For example:
5353
- [PyPy](https://www.pypy.org/) (Python)
5454
- [Stackless](http://www.stackless.com/)
5555

56-
Each of these implementations offer some benefits: Jython, for example, compiles Python source code to Java byte code, then routes it to the Java Virtual Machine. Because Python code is translated to Java byte code, it looks and feels like a true Java program at runtime and so it integrates well with Java applications.
56+
Each of these implementations offer some benefits: Jython, for example, compiles Python 2 source code to Java byte code, then routes it to the Java Virtual Machine. Because Python code is translated to Java bytecode, it looks and feels like a true Java program at runtime and so it integrates well with Java applications.
5757

5858
IronPython is well-integrated with .NET, which means IronPython can use the .NET framework and Python libraries or vice versa.
5959

6060
We want to unlock the same possibilities that Jython and IronPython enable, but for the Rust programming language. In addition, thanks to Rusts' minimal runtime, we're able to compile RustPython to WebAssembly and allow users to run their Python code easily in the browser.
6161

62-
Check the "learn more" section for an explainer of all those jargon-y words, or read the blog for more in-depth technical discussion.
62+
Check out the "learn more" section for an explainer of all those jargon-y words, or read the blog for more in-depth technical discussion.

‎manifest.webmanifest

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
"start_url": ".",
55
"display": "standalone",
66
"theme_color": "#F74C00",
7-
"description": "An open source Python-3 (CPython >= 3.5.0) Interpreter written in Rust 🐍 😱 🤘"
7+
"description": "An open source Python 3 (CPython >= 3.5.0) Interpreter written in Rust 🐍 😱 🤘"
88
}

0 commit comments

Comments
 (0)
Please sign in to comment.