Skip to content

Commit

Permalink
Install requirements from viz, telemetry separately
Browse files Browse the repository at this point in the history
Signed-off-by: Nok Lam Chan <[email protected]>
  • Loading branch information
noklam committed Sep 3, 2024
1 parent 6f4fb4b commit f892037
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 17 deletions.
14 changes: 10 additions & 4 deletions bundled/tool/check_consent.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
from kedro_telemetry.plugin import _check_for_telemetry_consent
import logging
# import logging

logger = logging.getLogger(__name__)
# logger = logging.getLogger(__name__)

if __name__ == "__main__":
from pathlib import Path
import sys
import sys

if len(sys.argv) > 1:
path = Path(sys.argv[1])
else:
path = Path.cwd()
consent = _check_for_telemetry_consent(path)
logger.debug(f"Consent for telemetry: {consent}")




# logger.debug(f"Consent for telemetry: {consent}")
print("dummy")
# return "dummy"
47 changes: 47 additions & 0 deletions bundled/tool/install_telemetry_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import subprocess
import sys
from pathlib import Path

def install_dependencies(extension_root_dir):
"""
Install dependencies required for the Kedro extension.
Args:
extension_root_dir (str): The root directory of the extension.
Raises:
ImportError: If the required dependencies are not found.
"""
...
libs_path = Path(extension_root_dir) / "bundled" / "libs"
requirements_path = Path(extension_root_dir) / "kedro-viz-requirements.txt"

try:
import kedro_telemetry
from packaging.version import parse

version = parse(kedro_telemetry.__version__)
if version.major<1 and version.minor<6: # at least >0.6.0
raise ImportError("kedro-telemetry version must be >=0.6.0")
except ImportError:
subprocess.check_call(
[
sys.executable,
"-m",
"pip",
"install",
"-r",
Path(requirements_path),
"-t",
Path(libs_path),
"--no-cache-dir",
"--no-deps"
]
)


if __name__ == "__main__":
if len(sys.argv) > 1:
extension_root_dir = sys.argv[1]
else:
extension_root_dir = None
install_dependencies(extension_root_dir)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def install_dependencies(extension_root_dir):
try:
import fastapi
import orjson
import kedro_telemetry
from packaging.version import parse

except ImportError:
subprocess.check_call(
[
Expand Down
2 changes: 2 additions & 0 deletions kedro-telemetry-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packaging
kedro-telemetry>=0.6.0 # First version that does not prompt for telemetry
2 changes: 1 addition & 1 deletion kedro-viz-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fastapi>=0.100.0,<0.200.0
pydantic>=2.0.0 # In case of FastAPI installs pydantic==1
orjson>=3.9, <4.0
orjson>=3.9, <4.0
40 changes: 33 additions & 7 deletions src/common/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,48 @@ export async function getProjectRoot(): Promise<WorkspaceFolder> {
}

export async function installDependenciesIfNeeded(context: vscode.ExtensionContext): Promise<void> {
// Install necessary dependencies for the flowcharts and telemetry
const alreadyInstalled = context.globalState.get('dependenciesInstalled', false);

if (!alreadyInstalled) {
const pathToScript = 'bundled/tool/install_dependencies.py';
const vizPathToScript = 'bundled/tool/install_viz_dependencies.py';
const telemetryPathToScript = 'bundled/tool/install_telemetry_dependencies.py';
try {
const stdout = await callPythonScript(pathToScript, EXTENSION_ROOT_DIR, context);

const stdoutViz = await callPythonScript(vizPathToScript, EXTENSION_ROOT_DIR, context);
const stdoutTelemetry = await callPythonScript(telemetryPathToScript, EXTENSION_ROOT_DIR, context);
// Check if the script output contains the success message
if (stdout.includes('Successfully installed')) {
context.globalState.update('dependenciesInstalled', true);
traceLog(`Python dependencies installed!`);
console.log('Python dependencies installed!');
if (stdoutViz.includes('Successfully installed')) {
traceLog(`Kedro-viz dependencies installed!`);
console.log('Kedro-viz dependencies installed!');
}
if (stdoutTelemetry.includes('Successfully installed')) {
traceLog(`kedro-telemetry dependencies installed!`);
console.log('kedro-telemetry dependencies installed!');
}
context.globalState.update('dependenciesInstalled', true);
} catch (error) {
traceError(`Failed to install Python dependencies:: ${error}`);
console.error(`Failed to install Python dependencies:: ${error}`);
}
}
}



export async function checkKedroProjectConsent(context: vscode.ExtensionContext): Promise<Boolean> {

const pathToScript = 'bundled/tool/check_consent.py'
try {
const stdout = await callPythonScript(pathToScript, EXTENSION_ROOT_DIR, context);

// Check if the script output contains the success message
if (stdout.includes('true')) {
context.globalState.update('dependenciesInstalled', true);
console.log('Consent from Kedro Project: true !');
}
return true
} catch (error) {
traceError(`Failed to check for telemetry consent:: ${error}`);
}
return false
}
14 changes: 9 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ import { restartServer } from './common/server';
import { checkIfConfigurationChanged, getInterpreterFromSetting } from './common/settings';
import { loadServerDefaults } from './common/setup';
import { createStatusBar } from './common/status_bar';
import { getLSClientTraceLevel, installDependenciesIfNeeded } from './common/utilities';
import { checkKedroProjectConsent, getLSClientTraceLevel, installDependenciesIfNeeded } from './common/utilities';
import { createOutputChannel, onDidChangeConfiguration, registerCommand } from './common/vscodeapi';
import KedroVizPanel from './webview/vizWebView';

let lsClient: LanguageClient | undefined;

export async function activate(context: vscode.ExtensionContext): Promise<void> {
await installDependenciesIfNeeded(context);
await installDependenciesIfNeeded(context, );

// Check for consent in the Kedro Project
const consent = await checkKedroProjectConsent(context);


// This is required to get server name and module. This should be
// the first thing that we do in this extension.
Expand Down Expand Up @@ -109,9 +113,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>

traceError(
'Python interpreter missing:\r\n' +
'[Option 1] Select python interpreter using the ms-python.python.\r\n' +
`[Option 2] Set an interpreter using "${serverId}.interpreter" setting.\r\n` +
'Please use Python 3.8 or greater.',
'[Option 1] Select python interpreter using the ms-python.python.\r\n' +
`[Option 2] Set an interpreter using "${serverId}.interpreter" setting.\r\n` +
'Please use Python 3.8 or greater.',
);
};

Expand Down

0 comments on commit f892037

Please sign in to comment.