Skip to content

Add publishing scripts #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
/api-ids.json
/node_modules/
*.rst
.idea
.DS_Store
scripts/publish/dist
/crowdin/*.json
__pycache__
19 changes: 19 additions & 0 deletions scripts/publish/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This directory contains scripts and templates for packaging stubs as wheels and publishing these.

Preparation:

* Optional: remove old wheels from dist (required if you want to regenerate wheels for the same version)
* Create a virtual environment
* install `build` and `twine`

Building the wheels:

```
python build-wheels.py
```

Publishing the wheels:

```
python publish-wheels.py
```
38 changes: 38 additions & 0 deletions scripts/publish/build-wheels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import shutil
import subprocess
import os.path
import sys

def copy_file(src_path, dest_path, **replacements):
with open(src_path, "tr") as src:
with open(dest_path, "tw") as dst:
content = src.read()
for key in replacements:
content = content.replace("{" + key + "}", replacements[key])
dst.write(content)


dist_dir = os.path.abspath("dist")
all_langs_dir = os.path.join("..", "..", "lang")
template_files = ["pyproject.toml", "README.md"]
for lang in os.listdir(all_langs_dir):
if lang == ".DS_Store":
continue

lang_dir = os.path.join(all_langs_dir, lang)
for name in template_files:
copy_file(os.path.join("templates", name), os.path.join(lang_dir, name), lang=lang)

copy_file("../../LICENSE.md", os.path.join(lang_dir, "LICENSE.md"))

subprocess.run([sys.executable, "-m", "build", "--wheel", "--outdir", "dist", lang_dir])

# clean up
for name in template_files + [
"LICENSE.md", "build", f"micropython_microbit_stubs_{lang.replace('-', '_')}.egg-info"]:
full_path = os.path.join(lang_dir, name)
if os.path.isdir(full_path):
shutil.rmtree(full_path)
else:
os.remove(full_path)

4 changes: 4 additions & 0 deletions scripts/publish/publish-wheels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import subprocess
import sys

subprocess.run([sys.executable, "-m", "twine", "upload", "dist/*.whl", "-u", "__token__"])
9 changes: 9 additions & 0 deletions scripts/publish/templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# BBC micro:bit MicroPython typing stubs

This package contains Python stub files for
[MicroPython for micro:bit V2](https://github.com/microbit-foundation/micropython-microbit-v2).

The docstrings are given in language {lang}.

As the package contains stdlib stubs, the _typeshed path_ of the program analyzer (e.g. MyPy or Pyright)
needs to be configured accordingly.
24 changes: 24 additions & 0 deletions scripts/publish/templates/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[build-system]
requires = ["setuptools>=68", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "micropython-microbit-stubs-{lang}"
version = "0.0.1-b2"
description = "BBC micro:bit MicroPython type stubs (language: {lang})"
readme = "README.md"
license = "MIT AND Apache-2.0"
license-files = ["LICENSE.md"]
urls = {"Homepage" = "https://github.com/microbit-foundation/micropython-microbit-stubs"}
classifiers = [
"Programming Language :: Python :: Implementation :: MicroPython",
"Typing :: Stubs Only",
]

[tool.setuptools]
packages = ["stdlib"]

package-dir = {"stdlib" = "typeshed/stdlib"}

[tool.setuptools.package-data]
"*" = ["**/*.pyi"]