More on an Ubuntu Component Store

After yesterday’s musings on a “component store” for Ubuntu developers, a few people said “hm that sounds interesting, how would it work?” So I’ve thrown together a little demo.

I should be clear: this is a demo. It’s not a component store; it’s not for real use; you can’t add things to it; you can’t use it in your apps. This is just enough of a test implementation to allow people to talk about whether this is a good idea or not. None of the code I’ve written would be used in a real implementation, if such a thing existed: I don’t do any error checking, I don’t have any tests. It’s just to give a demo of what I think the developer experience of a component store might be like if it existed, which it does not.

First you need the utility which searches the store, which is called ucs. Get it with bzr branch lp:~sil/+junk/ucs-cli. You now have a utility named ucs which can search the component store for components you might find useful in your apps.

Next, an app which uses it. Grab a demo with bzr branch lp:~sil/+junk/ucs-demo-app. You can now load that app into the Ubuntu SDK editor, or just run it from the command line with qmlscene ucs-demo-app/UCSDemoApp.qml. If you do that, you’ll see that it’s missing components: UCSDemoApp.qml:3 "ubuntu_component_store": no such directory. So, the app needs components and they aren’t installed, which is correct. Change to the app’s folder and run ucs install.1

$ cd ucs-demo-app
$ ucs install
Installing RedButton

and now the app should work: qmlscene UCSDemoApp.qml shows an app with a red button in it. If you look at the source of the app in the ucs-demo-app folder, you’ll see two things that make it different from a stock app:

  1. import "ubuntu_component_store" at the top of UCSDemoApp.qml. This includes components installed from the UCS into the app. You don’t need to individually name the components you import: just import "ubuntu_component_store". The app can then use all the components it asks for, such as the RedButton {} QML Item.

  2. there is an ubuntu_component_store.json file in the app’s folder. This ships with the app, and it describes the components that this app uses. Basically, it is JSON like this: { dependencies: { RedButton: "*" }}, describing that this app requires a component called RedButton and doesn’t care about its version number (hence "*").

So the process for working on an app which uses components from the store is: get the app source, then ucs install. That will install all the components that the app requires, and then you can start hacking on the app.

The process for developing an app which needs components: if you want to add a component to your app-in-progress, then ucs list will show the list of all components (which in this demo is one, RedButton), and ucs install RedButton will install that component2 and update ubuntu_component_store.json to add it to your dependency list. So when developing, just ucs install ComponentINeed, and then make sure that ubuntu_component_store.json is checked into source control and that the ubuntu_component_store/ folder isn’t checked in.

Those of you who have worked with node.js and npm will be thinking: this looks a lot like npm. You are not wrong. I think that that’s an excellent model for building projects. There will be people who say “but what if I want the same component in two projects but I don’t want to have it on my disk twice?” Ignore these people. Make a component store which works on a project-by-project basis; it’s so much nicer. Clearly there’d need to be a bunch more work on all this: ucs search and ucs submit and ucs remove and a web UI to browse everything and API specifications and server scaling and re-running ucs install after you install a component in case that component itself has dependencies and deciding what happens if two components in the same project have the same dependency and actually paying attention to version numbers and, and, and. There’s a bunch of integration which could be done with the Ubuntu SDK editor: if your app ships with an ubuntu_component_store.json file, then run ucs install when you open it. Ship ucs with the SDK. Automatically add ubuntu_component_store/ to bzr ignore. Provide a graphical browser for the list of components. This is not an implementation: it’s a demo. A real version would need a decent amount of thought.

I don’t know whether this would actually take off. I don’t know whether there are sufficient people developing reusable components for Ubuntu apps to justify it. But I think that, if there are, then this might be a good way for someone to go about it.

  1. fill in a path to the ucs utility wherever you branched it, of course, or put it on your $PATH
  2. from wherever the store says it’s hosted. This RedButton component is on github, mainly because ucs downloads a zip file of the component and github helpfully provides them for you, which Launchpad doesn’t. Note that I think that components should not themselves be uploaded to the store; the store just stores a URL for them.
I'm currently available for hire, to help you plan, architect, and build new systems, and for technical writing and articles. You can take a look at some projects I've worked on and some of my writing. If you'd like to talk about your upcoming project, do get in touch.

More in the discussion (powered by webmentions)

  • Jono Bacon responded at +Stuart Langridge wrote about the notion of an Ubuntu SDK component store, and even went so far as to put together a prototype. I think this is an awe…
  • Jono Bacon responded at +Stuart Langridge wrote about the notion of an Ubuntu SDK component store, and even went so far as to put together a prototype. I think this is an awe…