67 lines
2.5 KiB
Markdown
67 lines
2.5 KiB
Markdown
---
|
|
title: Packages
|
|
description: >
|
|
Flux source is organized into packages.
|
|
A package consists of one or more source files.
|
|
Each source file is parsed individually and composed into a single package.
|
|
aliases:
|
|
- /influxdb/v2.0/reference/flux/language/programs
|
|
- /influxdb/v2.0/reference/flux/language/packages/
|
|
- /influxdb/cloud/reference/flux/language/packages/
|
|
menu:
|
|
flux_0_x_ref:
|
|
parent: Flux specification
|
|
name: Packages
|
|
weight: 111
|
|
---
|
|
|
|
Flux source code is organized into packages.
|
|
A package consists of one or more source files.
|
|
Each source file is parsed individually and composed into a single package.
|
|
|
|
```js
|
|
File = [ PackageClause ] [ ImportList ] StatementList .
|
|
ImportList = { ImportDeclaration } .
|
|
```
|
|
|
|
## Package clause
|
|
|
|
```js
|
|
PackageClause = "package" identifier .
|
|
```
|
|
|
|
A _package clause_ defines the name for the current package.
|
|
Package names must be valid Flux identifiers.
|
|
The package clause must be at the beginning of any Flux source file.
|
|
All files in the same package must declare the same package name.
|
|
When a file does not declare a package clause, all identifiers in that
|
|
file will belong to the special `main` package.
|
|
|
|
### Package main
|
|
|
|
The `main` package is special for a few reasons:
|
|
|
|
1. It defines the entry point of a Flux program.
|
|
2. It cannot be imported.
|
|
3. All statements are marked as producing side effects.
|
|
|
|
## Package initialization
|
|
|
|
Packages are initialized in the following order:
|
|
|
|
1. All imported packages are initialized and assigned to their package identifier.
|
|
2. All option declarations are evaluated and assigned regardless of order.
|
|
An option cannot have a dependency on another option assigned in the same package block.
|
|
3. All variable declarations are evaluated and assigned regardless of order. A variable cannot have a direct or indirect dependency on itself.
|
|
4. Any package side effects are evaluated.
|
|
|
|
A package will only be initialized once across all file blocks and across all packages blocks regardless of how many times it is imported.
|
|
|
|
Initializing imported packages must be deterministic.
|
|
Specifically after all imported packages are initialized, each option must be assigned the same value.
|
|
Packages imported in the same file block are initialized in declaration order.
|
|
Packages imported across different file blocks have no known order.
|
|
When a set of imports modify the same option, they must be ordered by placing them in the same file block.
|
|
|
|
{{< page-nav prev="/flux/v0.x/spec/operators/" next="/flux/v0.x/spec/statements/" >}}
|