Home

Awesome

glyph

A proof-of-concept package manager for Cairo contracts/libraries. Distribution through pypi. Installation through existing package managers -- pip, pipenv, poetry.

Intended to be a lightweight layer on top of existing python package management. Sole responsibility is collecting contracts/libraries registered to the contracts namespace package, and copying their contents to a new contracts/lib folder.

NOTE: solely experimental to play around one potential strategy, doubtful that this would be a real package management solution for the ecosystem

Usage

Install with pip install cairo-glyph. Additionally, pip install cairo-nile and nile init to intialize a starter project.

Check out the help command (auto-gen from code, will always be more up to date than this README):

(venv) sam@sam:~/dev/eth/tmp$ glyph --help
Usage: glyph [OPTIONS] COMMAND [ARGS]...

  A proof-of-concept package manager for Cairo.

Options:
  --install-completion  Install completion for the current shell.
  --show-completion     Show completion for the current shell, to copy it or
                        customize the installation.
  --help                Show this message and exit.

Commands:
  clean  Remove everything in the lib directory
  use    Install one or all added cairo packages in the project

Use all libraries installed to the venv:

(venv) sam@sam:~/dev/eth/tmp$ glyph use --all
šŸ”Ž Discovering installed contracts...

āœ… Done.

For now, nothing is installed. To change that, do a pip install cairo-placeholder

Then do it again:

(venv) $ glyph use --all
šŸ”Ž Discovering installed contracts...

 ā€¢ Using contracts.placeholder

āœ… Done.

If we inspect our project directory we now see it's installed in a contracts/lib folder:

ā”œā”€ā”€ accounts.json
ā”œā”€ā”€ contracts
ā”‚Ā Ā  ā”œā”€ā”€ contract.cairo
ā”‚Ā Ā  ā””ā”€ā”€ libs
ā”‚Ā Ā      ā””ā”€ā”€ placeholder
ā”‚Ā Ā          ā””ā”€ā”€ contract.cairo
ā”œā”€ā”€ Makefile
ā”œā”€ā”€ tests
ā”‚Ā Ā  ā””ā”€ā”€ test_contract.p

šŸ„³

Your Own Library Setup

In order to allow your contracts to be installed, a few conventions must be followed.

contracts                # The "namespace package" that the contracts are installed to
ā””ā”€ā”€ placeholder          # The library you are distributing
    ā”œā”€ā”€ contract.cairo
    ā””ā”€ā”€ __init__.py      # Required to be installable.
setup.py                 # The installer

The actual setup.py will look something like this:

from setuptools import setup


setup(
    name="placeholder",

    version="1",
    description="",
    long_description="",

    author="Jane Doe",
    author_email="author@example.com",

    license="MIT License",

    packages=["contracts.placeholder"],
    # Include all extra package data. Possible to include *.cairo only
    package_data={"": ["*"]},
    zip_safe=False,
)

If using poetry, have pyproject.toml like:

[tool.poetry]
name = "cairo-placeholder"
version = "0.0.2"
description = "Example project for cairo-glyph"
authors = ["Your Name <you@example.com>"]
license = "MIT License"
readme = "README.md"
packages = [
    { include = "contracts/*" },
]

[tool.poetry.dependencies]
python = "^3.7"
cairo-nile = "^0.3.0"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

Once distributed on pypi, one could:

(venv) $ pip install cairo-glyph cairo-placeholder
...
(venv) $ glyph use placeholder
šŸ”Ž Discovering installed contracts...

 ā€¢ Using contracts.placeholder

āœ… Done.

Adding the following to your project:

contracts/
ā””ā”€ā”€ libs
    ā””ā”€ā”€ placeholder
        ā””ā”€ā”€ contract.cairo