Skip to content
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 @@ -177,3 +177,6 @@ dmypy.json
# .NET build artifacts
/tests/**/bin/
/tests/**/obj/

# Canonical workshop
/.workshop.lock
43 changes: 43 additions & 0 deletions .workshop/dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: dev
base: ubuntu@24.04
sdks:
- name: uv
channel: latest/stable
- name: copilot
channel: latest/stable
- name: project-starcraft
actions:
setup: make setup
lint: make lint
format: make format
Comment on lines +11 to +12

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My puter 'splodes whenever I try to run either of these:

❯ workshop run -- format
success=true
ruff check --fix  snapcraft tests || success=false
ruff format  snapcraft tests
$success || exit 1
error: Failed to initialize cache at /var/lib/snapd/void/.ruff_cache: Permission denied (os error 13)
E902 No such file or directory (os error 2)
--> snapcraft:1:1

E902 No such file or directory (os error 2)
--> tests:1:1

Found 2 errors.
error: Failed to initialize cache at /var/lib/snapd/void/.ruff_cache: Permission denied (os error 13)
error: Failed to format snapcraft: No such file or directory (os error 2)
error: Failed to format tests: No such file or directory (os error 2)
make: *** [common.mk:107: format-ruff] Error 2


❯ workshop run -- lint
ruff check  snapcraft tests
ruff format --diff  snapcraft tests
error: Failed to initialize cache at /var/lib/snapd/void/.ruff_cache: Permission denied (os error 13)
E902 No such file or directory (os error 2)
--> snapcraft:1:1

E902 No such file or directory (os error 2)
--> tests:1:1

Found 2 errors.
make: *** [common.mk:129: lint-ruff] Error 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

test: make test
test-fast: make test-fast
test-coverage: make test-coverage
schema: make schema
clean: make clean
lock: |
uv lock "$@"
make setup
install-branch: |
set -euo pipefail
if [[ $# -lt 2 ]]; then
echo "Usage: install-branch <PACKAGE|URL> <BRANCH>" >&2
echo "" >&2
echo "Examples:" >&2
echo " workshop run -- install-branch craft-parts main" >&2
echo " workshop run -- install-branch https://github.com/user/repo.git main" >&2
exit 1
fi

REPO_OR_URL=$1
BRANCH=$2

# Check if it's a URL (contains :// or ends with .git)
if [[ $REPO_OR_URL =~ "://" ]] || [[ $REPO_OR_URL == *.git ]]; then
REPO_URL=$REPO_OR_URL
else
# Assume it's a package name, use canonical org by default
REPO_URL="https://github.com/canonical/${REPO_OR_URL}"
fi

uv pip install "git+${REPO_URL}@${BRANCH}"
2 changes: 2 additions & 0 deletions .workshop/starcraft/hooks/setup-base
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
apt-get update
apt-get install make
3 changes: 3 additions & 0 deletions .workshop/starcraft/hooks/setup-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
uv tool install ruff
uv tool install ty
make setup
13 changes: 13 additions & 0 deletions .workshop/starcraft/sdk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# For details: https://canonical-workshop.readthedocs-hosted.com/latest/explanation/sdks/sdks/#sketch-sdk
name: starcraft
plugs:
# Use this configuration to mount a host directory to the workshop
# models:
# interface: mount
# workshop-target: /home/workshop/models
slots:
# Use this configuration to expose a port, then add a corresponding system SDK plug
# More details: https://canonical-workshop.readthedocs-hosted.com/latest/how-to/customize-workshops/forward-ports/
# my-web-server:
# interface: tunnel
# endpoint: 8080
53 changes: 53 additions & 0 deletions docs/contribute/development.rst

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,59 @@ Inside the project directory, set up the development environment:
If these commands complete without error, your environment is ready.


Develop with Workshop
---------------------

.. admonition:: Work in progress
:class: caution

Workshop integration for Snapcraft is under active development. Some
features may be incomplete or subject to change.

Local development environments require periodic maintenance and debugging. You can
instead develop inside a sandbox, where the required development software
is pre-installed and immutable. Snapcraft provides a development image that's
controlled with `Workshop <https://documentation.ubuntu.com/canonical-workshop/>`__.

With the `Workshop Snap <https://snapcraft.io/workshop>`__ installed, start the
development environment by running ``workshop launch dev`` from within the Snapcraft
directory. When the workshop starts, it automatically runs ``make setup`` inside the
container. From there, use the pre-configured actions to carry out common
development tasks:
Comment on lines +86 to +90

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the inline command is easy to skim over when the rest of the commands are code-blocked:

Suggested change
With the `Workshop Snap <https://snapcraft.io/workshop>`__ installed, start the
development environment by running ``workshop launch dev`` from within the Snapcraft
directory. When the workshop starts, it automatically runs ``make setup`` inside the
container. From there, use the pre-configured actions to carry out common
development tasks:
With the `Workshop Snap <https://snapcraft.io/workshop>`__ installed, start the
development environment from within the Snapcraft directory:
.. code-block:: bash
workshop launch dev
When the workshop starts, it automatically runs ``make setup`` inside the
container. From there, use the pre-configured actions to carry out common
development tasks:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this. 👍


.. code-block:: bash

workshop run -- setup # re-run the virtual environment setup
workshop run -- lint # run all linters
workshop run -- format # run the autoformatters
workshop run -- test # run the full test suite
workshop run -- test-fast # run the fast test suite
workshop run -- test-coverage # run tests with a coverage report
workshop run -- schema # regenerate the JSON schema
workshop run -- clean # remove temporary build artifacts

Two additional actions support dependency work.

The ``lock`` action runs ``uv lock`` with any arguments you pass, then re-runs
``make setup``:

.. code-block:: bash

workshop run -- lock --upgrade-package craft-parts

The ``install-branch`` action installs a dependency directly from a Git branch. Pass a
short package name (resolves to the canonical GitHub organization by default)
or a full repository URL:

.. code-block:: bash

workshop run -- install-branch craft-parts main
workshop run -- install-branch https://github.com/user/craft-parts.git feat/my-fix

Workshop provides most of the features needed for developing Snapcraft. Read the
`Workshop tutorial <https://documentation.ubuntu.com/canonical-workshop/latest/tutorial/>`__
to learn what else Workshop can do.

Choose a task
-------------

Expand Down
Loading