Skip to content

Commit

Permalink
Merge pull request #269 from lf-lang/python-paths
Browse files Browse the repository at this point in the history
Document Python path functions
  • Loading branch information
lhstrh authored Aug 3, 2024
2 parents 504e9db + 57e7f01 commit ea0b763
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions docs/reference/target-language-details.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2916,9 +2916,29 @@ FIXME: Details needed here.
</ShowIf>
<ShowIf py>

:::warning
FIXME: Details needed here.
:::
A few utility libraries are provided.

- **File Access**

- `lf.source_directory()`: Returns a string giving the full path to the directory containing the `.lf` file of the program.
- `lf.package_directory()`: Returns a string giving the full path to the directory that is the root of the project or package (normally, the directory above the `src` directory).

The above can be used to find supporting files, as shown in the following example:

```lf-py
target Python
preamble {=
import os
=}
main reactor {
state source_path = {= os.path.join(lf.source_directory(), "PythonPaths.lf") =}
reaction(startup) {=
file = open(self.source_path, "r");
print(file.read());
file.close();
=}
}
```

</ShowIf>
<ShowIf ts>
Expand Down

0 comments on commit ea0b763

Please sign in to comment.