From 57e7f014a00b351253b89852d42d8d33b5db6173 Mon Sep 17 00:00:00 2001 From: "Edward A. Lee" Date: Tue, 25 Jun 2024 11:25:44 -0700 Subject: [PATCH] Document Python path functions --- docs/reference/target-language-details.mdx | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/docs/reference/target-language-details.mdx b/docs/reference/target-language-details.mdx index 129b8cbc1..02a59a75c 100644 --- a/docs/reference/target-language-details.mdx +++ b/docs/reference/target-language-details.mdx @@ -2916,9 +2916,29 @@ FIXME: Details needed here. -:::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(); + =} +} +```