-
Notifications
You must be signed in to change notification settings - Fork 380
feat(vscode): .env file into python env #4764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| import { test } from '@playwright/test' | ||
| import fs from 'fs-extra' | ||
| import { | ||
| createVirtualEnvironment, | ||
| openLineageView, | ||
| pipInstall, | ||
| PythonEnvironment, | ||
| REPO_ROOT, | ||
| startVSCode, | ||
| SUSHI_SOURCE_PATH, | ||
| } from './utils' | ||
| import os from 'os' | ||
| import path from 'path' | ||
| import { setTcloudVersion, setupAuthenticatedState } from './tcloud_utils' | ||
|
|
||
| function writeEnvironmentConfig(sushiPath: string) { | ||
| const configPath = path.join(sushiPath, 'config.py') | ||
| const originalConfig = fs.readFileSync(configPath, 'utf8') | ||
|
|
||
| const newConfig = | ||
| ` | ||
| import os | ||
|
|
||
| test_var = os.getenv("TEST_VAR") | ||
| if test_var is None or test_var == "": | ||
| raise Exception("TEST_VAR is not set") | ||
| ` + originalConfig | ||
|
|
||
| fs.writeFileSync(configPath, newConfig) | ||
| } | ||
|
|
||
| async function setupEnvironment(): Promise<[string, PythonEnvironment]> { | ||
| const tempDir = await fs.mkdtemp( | ||
| path.join(os.tmpdir(), 'vscode-test-tcloud-'), | ||
| ) | ||
| await fs.copy(SUSHI_SOURCE_PATH, tempDir) | ||
| const pythonEnvDir = path.join(tempDir, '.venv') | ||
| const pythonDetails = await createVirtualEnvironment(pythonEnvDir) | ||
| const custom_materializations = path.join( | ||
| REPO_ROOT, | ||
| 'examples', | ||
| 'custom_materializations', | ||
| ) | ||
| const sqlmeshWithExtras = `${REPO_ROOT}[bigquery,lsp]` | ||
| await pipInstall(pythonDetails, [sqlmeshWithExtras, custom_materializations]) | ||
|
|
||
| const settings = { | ||
| 'python.defaultInterpreterPath': pythonDetails.pythonPath, | ||
| 'sqlmesh.environmentPath': pythonEnvDir, | ||
| } | ||
| await fs.ensureDir(path.join(tempDir, '.vscode')) | ||
| await fs.writeJson(path.join(tempDir, '.vscode', 'settings.json'), settings, { | ||
| spaces: 2, | ||
| }) | ||
|
|
||
| return [tempDir, pythonDetails] | ||
| } | ||
|
|
||
| test.describe('python environment variable injection on sqlmesh_lsp', () => { | ||
| test('normal setup - error ', async () => { | ||
| const [tempDir, _] = await setupEnvironment() | ||
| writeEnvironmentConfig(tempDir) | ||
| const { window, close } = await startVSCode(tempDir) | ||
| try { | ||
| await openLineageView(window) | ||
| await window.waitForSelector('text=Error creating context') | ||
| } finally { | ||
| await close() | ||
| } | ||
| }) | ||
|
|
||
| test('normal setup - set', async () => { | ||
| const [tempDir, _] = await setupEnvironment() | ||
| writeEnvironmentConfig(tempDir) | ||
| const env_file = path.join(tempDir, '.env') | ||
| fs.writeFileSync(env_file, 'TEST_VAR=test_value') | ||
| const { window, close } = await startVSCode(tempDir) | ||
| try { | ||
| await openLineageView(window) | ||
| await window.waitForSelector('text=Loaded SQLMesh context') | ||
| } finally { | ||
| await close() | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| async function setupTcloudProject( | ||
| tempDir: string, | ||
| pythonDetails: PythonEnvironment, | ||
| ) { | ||
| // Install the mock tcloud package | ||
| const mockTcloudPath = path.join(__dirname, 'tcloud') | ||
| await pipInstall(pythonDetails, [mockTcloudPath]) | ||
|
|
||
| // Create a tcloud.yaml to mark this as a tcloud project | ||
| const tcloudConfig = { | ||
| url: 'https://mock.tobikodata.com', | ||
| org: 'test-org', | ||
| project: 'test-project', | ||
| } | ||
| await fs.writeFile( | ||
| path.join(tempDir, 'tcloud.yaml'), | ||
| `url: ${tcloudConfig.url}\norg: ${tcloudConfig.org}\nproject: ${tcloudConfig.project}\n`, | ||
| ) | ||
| // Write mock ".tcloud_auth_state.json" file | ||
| await setupAuthenticatedState(tempDir) | ||
| // Set tcloud version to 2.10.1 | ||
| await setTcloudVersion(tempDir, '2.10.1') | ||
| } | ||
|
|
||
| test.describe('tcloud version', () => { | ||
| test('normal setup - error ', async () => { | ||
| const [tempDir, pythonDetails] = await setupEnvironment() | ||
| await setupTcloudProject(tempDir, pythonDetails) | ||
| writeEnvironmentConfig(tempDir) | ||
| const { window, close } = await startVSCode(tempDir) | ||
| try { | ||
| await openLineageView(window) | ||
| await window.waitForSelector('text=Error creating context') | ||
| } finally { | ||
| await close() | ||
| } | ||
| }) | ||
|
|
||
| test('normal setup - set', async () => { | ||
| const [tempDir, pythonDetails] = await setupEnvironment() | ||
| await setupTcloudProject(tempDir, pythonDetails) | ||
| writeEnvironmentConfig(tempDir) | ||
| const env_file = path.join(tempDir, '.env') | ||
| fs.writeFileSync(env_file, 'TEST_VAR=test_value') | ||
| const { window, close } = await startVSCode(tempDir) | ||
| try { | ||
| await openLineageView(window) | ||
| await window.waitForSelector('text=Loaded SQLMesh context') | ||
| } finally { | ||
| await close() | ||
| } | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import path from 'path' | ||
| import fs from 'fs-extra' | ||
|
|
||
| /** | ||
| * Helper function to set up a pre-authenticated tcloud state | ||
| */ | ||
| export async function setupAuthenticatedState(tempDir: string): Promise<void> { | ||
| const authStateFile = path.join(tempDir, '.tcloud_auth_state.json') | ||
| const authState = { | ||
| is_logged_in: true, | ||
| id_token: { | ||
| iss: 'https://mock.tobikodata.com', | ||
| aud: 'mock-audience', | ||
| sub: 'user-123', | ||
| scope: 'openid email profile', | ||
| iat: Math.floor(Date.now() / 1000), | ||
| exp: Math.floor(Date.now() / 1000) + 3600, // Valid for 1 hour | ||
| email: 'test@example.com', | ||
| name: 'Test User', | ||
| }, | ||
| } | ||
| await fs.writeJson(authStateFile, authState) | ||
| } | ||
|
|
||
| /** | ||
| * Helper function to set the tcloud version for testing | ||
| */ | ||
| export async function setTcloudVersion( | ||
| tempDir: string, | ||
| version: string, | ||
| ): Promise<void> { | ||
| const versionStateFile = path.join(tempDir, '.tcloud_version_state.json') | ||
| await fs.writeJson(versionStateFile, { version }) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.