stubber.publish.stubpacker

Module Contents

Classes

StubPackage

Create a stub-only package for a specific version , port and board of micropython

class stubber.publish.stubpacker.StubPackage(package_name: str, version: str = '0.0.1', description: str = 'MicroPython stubs', stubs: Optional[List[Tuple[str, pathlib.Path]]] = None, json_data: Optional[Dict[str, Any]] = None)

Create a stub-only package for a specific version , port and board of micropython

properties:
  • toml_path - the path to the pyproject.toml file

  • package_path - the path to the folder where the package info will be stored (‘./publish’).

  • pkg_version - the version of the package as used on PyPi (semver). Is stored directly in the pyproject.toml file

  • pyproject - the contents of the pyproject.toml file

Parameters
  • package_name (str) –

  • version (str) –

  • description (str) –

  • stubs (Optional[List[Tuple[str, pathlib.Path]]]) –

  • json_data (Optional[Dict[str, Any]]) –

- from_json - load the package from json
- to_json - return the package as json
- create_update_pyproject_toml - create or update the `pyproject.toml` file
- create_readme - create the readme file
- create_license - create the license file
- copy_stubs - copy the stubs to the package folder
- update_included_stubs - update the included stubs in the `pyproject.toml` file
- create_hash - create a hash of the package files
- update_package_files - combines clean, copy, and create reeadme & updates
property package_path pathlib.Path

package path based on the package name and version and relative to the publish folder

Return type

pathlib.Path

property toml_path pathlib.Path

the path to the pyproject.toml file

Return type

pathlib.Path

property pkg_version str

return the version of the package

Return type

str

property pyproject Union[Dict[str, Any], None]

parsed pyproject.toml or None

Return type

Union[Dict[str, Any], None]

to_dict()

return the package as a dict to store in the jsondb

need to simplify some of the Objects to allow serialisation to json - the paths to posix paths - the version (semver) to a string - toml file to list of lines

from_dict(json_data)

load the package from a dict (from the jsondb)

update_package_files()
Update the stub-only package for a specific version of micropython
  • cleans the package folder

  • copies the stubs from the list of stubs.

  • creates/updates the readme and the license file

copy_stubs()

Copy files from all listed stub folders to the package folder the order of the stub folders is relevant as “last copy wins”

  • 1 - Copy all firmware stubs/merged to the package folder

  • 2 - copy the remaining stubs to the package folder

  • 3 - remove *.py files from the package folder

create_readme()
Create a readme file for the package
  • based on the template readme file

  • with a list of all included stub folders added to it (not the individual stub-files)

create_license()
Create a license file for the package
  • copied from the template license file

create_update_pyproject_toml()

create or update/overwrite a pyproject.toml file by combining a template file with the given parameters. and updating it with the pyi files included

update_included_stubs()

Add the stub files to the pyproject.toml file

clean()

Remove the stub files from the package folder

This is used before update the stub package, to avoid lingering stub files, and after the package has been built, to avoid needing to store files multiple times.

.gitignore cannot be used as this will prevent poetry from processing the files.

create_hash(include_md=True) str

Create a SHA1 hash of all files in the package, excluding the pyproject.toml file itself. the hash is based on the content of the .py/.pyi and .md files in the package. if include_md is False , the .md files are not hased, allowing the files in the packeges to be compared simply As a single has is created across all files, the files are sorted prior to hashing to ensure that the hash is stable.

A changed hash will not indicate which of the files in the package have been changed.

Return type

str

update_hashes()

Update the pachage hashes

is_changed() bool

Check if the package has changed, based on the current and the stored hash

Return type

bool

bump(*, rc: int = 0) str

bump the postrelease version of the package, and write the change to disk if rc > 1, the version is bumped to the specified release candidate

Parameters

rc (int) –

Return type

str

run_poetry(parameters: List[str]) bool

Run a poetry commandline in the package folder. Note: this may write some output to the console (‘All set!’)

Parameters

parameters (List[str]) –

Return type

bool

write_package_json()
check() bool

check if the package is valid by running poetry check Note: this will write some output to the console (‘All set!’)

Return type

bool

build() bool

build the package by running poetry build

Return type

bool

publish(production=False) bool
Return type

bool