@camstack/types 1.2.599 → 1.2.600

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.600] - 2026-11-19
11
+
12
+ ### Changed
13
+
14
+ - installPythonRequirements accepts exclusiveOf: pip distributions to uninstall before the file is installed
15
+
10
16
  ## [1.2.599] - 2026-11-19
11
17
 
12
18
  ### Added
@@ -22,6 +22,15 @@ export declare function ensurePython(dataDir: string, logger: IScopedLogger): Pr
22
22
  * Install Python packages into the portable Python environment.
23
23
  */
24
24
  export declare function installPythonPackages(pythonPath: string, packages: readonly string[], logger: IScopedLogger): Promise<void>;
25
+ /** Options of {@link installPythonRequirements}. */
26
+ export interface InstallRequirementsOptions {
27
+ /**
28
+ * pip distributions that provide the same module as this file and must not
29
+ * coexist with it. Any of them found installed is uninstalled and the file
30
+ * is installed again, whatever its marker says.
31
+ */
32
+ readonly exclusiveOf?: readonly string[];
33
+ }
25
34
  /**
26
35
  * Install a pip requirements file into the embedded Python.
27
36
  *
@@ -34,4 +43,4 @@ export declare function installPythonPackages(pythonPath: string, packages: read
34
43
  * The marker is updated only after `pip install` succeeds. A failed
35
44
  * install never writes a marker, so the next call retries.
36
45
  */
37
- export declare function installPythonRequirements(pythonPath: string, requirementsFile: string, logger: IScopedLogger): Promise<void>;
46
+ export declare function installPythonRequirements(pythonPath: string, requirementsFile: string, logger: IScopedLogger, options?: InstallRequirementsOptions): Promise<void>;
@@ -127,8 +127,14 @@ export interface IAddonDepsManager {
127
127
  * Idempotent: keyed on (file basename + sha256 of contents). Marker
128
128
  * lives under the python install dir so re-downloading python wipes
129
129
  * everything together.
130
+ *
131
+ * `options.exclusiveOf` names pip distributions that ship the same module
132
+ * (onnxruntime vs onnxruntime-gpu): any found installed is uninstalled and
133
+ * the file is installed again, so a node never holds both.
130
134
  */
131
- installPythonRequirements(requirementsFile: string): Promise<void>;
135
+ installPythonRequirements(requirementsFile: string, options?: {
136
+ readonly exclusiveOf?: readonly string[];
137
+ }): Promise<void>;
132
138
  /** Get the deps directory path */
133
139
  getDepsDir(): string;
134
140
  }
package/dist/node.d.ts CHANGED
@@ -5,7 +5,7 @@ export type { OwnerOnlyDeps } from './util/owner-only-file.js';
5
5
  export { icaclsArgs, mkdirOwnerOnlySync, OwnerOnlyError, restrictDirToOwnerSync, restrictFileToOwnerSync, writeOwnerOnlyFileSync, } from './util/owner-only-file.js';
6
6
  export { FFMPEG_RELEASE, getFfmpegArtifact, getFfmpegDownloadUrl, } from './deps/ffmpeg-artifacts.js';
7
7
  export { probeFfmpegBinary, parseFfmpegCapabilities, type FfmpegBinaryCapabilities, } from './ffmpeg/binary-capabilities.js';
8
- export { ensurePython, getPythonDownloadUrl, installPythonPackages, installPythonRequirements, PYTHON_VERSION, } from './deps/python-downloader.js';
8
+ export { ensurePython, getPythonDownloadUrl, installPythonPackages, installPythonRequirements, PYTHON_VERSION, type InstallRequirementsOptions, } from './deps/python-downloader.js';
9
9
  export { chooseEdgetpuDelegate, declaresEdgetpuDelegate, EDGETPU_DELEGATE_DIRECTIVE, EDGETPU_DELEGATE_RELEASE, EDGETPU_LIB_ENV, edgetpuDelegateFileName, edgetpuLibDir, ensureEdgetpuDelegate, getEdgetpuDelegateArtifact, LEGACY_EDGETPU_LIB, nodeDataRootFromEnv, type EdgetpuDelegateArtifact, type EdgetpuDelegateChoice, type EdgetpuDelegateLookup, type EdgetpuDelegateOrigin, type EdgetpuDelegateResult, type EdgetpuStagedFile, type EnsureEdgetpuDelegateOptions, } from './deps/edgetpu-delegate.js';
10
10
  export { debDataMember, extractDebPayload, installLibraryFromDeb, readArMembers, } from './deps/deb-extract.js';
11
11
  export type { Fmp4FragmentChildArgs, Fmp4FragmentChildDeps, } from './ffmpeg/fmp4-fragment-child.js';
package/dist/node.js CHANGED
@@ -816,6 +816,24 @@ async function installPythonPackages(pythonPath, packages, logger) {
816
816
  throw err;
817
817
  }
818
818
  }
819
+ /** True when `pip show <dist>` finds the distribution in the embedded Python. */
820
+ function isPipDistributionInstalled(pythonPath, dist) {
821
+ try {
822
+ (0, node_child_process.execFileSync)(pythonPath, [
823
+ "-m",
824
+ "pip",
825
+ "show",
826
+ "--disable-pip-version-check",
827
+ dist
828
+ ], {
829
+ stdio: "pipe",
830
+ timeout: 6e4
831
+ });
832
+ return true;
833
+ } catch {
834
+ return false;
835
+ }
836
+ }
819
837
  /**
820
838
  * Install a pip requirements file into the embedded Python.
821
839
  *
@@ -828,20 +846,47 @@ async function installPythonPackages(pythonPath, packages, logger) {
828
846
  * The marker is updated only after `pip install` succeeds. A failed
829
847
  * install never writes a marker, so the next call retries.
830
848
  */
831
- async function installPythonRequirements(pythonPath, requirementsFile, logger) {
849
+ async function installPythonRequirements(pythonPath, requirementsFile, logger, options = {}) {
832
850
  if (!(0, node_fs.existsSync)(requirementsFile)) throw new Error(`Requirements file not found: ${requirementsFile}`);
833
851
  const contents = (0, node_fs.readFileSync)(requirementsFile);
834
852
  const hash = (0, node_crypto.createHash)("sha256").update(contents).digest("hex").slice(0, 16);
835
853
  const fileBase = (0, node_path.basename)(requirementsFile).replace(/\.txt$/i, "");
836
854
  const markerDir = (0, node_path.join)((0, node_path.join)(pythonPath, "..", ".."), ".requirements-installed");
837
855
  const markerPath = (0, node_path.join)(markerDir, `${fileBase}-${hash}.marker`);
838
- if ((0, node_fs.existsSync)(markerPath)) {
856
+ const conflicting = (options.exclusiveOf ?? []).filter((dist) => isPipDistributionInstalled(pythonPath, dist));
857
+ if (conflicting.length === 0 && (0, node_fs.existsSync)(markerPath)) {
839
858
  logger.debug("Python requirements already installed", { meta: {
840
859
  requirementsFile,
841
860
  hash
842
861
  } });
843
862
  return;
844
863
  }
864
+ if (conflicting.length > 0) {
865
+ logger.info("Replacing conflicting Python distributions", { meta: {
866
+ requirementsFile,
867
+ conflicting
868
+ } });
869
+ try {
870
+ (0, node_child_process.execFileSync)(pythonPath, [
871
+ "-m",
872
+ "pip",
873
+ "uninstall",
874
+ "--yes",
875
+ "--disable-pip-version-check",
876
+ ...conflicting
877
+ ], {
878
+ stdio: "pipe",
879
+ timeout: 12e4
880
+ });
881
+ } catch (err) {
882
+ logger.error("Failed to uninstall conflicting Python distributions", { meta: {
883
+ requirementsFile,
884
+ conflicting,
885
+ error: require_composed_stable_id.errMsg(err)
886
+ } });
887
+ throw err;
888
+ }
889
+ }
845
890
  logger.info("Installing Python requirements", { meta: {
846
891
  requirementsFile,
847
892
  hash
@@ -853,6 +898,7 @@ async function installPythonRequirements(pythonPath, requirementsFile, logger) {
853
898
  "install",
854
899
  "--quiet",
855
900
  "--disable-pip-version-check",
901
+ ...conflicting.length > 0 ? ["--force-reinstall"] : [],
856
902
  "-r",
857
903
  requirementsFile
858
904
  ], {
package/dist/node.mjs CHANGED
@@ -793,6 +793,24 @@ async function installPythonPackages(pythonPath, packages, logger) {
793
793
  throw err;
794
794
  }
795
795
  }
796
+ /** True when `pip show <dist>` finds the distribution in the embedded Python. */
797
+ function isPipDistributionInstalled(pythonPath, dist) {
798
+ try {
799
+ execFileSync(pythonPath, [
800
+ "-m",
801
+ "pip",
802
+ "show",
803
+ "--disable-pip-version-check",
804
+ dist
805
+ ], {
806
+ stdio: "pipe",
807
+ timeout: 6e4
808
+ });
809
+ return true;
810
+ } catch {
811
+ return false;
812
+ }
813
+ }
796
814
  /**
797
815
  * Install a pip requirements file into the embedded Python.
798
816
  *
@@ -805,20 +823,47 @@ async function installPythonPackages(pythonPath, packages, logger) {
805
823
  * The marker is updated only after `pip install` succeeds. A failed
806
824
  * install never writes a marker, so the next call retries.
807
825
  */
808
- async function installPythonRequirements(pythonPath, requirementsFile, logger) {
826
+ async function installPythonRequirements(pythonPath, requirementsFile, logger, options = {}) {
809
827
  if (!existsSync(requirementsFile)) throw new Error(`Requirements file not found: ${requirementsFile}`);
810
828
  const contents = readFileSync(requirementsFile);
811
829
  const hash = createHash("sha256").update(contents).digest("hex").slice(0, 16);
812
830
  const fileBase = basename(requirementsFile).replace(/\.txt$/i, "");
813
831
  const markerDir = join(join(pythonPath, "..", ".."), ".requirements-installed");
814
832
  const markerPath = join(markerDir, `${fileBase}-${hash}.marker`);
815
- if (existsSync(markerPath)) {
833
+ const conflicting = (options.exclusiveOf ?? []).filter((dist) => isPipDistributionInstalled(pythonPath, dist));
834
+ if (conflicting.length === 0 && existsSync(markerPath)) {
816
835
  logger.debug("Python requirements already installed", { meta: {
817
836
  requirementsFile,
818
837
  hash
819
838
  } });
820
839
  return;
821
840
  }
841
+ if (conflicting.length > 0) {
842
+ logger.info("Replacing conflicting Python distributions", { meta: {
843
+ requirementsFile,
844
+ conflicting
845
+ } });
846
+ try {
847
+ execFileSync(pythonPath, [
848
+ "-m",
849
+ "pip",
850
+ "uninstall",
851
+ "--yes",
852
+ "--disable-pip-version-check",
853
+ ...conflicting
854
+ ], {
855
+ stdio: "pipe",
856
+ timeout: 12e4
857
+ });
858
+ } catch (err) {
859
+ logger.error("Failed to uninstall conflicting Python distributions", { meta: {
860
+ requirementsFile,
861
+ conflicting,
862
+ error: errMsg(err)
863
+ } });
864
+ throw err;
865
+ }
866
+ }
822
867
  logger.info("Installing Python requirements", { meta: {
823
868
  requirementsFile,
824
869
  hash
@@ -830,6 +875,7 @@ async function installPythonRequirements(pythonPath, requirementsFile, logger) {
830
875
  "install",
831
876
  "--quiet",
832
877
  "--disable-pip-version-check",
878
+ ...conflicting.length > 0 ? ["--force-reinstall"] : [],
833
879
  "-r",
834
880
  requirementsFile
835
881
  ], {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/types",
3
- "version": "1.2.599",
3
+ "version": "1.2.600",
4
4
  "description": "Shared types, interfaces, and model catalogs for the CamStack detection ecosystem",
5
5
  "keywords": [
6
6
  "camstack",