From 37c127779852be9452d046d0035c52c767c4b5fa Mon Sep 17 00:00:00 2001 From: Simon Sawicki Date: Sat, 27 Sep 2025 17:56:19 +0200 Subject: [PATCH] Namespace packages --- pyproject.toml | 5 ++--- rollup.config.js | 14 +++++++------- run.ts | 2 +- src/{ => yt/solver}/dynamic.lib.ts | 0 src/{ => yt/solver}/lib.ts | 0 src/{ => yt/solver}/main.ts | 2 +- src/{ => yt/solver}/n.ts | 4 ++-- src/{ => yt/solver}/setup.ts | 0 src/{ => yt/solver}/sig.ts | 4 ++-- src/{ => yt/solver}/solvers.test.ts | 6 +++--- src/{ => yt/solver}/solvers.ts | 0 {tests => src/yt/solver/test}/download.ts | 0 {tests => src/yt/solver/test}/io.ts | 0 .../yt/solver/test}/players/.gitignore | 0 {tests => src/yt/solver/test}/tests.ts | 2 +- {tests => src/yt/solver/test}/utils.ts | 2 +- yt_dlp_ejs/__init__.py | 19 ------------------- yt_dlp_ejs/yt/__init__.py | 0 yt_dlp_ejs/yt/solver/__init__.py | 17 +++++++++++++++++ 19 files changed, 37 insertions(+), 40 deletions(-) rename src/{ => yt/solver}/dynamic.lib.ts (100%) rename src/{ => yt/solver}/lib.ts (100%) rename src/{ => yt/solver}/main.ts (97%) rename src/{ => yt/solver}/n.ts (96%) rename src/{ => yt/solver}/setup.ts (100%) rename src/{ => yt/solver}/sig.ts (97%) rename src/{ => yt/solver}/solvers.test.ts (83%) rename src/{ => yt/solver}/solvers.ts (100%) rename {tests => src/yt/solver/test}/download.ts (100%) rename {tests => src/yt/solver/test}/io.ts (100%) rename {tests => src/yt/solver/test}/players/.gitignore (100%) rename {tests => src/yt/solver/test}/tests.ts (99%) rename {tests => src/yt/solver/test}/utils.ts (64%) create mode 100644 yt_dlp_ejs/yt/__init__.py create mode 100644 yt_dlp_ejs/yt/solver/__init__.py diff --git a/pyproject.toml b/pyproject.toml index 8127694..670bf92 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,5 @@ commands = [ ] [tool.hatch.build.targets.wheel.force-include] -"dist/yt.solver.core.min.js" = "yt_dlp_ejs/yt.solver.core.min.js" -"dist/yt.solver.lib.min.js" = "yt_dlp_ejs/yt.solver.lib.min.js" - +"dist/yt.solver.core.min.js" = "yt_dlp_ejs/yt/solver/core.min.js" +"dist/yt.solver.lib.min.js" = "yt_dlp_ejs/yt/solver/lib.min.js" diff --git a/rollup.config.js b/rollup.config.js index cc752ae..4a90b12 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -83,7 +83,7 @@ function prettifyOutput() { export default defineConfig([ { - input: "src/main.ts", + input: "src/yt/solver/main.ts", output: { name: "jsc", globals: { @@ -119,7 +119,7 @@ export default defineConfig([ ], }, { - input: "src/main.ts", + input: "src/yt/solver/main.ts", output: { name: "jsc", globals: { @@ -153,7 +153,7 @@ export default defineConfig([ ], }, { - input: "src/lib.ts", + input: "src/yt/solver/lib.ts", output: { name: "lib", file: "dist/yt.solver.lib.js", @@ -184,7 +184,7 @@ export default defineConfig([ ], }, { - input: "src/lib.ts", + input: "src/yt/solver/lib.ts", output: { name: "lib", file: "dist/yt.solver.lib.min.js", @@ -212,14 +212,14 @@ export default defineConfig([ ], }, { - input: "src/dynamic.lib.ts", + input: "src/yt/solver/dynamic.lib.ts", output: { name: "lib", file: "dist/yt.solver.deno.lib.js", format: "es", }, plugins: [ - dynamicImportRewrite({ format: "deno" }), + dynamicImportRewrite(), license({ banner: { content: LICENSE_BANNER, @@ -238,7 +238,7 @@ export default defineConfig([ ], }, { - input: "src/dynamic.lib.ts", + input: "src/yt/solver/dynamic.lib.ts", output: { name: "lib", file: "dist/yt.solver.bun.lib.js", diff --git a/run.ts b/run.ts index 5b967ab..37bb48f 100644 --- a/run.ts +++ b/run.ts @@ -2,7 +2,7 @@ import { argv, exit } from "node:process"; import { readFileSync } from "node:fs"; import { isOneOf } from "./src/utils.ts"; -import main from "./src/main.ts"; +import main from "./src/yt/solver/main.ts"; const args = argv.slice(2); if (args.length < 2) { diff --git a/src/dynamic.lib.ts b/src/yt/solver/dynamic.lib.ts similarity index 100% rename from src/dynamic.lib.ts rename to src/yt/solver/dynamic.lib.ts diff --git a/src/lib.ts b/src/yt/solver/lib.ts similarity index 100% rename from src/lib.ts rename to src/yt/solver/lib.ts diff --git a/src/main.ts b/src/yt/solver/main.ts similarity index 97% rename from src/main.ts rename to src/yt/solver/main.ts index cbe94c8..6de8219 100644 --- a/src/main.ts +++ b/src/yt/solver/main.ts @@ -1,5 +1,5 @@ import { getFromPrepared, preprocessPlayer } from "./solvers.ts"; -import { isOneOf } from "./utils.ts"; +import { isOneOf } from "../../utils.ts"; export default function main(input: Input): Output { const preprocessedPlayer = diff --git a/src/n.ts b/src/yt/solver/n.ts similarity index 96% rename from src/n.ts rename to src/yt/solver/n.ts index 7491f03..94e6a7e 100644 --- a/src/n.ts +++ b/src/yt/solver/n.ts @@ -1,6 +1,6 @@ import { type ESTree } from "meriyah"; -import { matchesStructure } from "./utils.ts"; -import { type DeepPartial } from "./types.ts"; +import { matchesStructure } from "../../utils.ts"; +import { type DeepPartial } from "../../types.ts"; const identifier: DeepPartial = { type: "VariableDeclaration", diff --git a/src/setup.ts b/src/yt/solver/setup.ts similarity index 100% rename from src/setup.ts rename to src/yt/solver/setup.ts diff --git a/src/sig.ts b/src/yt/solver/sig.ts similarity index 97% rename from src/sig.ts rename to src/yt/solver/sig.ts index 0a6b4ab..595b586 100644 --- a/src/sig.ts +++ b/src/yt/solver/sig.ts @@ -1,6 +1,6 @@ import { type ESTree } from "meriyah"; -import { matchesStructure } from "./utils.ts"; -import { type DeepPartial } from "./types.ts"; +import { matchesStructure } from "../../utils.ts"; +import { type DeepPartial } from "../../types.ts"; const logicalExpression: DeepPartial = { type: "ExpressionStatement", diff --git a/src/solvers.test.ts b/src/yt/solver/solvers.test.ts similarity index 83% rename from src/solvers.test.ts rename to src/yt/solver/solvers.test.ts index 3e1c863..70c3c33 100644 --- a/src/solvers.test.ts +++ b/src/yt/solver/solvers.test.ts @@ -1,7 +1,7 @@ import { getFromPrepared, preprocessPlayer } from "./solvers.ts"; -import { players, tests } from "../tests/tests.ts"; -import { getCachePath } from "../tests/utils.ts"; -import { getIO } from "../tests/io.ts"; +import { players, tests } from "./test/tests.ts"; +import { getCachePath } from "./test/utils.ts"; +import { getIO } from "./test/io.ts"; const io = await getIO(); diff --git a/src/solvers.ts b/src/yt/solver/solvers.ts similarity index 100% rename from src/solvers.ts rename to src/yt/solver/solvers.ts diff --git a/tests/download.ts b/src/yt/solver/test/download.ts similarity index 100% rename from tests/download.ts rename to src/yt/solver/test/download.ts diff --git a/tests/io.ts b/src/yt/solver/test/io.ts similarity index 100% rename from tests/io.ts rename to src/yt/solver/test/io.ts diff --git a/tests/players/.gitignore b/src/yt/solver/test/players/.gitignore similarity index 100% rename from tests/players/.gitignore rename to src/yt/solver/test/players/.gitignore diff --git a/tests/tests.ts b/src/yt/solver/test/tests.ts similarity index 99% rename from tests/tests.ts rename to src/yt/solver/test/tests.ts index be6315b..22a7211 100644 --- a/tests/tests.ts +++ b/src/yt/solver/test/tests.ts @@ -247,7 +247,7 @@ export const tests: { input: "MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJA", expected: - "-MGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKnMznQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJA", + "-MGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKnMznQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJ", }, ], }, diff --git a/tests/utils.ts b/src/yt/solver/test/utils.ts similarity index 64% rename from tests/utils.ts rename to src/yt/solver/test/utils.ts index 5f59591..95e8733 100644 --- a/tests/utils.ts +++ b/src/yt/solver/test/utils.ts @@ -1,5 +1,5 @@ import { type Variant } from "./tests.ts"; export function getCachePath(player: string, variant: Variant) { - return `tests/players/${player}-${variant}`; + return `src/yt/solver/test/players/${player}-${variant}`; } diff --git a/yt_dlp_ejs/__init__.py b/yt_dlp_ejs/__init__.py index a4c6a7e..4b53065 100644 --- a/yt_dlp_ejs/__init__.py +++ b/yt_dlp_ejs/__init__.py @@ -1,25 +1,6 @@ -import importlib.resources - -import yt_dlp_ejs -# XXX: this reflects package version from yt_dlp_ejs._version import version -def yt_solver_core() -> str: - """ - Read the contents of the JavaScript core solver bundle as string. - """ - return importlib.resources.read_text(yt_dlp_ejs, 'yt.solver.core.min.js') - - -def yt_solver_lib() -> str: - """ - Read the contents of the JavaScript library solver bundle as string. - """ - return importlib.resources.read_text(yt_dlp_ejs, 'yt.solver.lib.min.js') - __all__ = [ - "core", - "lib", "version", ] diff --git a/yt_dlp_ejs/yt/__init__.py b/yt_dlp_ejs/yt/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/yt_dlp_ejs/yt/solver/__init__.py b/yt_dlp_ejs/yt/solver/__init__.py new file mode 100644 index 0000000..9fc4405 --- /dev/null +++ b/yt_dlp_ejs/yt/solver/__init__.py @@ -0,0 +1,17 @@ +import importlib + +import yt_dlp_ejs.yt.solver + + +def core() -> str: + """ + Read the contents of the JavaScript core solver bundle as string. + """ + return importlib.resources.read_text(yt_dlp_ejs.yt.solver, "core.min.js") + + +def lib() -> str: + """ + Read the contents of the JavaScript library solver bundle as string. + """ + return importlib.resources.read_text(yt_dlp_ejs.yt.solver, "lib.min.js")