Skip to content

Commit f2ebd65

Browse files
committed
Merge remote-tracking branch 'upsteam/master'
2 parents d4b9df1 + 05bb260 commit f2ebd65

747 files changed

Lines changed: 14451 additions & 5807 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.git-blame-ignore-revs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#all: Reformat remaining C code that doesn't have a space after a comma.
1+
# top: Update Python formatting to black "2023 stable style".
2+
8b2748269244304854b3462cb8902952b4dcb892
3+
4+
# all: Reformat remaining C code that doesn't have a space after a comma.
25
5b700b0af90591d6b1a2c087bb8de6b7f1bfdd2d
36

47
# ports: Reformat more C and Python source code.

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
# Maintain dependencies for GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "daily"
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Code size comment
2+
3+
on:
4+
workflow_run:
5+
workflows: [Check code size]
6+
types: [completed]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
comment:
14+
runs-on: ubuntu-20.04
15+
steps:
16+
- name: 'Download artifact'
17+
id: download-artifact
18+
uses: actions/github-script@v6
19+
with:
20+
result-encoding: string
21+
script: |
22+
const fs = require('fs');
23+
24+
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
25+
owner: context.repo.owner,
26+
repo: context.repo.repo,
27+
run_id: context.payload.workflow_run.id,
28+
});
29+
30+
const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
31+
return artifact.name == "code-size-report"
32+
});
33+
34+
if (matchArtifact.length === 0) {
35+
console.log('no matching artifact found');
36+
console.log('result: "skip"');
37+
38+
return 'skip';
39+
}
40+
41+
const download = await github.rest.actions.downloadArtifact({
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
artifact_id: matchArtifact[0].id,
45+
archive_format: 'zip',
46+
});
47+
48+
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/code-size-report.zip`, Buffer.from(download.data));
49+
50+
console.log('artifact downloaded to `code-size-report.zip`');
51+
console.log('result: "ok"');
52+
53+
return 'ok';
54+
- name: 'Unzip artifact'
55+
if: steps.download-artifact.outputs.result == 'ok'
56+
run: unzip code-size-report.zip
57+
- name: Post comment to pull request
58+
if: steps.download-artifact.outputs.result == 'ok'
59+
uses: actions/github-script@v6
60+
with:
61+
github-token: ${{secrets.GITHUB_TOKEN}}
62+
script: |
63+
const fs = require('fs');
64+
65+
const prNumber = Number(fs.readFileSync('pr_number'));
66+
const codeSizeReport = `Code size report:
67+
68+
\`\`\`
69+
${fs.readFileSync('diff')}
70+
\`\`\`
71+
`;
72+
73+
const comments = await github.paginate(
74+
github.rest.issues.listComments,
75+
{
76+
owner: context.repo.owner,
77+
repo: context.repo.repo,
78+
issue_number: prNumber,
79+
}
80+
);
81+
82+
comments.reverse();
83+
84+
const previousComment = comments.find(comment =>
85+
comment.user.login === 'github-actions[bot]'
86+
)
87+
88+
// if github-actions[bot] already made a comment, update it,
89+
// otherwise create a new comment.
90+
91+
if (previousComment) {
92+
await github.rest.issues.updateComment({
93+
owner: context.repo.owner,
94+
repo: context.repo.repo,
95+
comment_id: previousComment.id,
96+
body: codeSizeReport,
97+
});
98+
} else {
99+
await github.rest.issues.createComment({
100+
owner: context.repo.owner,
101+
repo: context.repo.repo,
102+
issue_number: prNumber,
103+
body: codeSizeReport,
104+
});
105+
}

.github/workflows/mpremote.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Package mpremote
2+
3+
on:
4+
push:
5+
pull_request:
6+
paths:
7+
- '.github/workflows/*.yml'
8+
- 'tools/**'
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
# Version is determined from git,
17+
# should be deep enough to get to latest tag
18+
fetch-depth: '1000'
19+
- run: |
20+
git fetch --prune --unshallow --tags
21+
- uses: actions/setup-python@v4
22+
- name: Install build tools
23+
run: pip install build
24+
- name: Build mpremote wheel
25+
run: cd tools/mpremote && python -m build --wheel
26+
- name: Archive mpremote wheel
27+
uses: actions/upload-artifact@v3
28+
with:
29+
name: mpremote
30+
path: |
31+
tools/mpremote/dist/mpremote*.whl

.gitignore

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,25 @@
1-
# Compiled Sources
2-
###################
3-
*.o
4-
*.a
5-
*.elf
6-
*.bin
7-
*.map
8-
*.hex
9-
*.dis
10-
*.exe
11-
12-
# Packages
13-
############
14-
15-
# Logs and Databases
16-
######################
17-
*.log
18-
19-
# VIM Swap Files
20-
######################
21-
*.swp
1+
# This .gitignore file is intended to be minimal.
2+
#
3+
# If you find that you need additional rules, such as IDE temporary
4+
# files, please do so either via a global .gitignore file (registered
5+
# with core.excludesFile), or by adding private repository-specific
6+
# rules to .git/info/exclude. See https://git-scm.com/docs/gitignore
7+
# for more information.
228

239
# Build directories
24-
######################
2510
build/
2611
build-*/
12+
docs/genrst/
2713

2814
# Test failure outputs
29-
######################
3015
tests/results/*
3116

3217
# Python cache files
33-
######################
3418
__pycache__/
35-
*.pyc
3619

3720
# Customized Makefile/project overrides
38-
######################
3921
GNUmakefile
4022
user.props
4123

42-
# Generated rst files
43-
######################
44-
genrst/
45-
4624
# MacOS desktop metadata files
47-
######################
4825
.DS_Store

CODECONVENTIONS.md

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,70 @@ changes to the correct style. Without arguments this tool will reformat all
6565
source code (and may take some time to run). Otherwise pass as arguments to
6666
the tool the files that changed and it will only reformat those.
6767

68-
**Important**: Use only [uncrustify](https://github.com/uncrustify/uncrustify)
69-
v0.71 or v0.72 for MicroPython. Different uncrustify versions produce slightly
70-
different formatting, and the configuration file formats are often incompatible.
68+
uncrustify
69+
==========
70+
71+
Only [uncrustify](https://github.com/uncrustify/uncrustify) v0.71 or v0.72 can
72+
be used for MicroPython. Different uncrustify versions produce slightly
73+
different formatting, and the configuration file formats are often
74+
incompatible. v0.73 or newer *will not work*.
75+
76+
Depending on your operating system version, it may be possible to install a pre-compiled
77+
uncrustify version:
78+
79+
Ubuntu, Debian
80+
--------------
81+
82+
Ubuntu versions 21.10 or 22.04LTS, and Debian versions bullseye or bookworm all
83+
include v0.72 so can be installed directly:
84+
85+
```
86+
$ apt install uncrustify
87+
```
88+
89+
Arch Linux
90+
----------
91+
92+
The current Arch uncrustify version is too new. There is an [old Arch package
93+
for v0.72](https://archive.archlinux.org/packages/u/uncrustify/) that can be
94+
installed from the Arch Linux archive ([more
95+
information](https://wiki.archlinux.org/title/Downgrading_packages#Arch_Linux_Archive)). Use
96+
the [IgnorePkg feature](https://wiki.archlinux.org/title/Pacman#Skip_package_from_being_upgraded)
97+
to prevent it re-updating.
98+
99+
Brew
100+
----
101+
102+
This command may work, please raise a new Issue if it doesn't:
103+
104+
```
105+
curl -L https://github.com/Homebrew/homebrew-core/raw/2b07d8192623365078a8b855a164ebcdf81494a6/Formula/uncrustify.rb > uncrustify.rb && brew install uncrustify.rb && rm uncrustify.rb
106+
```
71107

72108
Automatic Pre-Commit Hooks
73109
==========================
74110

75111
To have code formatting and commit message conventions automatically checked,
76-
a configuration file is provided for the [pre-commit]
77-
(https://pre-commit.com/) tool.
112+
a configuration file is provided for the [pre-commit](https://pre-commit.com/)
113+
tool.
78114

79115
First install `pre-commit`, either from your system package manager or via
80116
`pip`. When installing `pre-commit` via pip, it is recommended to use a
81117
virtual environment. Other sources, such as Brew are also available, see
82118
[the docs](https://pre-commit.com/index.html#install) for details.
83119

84120
```
85-
$ apt install pre-commit # Ubuntu
121+
$ apt install pre-commit # Ubuntu, Debian
86122
$ pacman -Sy python-precommit # Arch Linux
87123
$ brew install pre-commit # Brew
88124
$ pip install pre-commit # PyPI
89125
```
90126

91-
Then inside the MicroPython repository, register the git hooks for pre-commit
127+
Next, install [uncrustify (see above)](#uncrustify). Other dependencies are managed by
128+
pre-commit automatically, but uncrustify needs to be installed and available on
129+
the PATH.
130+
131+
Then, inside the MicroPython repository, register the git hooks for pre-commit
92132
by running:
93133

94134
```
@@ -115,7 +155,6 @@ Tips:
115155
* To ignore the pre-commit message format check temporarily, start the commit
116156
message subject line with "WIP" (for "Work In Progress").
117157

118-
119158
Python code conventions
120159
=======================
121160

docs/develop/cmodules.rst

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ A MicroPython user C module is a directory with the following files:
9595
Basic example
9696
-------------
9797

98-
This simple module named ``cexample`` provides a single function
99-
``cexample.add_ints(a, b)`` which adds the two integer args together and returns
100-
the result. It can be found in the MicroPython source tree
98+
The ``cexample`` module provides examples for a function and a class. The
99+
``cexample.add_ints(a, b)`` function adds two integer args together and returns
100+
the result. The ``cexample.Timer()`` type creates timers that can be used to
101+
measure the elapsed time since the object is instantiated.
102+
103+
The module can be found in the MicroPython source tree
101104
`in the examples directory <https://github.com/micropython/micropython/tree/master/examples/usercmodule/cexample>`_
102105
and has a source file and a Makefile fragment with content as described above::
103106

@@ -272,3 +275,13 @@ can now be accessed in Python just like any other builtin module, e.g.
272275
import cexample
273276
print(cexample.add_ints(1, 3))
274277
# should display 4
278+
279+
.. code-block:: python
280+
281+
from cexample import Timer
282+
from time import sleep_ms
283+
284+
watch = Timer()
285+
sleep_ms(1000)
286+
print(watch.time())
287+
# should display approximately 1000

docs/develop/compiler.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,17 @@ The most relevant method you should know about is this:
147147
.. code-block:: c
148148
149149
mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl) {
150+
// Create a context for this module, and set its globals dict.
151+
mp_module_context_t *context = m_new_obj(mp_module_context_t);
152+
context->module.globals = mp_globals_get();
153+
150154
// Compile the input parse_tree to a raw-code structure.
151-
mp_raw_code_t *rc = mp_compile_to_raw_code(parse_tree, source_file, is_repl);
155+
mp_compiled_module_t cm;
156+
cm.context = context;
157+
mp_compile_to_raw_code(parse_tree, source_file, is_repl, &cm);
158+
152159
// Create and return a function object that executes the outer module.
153-
return mp_make_function_from_raw_code(rc, MP_OBJ_NULL, MP_OBJ_NULL);
160+
return mp_make_function_from_raw_code(cm.rc, cm.context, NULL);
154161
}
155162
156163
The compiler compiles the code in four passes: scope, stack size, code size and emit.

docs/differences/index_template.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ above. The sections below describe the current status of these features.
1313
../differences/python_37.rst
1414
../differences/python_38.rst
1515
../differences/python_39.rst
16+
../differences/python_310.rst
1617

1718
For the features of Python that are implemented by MicroPython, there are
1819
sometimes differences in their behaviour compared to standard Python. The

0 commit comments

Comments
 (0)