-
Notifications
You must be signed in to change notification settings - Fork 19
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
New blog about how to create and publish packages #295
base: main
Are you sure you want to change the base?
Changes from all commits
fca1bf0
7bdd2db
ba52b20
e20fe8d
547cef0
13cba12
715a3fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,136 @@ | ||||||||
--- | ||||||||
slug: packages | ||||||||
title: Guide to Creating and Publishing a Package | ||||||||
authors: [vinzbarbuto] | ||||||||
tags: [packages, packaging, lingua franca, docs] | ||||||||
--- | ||||||||
|
||||||||
The Lingua Franca (LF) [Package Explorer](/docs/tools/code-extension#package-explorer) is a new feature within the Lingua Franca Visual Studio Code extension, built to streamline package management for developers. Supporting both local and remote sources, the Package Explorer enables effortless listing and management of packages—whether defined locally by developers or installed through the Lingo Package Manager. This integration aligns with the Lingua Franca community’s vision for a collaborative and reusable ecosystem. Developers can create and publish their own packages, enabling others to easily incorporate these resources into their projects. This collaborative model not only enhances programmability and accelerates product development but also simplifies the design of complex Lingua Franca applications. | ||||||||
|
||||||||
{/* truncate */} | ||||||||
|
||||||||
In this guide, we’ll walk you through the essential steps to create and publish a package to the community repository, covering: | ||||||||
|
||||||||
1. [**Creating a New Package**](#creating-a-package) | ||||||||
Get started by setting up your package with the required files and directory structure to meet Lingua Franca standards. | ||||||||
|
||||||||
2. [**Configuring the `Lingo.toml` File**](#configuring-the-lingotoml-file) | ||||||||
Set up the `Lingo.toml` configuration to ensure compatibility with the Lingo Package Manager, making your package easy to download and install. | ||||||||
|
||||||||
3. [**Publishing to your (public) repository**](#publishing-a-package) | ||||||||
Learn how to publish your package to share it with the broader community. | ||||||||
|
||||||||
By the end of this guide, you'll have a fully configured, shareable package ready to distribute within the Lingua Franca ecosystem. | ||||||||
|
||||||||
## Creating a New Package | ||||||||
You can create a new [LF package](/docs/glossary/#package) either manually by creating an [LF file](/docs/glossary/#lf-file) or by using the [Lingo Package Manager](https://github.com/lf-lang/lingo). | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
#### Option 1: Create a Project Using the Lingo Package Manager (Recommended) | ||||||||
1. After [installing the Lingo Package Manager](https://www.lf-lang.org/docs/installation#lingo), create an empty directory to serve as the root of your new package. | ||||||||
2. Open the terminal in this folder and run the <kbd>lingo init</kbd> command. | ||||||||
|
||||||||
This will set up a new LF package with the following structure: | ||||||||
|
||||||||
``` | ||||||||
├── . | ||||||||
│ ├── src/ | ||||||||
│ │ └── Main.lf | ||||||||
└── └── Lingo.toml # Configuration file for current package | ||||||||
``` | ||||||||
|
||||||||
#### Option 2: Create a New LF File | ||||||||
edwardalee marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
1. Go to <kbd>File > New File...</kbd> and select `New Lingua Franca File`. | ||||||||
2. Save the file in a directory called `src` to ensure that generated code is placed in a parallel `src-gen` directory. For example, if your file is called `Foo.lf`, the directory structure after building will look like this: | ||||||||
|
||||||||
``` | ||||||||
├── . | ||||||||
│ ├── bin/ | ||||||||
│ │ └── Foo | ||||||||
│ ├── src/ | ||||||||
│ │ └── Foo.lf | ||||||||
│ ├── src-gen/ | ||||||||
│ │ └── Foo/ | ||||||||
... | ||||||||
``` | ||||||||
|
||||||||
If you manually create the `Lingo.toml` file, place it adjacent to the `src` folder in the root directory of the package. This file serves as a configuration for the package, allowing you to specify the package name, version, and other metadata, including any dependencies you want to install. | ||||||||
|
||||||||
### Add `src/lib/` for Local Libraries | ||||||||
|
||||||||
To include local libraries in your Lingua Franca project, create a `lib` directory within the `src/` folder and place your LF files there. These files contain reusable reactors that can be used within the same package or, if published, in other packages via the Lingo Package Manager. The `src/lib` directory is the default location for Lingua Franca files your project exports, enabling other libraries to use them. This setup simplifies managing and reusing libraries across Lingua Franca projects. | ||||||||
|
||||||||
The `lib` directory should be placed alongside the `src` directory, organized as follows: | ||||||||
|
||||||||
``` | ||||||||
├── . | ||||||||
│ ├── src/ | ||||||||
│ │ ├── lib/ | ||||||||
│ │ │ ├── private/ | ||||||||
│ │ │ │ └── AbstractLibraryFile.lf | ||||||||
│ │ │ ├── LibraryFile_1.lf | ||||||||
│ │ │ └── LibraryFile_2.lf | ||||||||
│ │ └── Foo.lf | ||||||||
... | ||||||||
``` | ||||||||
|
||||||||
In LF, there is no visibility control, meaning you cannot mark a reactor or file as `private` as in other programming languages. The `private` directory serves this purpose by containing files meant solely for internal package use. Files in this directory are hidden in the Package Explorer within the VS Code extension, making them inaccessible to other packages. The `private` directory is useful for implementing design patterns like the Abstract Factory Pattern, which provides an interface for creating families of related objects without specifying concrete classes. For example, a developer might define an `AbstractLibraryFile.lf` containing abstract reactors and implement them in various ways within different files under the `lib` directory. | ||||||||
|
||||||||
### Must-Follow Guidelines | ||||||||
|
||||||||
When creating a new package, ensure that you follow these guidelines: | ||||||||
|
||||||||
- **README.md**: Include a `README.md` file in the root directory. This should provide an overview of the package, its purpose, a description of the LF files in the `lib/` folder, and relevant user information. The `README.md` is essential for publishing your package to the community repository and must be kept up to date. | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
- **File Naming**: Use descriptive names for files in the `lib/` directory that reflect their purpose. For example, name a file containing a reactor for different sensors as `Sensor.lf`. | ||||||||
|
||||||||
- **Example LF Files**: Include example LF files in the `src/` directory to demonstrate how to use the reactors in the `lib/` directory. These examples should be well-documented with comments explaining the purpose and usage of each reactor. | ||||||||
|
||||||||
## Configuring the `Lingo.toml` File | ||||||||
|
||||||||
The `Lingo.toml` file is a configuration file that provides essential information about your package, such as its name, version, and dependencies. It ensures that your package is recognized and installed correctly by the Lingo Package Manager. The `Lingo.toml` file should include the following sections: | ||||||||
|
||||||||
- **`[package]`**: Specify the package name, description, and version. | ||||||||
|
||||||||
- **`[lib]`**: Define the package name, the target language used to implement the code, the main reactor (which could be one of the examples from the `src/` directory), and the platform used to build the package. | ||||||||
|
||||||||
Here's an example of a `Lingo.toml` file: | ||||||||
|
||||||||
```toml | ||||||||
[package] | ||||||||
name = "PackageName" | ||||||||
version = "0.3.1" | ||||||||
|
||||||||
[properties] | ||||||||
|
||||||||
[lib] | ||||||||
name = "PackageName" | ||||||||
main = "./src/Main.lf" | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not clear to me what |
||||||||
target = "Python" | ||||||||
platform = "Native" | ||||||||
|
||||||||
[lib.properties] | ||||||||
|
||||||||
[dependencies] | ||||||||
``` | ||||||||
|
||||||||
The `Lingo.toml` can also include additional sections for dependencies and other purpose-specific configurations, however, these are optional and can be added as needed. | ||||||||
|
||||||||
## Publishing a Package | ||||||||
|
||||||||
Publishing your package makes it accessible to other developers, enabling them to discover, install, and use it in their projects. Before publishing, ensure your package is complete and the `Lingo.toml` file is properly configured. | ||||||||
|
||||||||
Follow these steps to publish your package: | ||||||||
|
||||||||
#### 1. Push Your Package to Your GitHub Repository | ||||||||
Upload your package to your own (public) GitHub repository. This allows you to share it immediately. | ||||||||
|
||||||||
#### 2. Follow the `<name>-<target>` Naming Scheme | ||||||||
Name your repository using the format `<name>-<target>`. For example, `package-python`. | ||||||||
- Use lowercase letters and hyphens. | ||||||||
- Ensure `<name>` is descriptive and unique. | ||||||||
- Specify `<target>` as the package's target language. | ||||||||
|
||||||||
#### 3. Add the Maintainer's Name to the Repository Description | ||||||||
This helps others know who to contact for questions or assistance. | ||||||||
|
||||||||
By following these steps, you ensure your package is properly organized and ready for community use. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend against manually setting up a LF project/package.
And a single LF file does not classify as a package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can add
(recommended)
next to Option 1, which involves using Lingo.That’s correct. In fact, there is already a link to the Glossary explaining what an LF file is. However, it serves as the starting point for creating a package, which should include additional elements (there is a definition for LF package too in the Glossary)