Skip to content

Commit ccfa2d6

Browse files
committed
Add publishing scripts
1 parent a94684f commit ccfa2d6

File tree

6 files changed

+97
-0
lines changed

6 files changed

+97
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
/api-ids.json
44
/node_modules/
55
*.rst
6+
.idea
7+
.DS_Store
8+
scripts/publish/dist
69
/crowdin/*.json
710
__pycache__

scripts/publish/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
This directory contains scripts and templates for packaging stubs as wheels and publishing these.
2+
3+
Preparation:
4+
5+
* Optional: remove old wheels from dist (required if you want to regenerate wheels for the same version)
6+
* Create a virtual environment
7+
* install `build` and `twine`
8+
9+
Building the wheels:
10+
11+
```
12+
python build-wheels.py
13+
```
14+
15+
Publishing the wheels:
16+
17+
```
18+
python publish-wheels.py
19+
```

scripts/publish/build-wheels.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import shutil
2+
import subprocess
3+
import os.path
4+
import sys
5+
6+
def copy_file(src_path, dest_path, **replacements):
7+
with open(src_path, "tr") as src:
8+
with open(dest_path, "tw") as dst:
9+
content = src.read()
10+
for key in replacements:
11+
content = content.replace("{" + key + "}", replacements[key])
12+
dst.write(content)
13+
14+
15+
dist_dir = os.path.abspath("dist")
16+
all_langs_dir = os.path.join("..", "..", "lang")
17+
template_files = ["pyproject.toml", "README.md"]
18+
for lang in os.listdir(all_langs_dir):
19+
if lang == ".DS_Store":
20+
continue
21+
22+
lang_dir = os.path.join(all_langs_dir, lang)
23+
for name in template_files:
24+
copy_file(os.path.join("templates", name), os.path.join(lang_dir, name), lang=lang)
25+
26+
copy_file("../../LICENSE.md", os.path.join(lang_dir, "LICENSE.md"))
27+
28+
subprocess.run([sys.executable, "-m", "build", "--wheel", "--outdir", "dist", lang_dir])
29+
30+
# clean up
31+
for name in template_files + [
32+
"LICENSE.md", "build", f"micropython_microbit_stubs_{lang.replace('-', '_')}.egg-info"]:
33+
full_path = os.path.join(lang_dir, name)
34+
if os.path.isdir(full_path):
35+
shutil.rmtree(full_path)
36+
else:
37+
os.remove(full_path)
38+

scripts/publish/publish-wheels.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import subprocess
2+
import sys
3+
4+
subprocess.run([sys.executable, "-m", "twine", "upload", "dist/*.whl", "-u", "__token__"])

scripts/publish/templates/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# BBC micro:bit MicroPython typing stubs
2+
3+
This package contains Python stub files for
4+
[MicroPython for micro:bit V2](https://github.com/microbit-foundation/micropython-microbit-v2).
5+
6+
The docstrings are given in language {lang}.
7+
8+
As the package contains stdlib stubs, the _typeshed path_ of the program analyzer (e.g. MyPy or Pyright)
9+
needs to be configured accordingly.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[build-system]
2+
requires = ["setuptools>=68", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "micropython-microbit-stubs-{lang}"
7+
version = "0.0.1-b2"
8+
description = "BBC micro:bit MicroPython type stubs (language: {lang})"
9+
readme = "README.md"
10+
license = "MIT AND Apache-2.0"
11+
license-files = ["LICENSE.md"]
12+
urls = {"Homepage" = "https://github.com/microbit-foundation/micropython-microbit-stubs"}
13+
classifiers = [
14+
"Programming Language :: Python :: Implementation :: MicroPython",
15+
"Typing :: Stubs Only",
16+
]
17+
18+
[tool.setuptools]
19+
packages = ["stdlib"]
20+
21+
package-dir = {"stdlib" = "typeshed/stdlib"}
22+
23+
[tool.setuptools.package-data]
24+
"*" = ["**/*.pyi"]

0 commit comments

Comments
 (0)