This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
232 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -6,6 +6,7 @@ omit = | |
scripts/uic.py | ||
scripts/designer.py | ||
scripts/qml.py | ||
scripts/lupdate.py | ||
|
||
[report] | ||
fail_under = 100 | ||
|
This file contains 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 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,20 @@ | ||
# pylint: disable=import-error | ||
|
||
import sys | ||
|
||
from utils import is_installed | ||
|
||
if __name__ == "__main__": | ||
if is_installed("PySide6"): | ||
from PySide6.scripts.pyside_tool import lupdate | ||
elif is_installed("PySide2"): | ||
sys.argv[0] = "pyside2-lupdate" | ||
from PySide2.scripts.pyside_tool import main as lupdate | ||
elif is_installed("PyQt6"): | ||
from PyQt6.lupdate.pylupdate import main as lupdate | ||
elif is_installed("PyQt5"): | ||
from PyQt5.pylupdate_main import main as lupdate | ||
else: | ||
sys.exit("No lupdate can be found in current Python environment.") | ||
|
||
sys.exit(lupdate()) |
This file contains 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 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 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 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
File renamed without changes.
File renamed without changes.
This file contains 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,35 @@ | ||
import os | ||
import subprocess | ||
|
||
from tests import ASSETS_DIR, SCRIPTS_DIR | ||
|
||
|
||
def test_lupdate_help(): | ||
result = invoke_lupdate_py(["-help"]) | ||
assert result.returncode == 0 | ||
assert len(result.stdout.decode("utf-8")) > 0 | ||
|
||
|
||
def test_lupdate_sample_py(): | ||
filename = "sample.py" | ||
result = invoke_lupdate_py( | ||
[get_assets_path(filename), "-ts", get_assets_path("sample.ts")] | ||
) | ||
assert result.returncode == 0 | ||
assert len(result.stdout.decode("utf-8")) > 0 | ||
assert os.path.exists(get_assets_path("sample.ts")) | ||
|
||
os.remove(get_assets_path("sample.ts")) | ||
|
||
|
||
def invoke_lupdate_py(args: list[str]): | ||
return subprocess.run( | ||
["poetry", "run", "python", "lupdate.py", *args], | ||
cwd=SCRIPTS_DIR, | ||
capture_output=True, | ||
check=True, | ||
) | ||
|
||
|
||
def get_assets_path(filename: str) -> str: | ||
return os.path.join(ASSETS_DIR, "linguist", filename) |
This file contains 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 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,31 @@ | ||
import { firstValueFrom } from 'rxjs' | ||
import type { CommandDeps } from '../commands' | ||
import { getTargetDocumentUri } from '../commands' | ||
import { run } from '../run' | ||
import { getToolCommand$ } from '../tool-utils' | ||
|
||
export async function lupdate({ extensionUri }: CommandDeps, ...args: any[]) { | ||
const targetDocumentUriResult = getTargetDocumentUri(...args) | ||
|
||
if (targetDocumentUriResult.kind !== 'Success') return targetDocumentUriResult | ||
|
||
const sourceFile = targetDocumentUriResult.value | ||
|
||
const getToolCommandResult = await firstValueFrom( | ||
getToolCommand$({ | ||
tool: 'lupdate', | ||
extensionUri, | ||
resource: sourceFile, | ||
}), | ||
) | ||
|
||
if (getToolCommandResult.kind !== 'Success') return getToolCommandResult | ||
|
||
return run({ | ||
command: [ | ||
...getToolCommandResult.value.command, | ||
sourceFile.fsPath, | ||
...getToolCommandResult.value.options, | ||
], | ||
}) | ||
} |
This file contains 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,71 @@ | ||
import * as assert from 'node:assert' | ||
import * as path from 'node:path' | ||
import { commands, window, workspace } from 'vscode' | ||
import { URI } from 'vscode-uri' | ||
import { EXTENSION_NAMESPACE } from '../../../constants' | ||
import { | ||
E2E_TIMEOUT, | ||
forceDeleteFile, | ||
setupE2EEnvironment, | ||
TEST_ASSETS_PATH, | ||
waitFor, | ||
} from '../test-utils' | ||
|
||
suite('linguist/e2e', () => { | ||
suiteSetup(async function () { | ||
this.timeout(E2E_TIMEOUT) | ||
await setupE2EEnvironment() | ||
}) | ||
|
||
suite('command palette', () => { | ||
suite('when a Python file is open', () => { | ||
const sampleFilenameNoExt = 'sample' | ||
|
||
setup(async function () { | ||
this.timeout(E2E_TIMEOUT) | ||
|
||
await removeGeneratedFile(sampleFilenameNoExt) | ||
|
||
const document = await workspace.openTextDocument( | ||
URI.file( | ||
path.resolve( | ||
TEST_ASSETS_PATH, | ||
'linguist', | ||
`${sampleFilenameNoExt}.py`, | ||
), | ||
), | ||
) | ||
await window.showTextDocument(document) | ||
}) | ||
|
||
teardown(async function () { | ||
this.timeout(E2E_TIMEOUT) | ||
await removeGeneratedFile(sampleFilenameNoExt) | ||
}) | ||
|
||
test('should run lupdate command', async () => { | ||
await commands.executeCommand(`${EXTENSION_NAMESPACE}.lupdate`) | ||
|
||
return waitFor(async () => { | ||
const readResult = await workspace.fs.readFile( | ||
URI.file( | ||
path.resolve( | ||
TEST_ASSETS_PATH, | ||
'linguist', | ||
`${sampleFilenameNoExt}.ts`, | ||
), | ||
), | ||
) | ||
|
||
assert.ok(readResult.byteLength > 0) | ||
}) | ||
}).timeout(E2E_TIMEOUT) | ||
}).timeout(E2E_TIMEOUT) | ||
}).timeout(E2E_TIMEOUT) | ||
}).timeout(E2E_TIMEOUT) | ||
|
||
async function removeGeneratedFile(sampleFilenameNoExt: string) { | ||
return forceDeleteFile( | ||
path.resolve(TEST_ASSETS_PATH, 'linguist', `${sampleFilenameNoExt}.ts`), | ||
) | ||
} |
This file contains 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,12 @@ | ||
import * as assert from 'node:assert' | ||
import { commands } from 'vscode' | ||
import { EXTENSION_NAMESPACE } from '../../../constants' | ||
|
||
suite('lupdate', () => { | ||
test('should include the command', async () => | ||
assert.ok( | ||
(await commands.getCommands(true)).includes( | ||
`${EXTENSION_NAMESPACE}.lupdate`, | ||
), | ||
)) | ||
}) |
This file contains 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
Oops, something went wrong.