Skip to content

Commit

Permalink
Merge branch 'develop' into doc/#625-edit-description-of-LTTB-decimator
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhlongviolin1 authored Dec 22, 2023
2 parents 6ce3d5d + 3f4903b commit ae8c2d7
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 72 deletions.
14 changes: 7 additions & 7 deletions doc/gui/extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ To complete the build of the extension library, we need the following tools:
- [Node.js](https://nodejs.org/en/) 18.0 or higher: a JavaScript runtime.<br/>
This embeds [npm](https://www.npmjs.com/), the Node Package Manager.

The build process needs that you set the environment variable `TAIPY_GUI_DIR` to the location of
the Taipy GUI installation:
The build process needs that you set the environment variable `TAIPY_DIR` to the location of
the Taipy installation:

- If you build from a local copy (a clone, for example) of the
[`taipy-gui` repository](https://github.com/Avaiga/taipy-gui/),
[`taipy` repository](https://github.com/Avaiga/taipy/),
this variable should be set to the path of the directory two levels above the directory where this
README file is located, then down to the "taipy" directory (i.e., the result of the Unix command
"``readlink -f `pwd`/../../taipy``").
- If you are building this extension library example from an installation of Taipy GUI, you can
get that location issuing the command `pip show taipy-gui`.

You can check that the setting is correct by verifying that the directory
"$TAIPY_GUI_DIR/taipy/gui/webapp" exists.
"$TAIPY_DIR/taipy/gui/webapp" exists.

A way to set this variable once and for all for your environment is to add the line:
```
TAIPY_GUI_DIR=<taipy_gui_installation_directory>
TAIPY_DIR=<taipy_installation_directory>
```
to the file `example_library/front-end/.env'. This file, if present, is read by the build process
to initialize the environment variable.
Expand Down Expand Up @@ -143,7 +143,7 @@ changes is.
### Building the JavaScript bundle

When all configuration files have been properly set (which is the case in this example) and
the "TAIPY_GUI_DIR" variable is set, we can build the JavaScript module file:
the "TAIPY_DIR" variable is set, we can build the JavaScript module file:

- Set your directory to `example_library/front-end`
- Install the Taipy GUI JavaScript bundle and the other dependencies:<br/>
Expand All @@ -152,7 +152,7 @@ the "TAIPY_GUI_DIR" variable is set, we can build the JavaScript module file:
npm install
```
This command will fail with a message indicating that the Taipy GUI 'webapp' directory
could not be found if the "TAIPY_GUI_DIR" environment variable was not set properly.
could not be found if the "TAIPY_DIR" environment variable was not set properly.
- You can now build the custom element library JavaScript bundle file:
```
npm run build
Expand Down
63 changes: 41 additions & 22 deletions doc/gui/extension/example_library/front-end/scripts/install.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,52 @@
require("dotenv").config();
const { exec, execSync } = require("child_process");
const { existsSync, writeFileSync, appendFileSync } = require("fs");
const { sep } = require("path");
const { sep, resolve } = require("path");

const getGuiEnv = () =>
execSync(
process.platform === "win32"
? 'pipenv run pip show taipy-gui | findStr "Location:"'
: "pipenv run pip show taipy-gui | grep Location:"
)
.toString()
.trim()
.substring(9)
.trim();
const getGuiEnv = (log = true) => {
try {
const pipGuiDir = execSync(
process.platform === "win32"
? 'pip show taipy-gui | findStr "Location:"'
: "pip show taipy-gui | grep Location:",
{
stdio: ["pipe", "pipe", "pipe"],
}
)
.toString()
.trim();
return pipGuiDir.substring(9).trim();
} catch (e) {
log && console.info("taipy-gui pip package is not installed.");
const base = existsSync("package.json") ? `..${sep}..` : existsSync("frontend") ? "." : sep;
if (existsSync(resolve(base, "taipy", "gui", "webapp", "package.json"))) {
log && console.info(`Found npm package for taipy-gui in ${resolve(base, "taipy", "gui", "webapp")}`);
return base;
} else {
log && console.warn(`taipy-gui npm package should be built locally in ${resolve(base, "taipy", "gui", "webapp")} first.`);
}
}
return sep;
};

let TAIPY_GUI_DIR = process.env.TAIPY_GUI_DIR;
if (!TAIPY_GUI_DIR) {
TAIPY_GUI_DIR = getGuiEnv();
if (existsSync(".env")) {
appendFileSync(".env", `\nTAIPY_GUI_DIR=${TAIPY_GUI_DIR}`);
} else {
writeFileSync(".env", `TAIPY_GUI_DIR=${TAIPY_GUI_DIR}`);
let taipyEnvDir = process.env.TAIPY_DIR;
if (!taipyEnvDir) {
taipyEnvDir = getGuiEnv();
if (taipyEnvDir != sep) {
if (existsSync(".env")) {
appendFileSync(".env", `\nTAIPY_DIR=${taipyEnvDir}`);
} else {
writeFileSync(".env", `TAIPY_DIR=${taipyEnvDir}`);
}
}
}

const taipy_webapp_dir = `${TAIPY_GUI_DIR}${sep}taipy${sep}gui${sep}webapp`;
if (!existsSync(taipy_webapp_dir)) {
const taipyWebappDir = `${taipyEnvDir}${sep}taipy${sep}gui${sep}webapp`;
if (!existsSync(taipyWebappDir)) {
console.error(
`Cannot find the Taipy GUI (${taipy_webapp_dir}) webapp directory.\nMake sure TAIPY_GUI_DIR is set properly as (${getGuiEnv()}).`
`Cannot find the Taipy GUI (${taipyWebappDir}) webapp directory.\nMake sure TAIPY_DIR is set properly as (${getGuiEnv(
false
)}).`
);
process.exit(1);
}
Expand All @@ -37,7 +56,7 @@ let i = 0;

let spinnerTimer;

exec(`npm i ${taipy_webapp_dir}`)
exec(`npm i ${taipyWebappDir}`)
.on("spawn", () => {
spinnerTimer = setInterval(() => {
process.stdout.write("Installing the Taipy GUI library... \r" + spinner[i++]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = (_env, options) => {
// If this file is moved, this path must be updated
manifest: path.resolve(
__dirname,
`${process.env.TAIPY_GUI_DIR}/taipy/gui/webapp/taipy-gui-deps-manifest.json`
`${process.env.TAIPY_DIR}/taipy/gui/webapp/taipy-gui-deps-manifest.json`
),
name: "TaipyGuiDependencies"
}),
Expand Down
4 changes: 2 additions & 2 deletions frontend/taipy-gui/extension-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ The Extension API is located by the 'taipy-gui' module.
In order to import items from this module, you have to install it, using `npm`.
The most simple way to install the Taipy GUI Extension module is:
```
npm i <TAIPY_GUI_DIR>/webapp
npm i <TAIPY_DIR>/taipy/gui/webapp
```

Where *<TAIPY_GUI_DIR>* represents the directory where, in the development machine's
Where *<TAIPY_DIR>* represents the directory where, in the development machine's
filesystem, the Taipy GUI Python package has been installed.

When the package is installed, your JavaScript code can import items from it:
Expand Down
2 changes: 1 addition & 1 deletion frontend/taipy/dev.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
TAIPY_GUI_DIR=<path the taipy package dir parent>
TAIPY_DIR=<path the taipy package dir parent>
95 changes: 59 additions & 36 deletions frontend/taipy/scripts/install.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,73 @@
require("dotenv").config();
const { exec, execSync } = require("child_process");
const { existsSync, writeFileSync, appendFileSync } = require("fs");
const { sep } = require("path");
const { sep, resolve } = require("path");

const getGuiEnv = () =>
execSync(process.platform === "win32" ? 'pip show taipy-gui | findStr "Location:"' : "pip show taipy-gui | grep Location:", {
stdio: ["pipe", "pipe", "pipe"],
})
.toString()
.trim()
.substring(9)
.trim();
const getGuiEnv = (log = true) => {
try {
const pipGuiDir = execSync(
process.platform === "win32"
? 'pip show taipy-gui | findStr "Location:"'
: "pip show taipy-gui | grep Location:",
{
stdio: ["pipe", "pipe", "pipe"],
}
)
.toString()
.trim();
return pipGuiDir.substring(9).trim();
} catch (e) {
log && console.info("taipy-gui pip package is not installed.");
const base = existsSync("package.json") ? `..${sep}..` : existsSync("frontend") ? "." : sep;
if (existsSync(resolve(base, "taipy", "gui", "webapp", "package.json"))) {
log && console.info(`Found npm package for taipy-gui in ${resolve(base, "taipy", "gui", "webapp")}`);
return base;
} else {
log && console.warn(`taipy-gui npm package should be built locally in ${resolve(base, "taipy", "gui", "webapp")} first.`);
}
}
return sep;
};

let TAIPY_GUI_DIR = process.env.TAIPY_GUI_DIR;
if (!TAIPY_GUI_DIR) {
TAIPY_GUI_DIR = getGuiEnv();
if (existsSync(".env")) {
appendFileSync(".env", `\nTAIPY_GUI_DIR=${TAIPY_GUI_DIR}`);
} else {
writeFileSync(".env", `TAIPY_GUI_DIR=${TAIPY_GUI_DIR}`);
}
let taipyEnvDir = process.env.TAIPY_DIR;
if (!taipyEnvDir) {
taipyEnvDir = getGuiEnv();
if (taipyEnvDir != sep) {
if (existsSync(".env")) {
appendFileSync(".env", `\nTAIPY_DIR=${taipyEnvDir}`);
} else {
writeFileSync(".env", `TAIPY_DIR=${taipyEnvDir}`);
}
}
}

const taipy_webapp_dir = `${TAIPY_GUI_DIR}${sep}taipy${sep}gui${sep}webapp`;
if (!existsSync(taipy_webapp_dir)) {
console.error(`Cannot find the Taipy GUI (${taipy_webapp_dir}) webapp directory.\nMake sure TAIPY_GUI_DIR is set properly as (${getGuiEnv()}).`);
process.exit(1);
const taipyWebappDir = `${taipyEnvDir}${sep}taipy${sep}gui${sep}webapp`;
if (!existsSync(taipyWebappDir)) {
console.error(
`Cannot find the Taipy GUI (${taipyWebappDir}) webapp directory.\nMake sure TAIPY_DIR is set properly as (${getGuiEnv(
false
)}).`
);
process.exit(1);
}

const spinner = "|/-\\";
let i = 0;

let spinnerTimer;

exec(`npm i ${taipy_webapp_dir}`)
.on("spawn", () => {
spinnerTimer = setInterval(() => {
process.stdout.write("Installing the Taipy GUI library... \r" + spinner[i++]);
i = i % spinner.length;
}, 150);
})
.on("exit", (code, signal) => {
clearInterval(spinnerTimer);
if (code === 0) {
console.log("\nInstallation finished");
} else {
console.log(`\nInstallation failed (code ${code}, signal ${signal})`);
}
});
exec(`npm i ${taipyWebappDir}`)
.on("spawn", () => {
spinnerTimer = setInterval(() => {
process.stdout.write("Installing the Taipy GUI library... \r" + spinner[i++]);
i = i % spinner.length;
}, 150);
})
.on("exit", (code, signal) => {
clearInterval(spinnerTimer);
if (code === 0) {
console.log("\nInstallation finished");
} else {
console.log(`\nInstallation failed (code ${code}, signal ${signal})`);
}
});
2 changes: 1 addition & 1 deletion frontend/taipy/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = (_env, options) => {
// If this file is moved, this path must be updated
manifest: path.resolve(
__dirname,
`${process.env.TAIPY_GUI_DIR}/taipy/gui/webapp/taipy-gui-deps-manifest.json`
`${process.env.TAIPY_DIR}/taipy/gui/webapp/taipy-gui-deps-manifest.json`
),
name: "TaipyGuiDependencies",
}),
Expand Down
2 changes: 1 addition & 1 deletion tools/frontend/bundle_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def build_taipy(root_path: Path):
env_file_path = root_path / "frontend" / "taipy" / ".env"
if not env_file_path.exists():
with open(env_file_path, "w") as env_file:
env_file.write(f"TAIPY_GUI_DIR={root_path}\n")
env_file.write(f"TAIPY_DIR={root_path}\n")
subprocess.run(["npm", "ci"], cwd=root_path / "frontend" / "taipy", check=True, shell=with_shell)
subprocess.run(["npm", "run", "build"], cwd=root_path / "frontend" / "taipy", check=True, shell=with_shell)

Expand Down
2 changes: 1 addition & 1 deletion tools/packages/taipy/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def run(self):
env_file_path = root_folder / "frontend" / "taipy" / ".env"
if not env_file_path.exists():
with open(env_file_path, "w") as env_file:
env_file.write(f"TAIPY_GUI_DIR={root_folder}\n")
env_file.write(f"TAIPY_DIR={root_folder}\n")
subprocess.run(["npm", "ci"], cwd=root_folder / "frontend" / "taipy", check=True, shell=with_shell)
subprocess.run(
["npm", "run", "build"], cwd=root_folder / "frontend" / "taipy", check=True, shell=with_shell
Expand Down

0 comments on commit ae8c2d7

Please sign in to comment.