generated from Exabyte-io/template-definitions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37d4d92
commit 2ecef50
Showing
17 changed files
with
501 additions
and
451 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,3 @@ | |
"@babel/plugin-proposal-class-properties" | ||
] | ||
} | ||
|
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
{ | ||
"all": true, | ||
"include": [ | ||
"src/**/*.js", | ||
"src/**/*.jsx" | ||
] | ||
"extension": [".ts"], | ||
"require": ["ts-node/register"], | ||
"include": ["src/**/*.ts", "src/**/*.tsx"], | ||
"exclude": ["dist"], | ||
"sourceMap": true, | ||
"instrument": true | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,153 +1,142 @@ | ||
// @ts-ignore | ||
// @ts-expect-error application-flavors.js is not typed | ||
import { allApplications, getAppData, getAppTree } from "@exabyte-io/application-flavors.js"; | ||
import { NamedDefaultableHashedInMemoryEntity } from "@exabyte-io/code.js/dist/entity"; | ||
import { type Constructor } from "@exabyte-io/code.js/dist/context"; | ||
|
||
import lodash from "lodash"; | ||
|
||
import { Executable } from "./executable"; | ||
import { getApplicationConfig, getExecutableConfig } from "./tree"; | ||
import { ApplicationConfig, ApplicationData } from "./types"; | ||
|
||
type ApplicationBase = InstanceType<typeof NamedDefaultableHashedInMemoryEntity>; | ||
|
||
// @ts-ignore | ||
export function ApplicationMixin< | ||
T extends Constructor<ApplicationBase> = Constructor<ApplicationBase> | ||
>(superclass: T) { | ||
return class AdeApplication extends superclass { | ||
static Executable = Executable; | ||
|
||
constructor(...args: any[]) { | ||
const config = args[0] as ApplicationConfig; | ||
if (!config || typeof config.name !== "string") throw new Error("Invalid application configuration object."); | ||
const staticConfig = getApplicationConfig(config); | ||
if (!staticConfig) throw new Error(`Application "${config.name} (${config.version}-${config.build})" is not supported.`); | ||
super({ ...staticConfig, ...config }); | ||
} | ||
|
||
// TODO: extract this from application-flavors "global" default config for espresso 5.4.0 | ||
static get defaultConfig() { | ||
return { | ||
name: "espresso", | ||
shortName: "qe", | ||
version: "6.3", | ||
summary: "Quantum Espresso", | ||
build: "Default", | ||
}; | ||
} | ||
|
||
static create(config: { | ||
name: string, | ||
version?: string, | ||
build?: string | ||
}) { | ||
return this.createFromNameVersionBuild(config); | ||
} | ||
|
||
static createFromNameVersionBuild({ | ||
name, | ||
version = undefined, | ||
build = "Default" | ||
}: { | ||
name: string, | ||
version?: string, | ||
build?: string | ||
}) { | ||
return new AdeApplication({ name, version, build }); | ||
} | ||
|
||
getExecutables() { | ||
return this.executables; | ||
} | ||
|
||
getBuilds() { | ||
const data = getAppData(this.prop("name")) as ApplicationData; | ||
const { versions } = data; | ||
const builds = ["Default"]; | ||
versions.map((v) => v.build && builds.push(v.build)); | ||
return lodash.uniq(builds); | ||
} | ||
|
||
getVersions() { | ||
const data = getAppData(this.prop("name")) as ApplicationData; | ||
const { versions } = data; | ||
const these: string[] = versions.map((v) => v.version); | ||
return lodash.uniq(these); | ||
} | ||
|
||
static getUniqueAvailableNames() { | ||
return allApplications; | ||
} | ||
|
||
getExecutableByName(name?: string) { | ||
return new AdeApplication.Executable( | ||
getExecutableConfig({ | ||
appName: this.prop("name"), | ||
execName: name, | ||
}), | ||
); | ||
} | ||
|
||
getExecutableByConfig(config: {name: string} | null | undefined = null) { | ||
return config ? this.getExecutableByName(config.name) : this.defaultExecutable; | ||
} | ||
|
||
get defaultExecutable() { | ||
return this.getExecutableByName(); | ||
} | ||
|
||
// override upon inheritance | ||
// eslint-disable-next-line class-methods-use-this | ||
get allowedModelTypes() { | ||
return []; | ||
} | ||
|
||
get summary() { | ||
return this.prop("summary"); | ||
} | ||
|
||
get version() { | ||
return this.prop("version"); | ||
} | ||
|
||
get build() { | ||
return this.prop("build"); | ||
} | ||
|
||
get shortName() { | ||
return this.prop("shortName", this.prop("name")); | ||
} | ||
|
||
get executables() { | ||
const tree = getAppTree(this.prop("name")); | ||
return Object.keys(tree) | ||
.filter((key) => { | ||
const { supportedApplicationVersions } = tree[key]; | ||
return ( | ||
!supportedApplicationVersions || | ||
supportedApplicationVersions.includes(this.prop("version")) | ||
); | ||
}) | ||
.map((key) => { | ||
return new AdeApplication.Executable({ ...tree[key], name: key }); | ||
}); | ||
} | ||
|
||
get hasAdvancedComputeOptions() { | ||
return this.prop("hasAdvancedComputeOptions"); | ||
} | ||
|
||
get isLicensed() { | ||
return this.prop("isLicensed"); | ||
} | ||
|
||
get isUsingMaterial() { | ||
const materialUsingApplications = ["vasp", "nwchem", "espresso", "exabyteml"]; | ||
return materialUsingApplications.includes(this.name); | ||
} | ||
export class Application extends NamedDefaultableHashedInMemoryEntity { | ||
static Executable = Executable; | ||
|
||
constructor(...args: any[]) { | ||
const config = args[0] as ApplicationConfig; | ||
if (!config || typeof config.name !== "string") throw new Error("Invalid application configuration object."); | ||
const staticConfig = getApplicationConfig(config); | ||
if (!staticConfig) throw new Error(`Application "${config.name} (${config.version}-${config.build})" is not supported.`); | ||
super({ ...staticConfig, ...config }); | ||
} | ||
|
||
// TODO: extract this from application-flavors "global" default config for espresso 5.4.0 | ||
static get defaultConfig() { | ||
return { | ||
name: "espresso", | ||
shortName: "qe", | ||
version: "6.3", | ||
summary: "Quantum Espresso", | ||
build: "Default", | ||
}; | ||
} | ||
|
||
static create(config: { | ||
name: string, | ||
version?: string, | ||
build?: string | ||
}) { | ||
return this.createFromNameVersionBuild(config); | ||
} | ||
|
||
static createFromNameVersionBuild({ | ||
name, | ||
version = undefined, | ||
build = "Default" | ||
}: { | ||
name: string, | ||
version?: string, | ||
build?: string | ||
}) { | ||
return new Application({ name, version, build }); | ||
} | ||
|
||
getExecutables() { | ||
return this.executables; | ||
} | ||
|
||
getBuilds() { | ||
const data = getAppData(this.prop("name")) as ApplicationData; | ||
const { versions } = data; | ||
const builds = ["Default"]; | ||
versions.map((v) => v.build && builds.push(v.build)); | ||
return lodash.uniq(builds); | ||
} | ||
|
||
getVersions() { | ||
const data = getAppData(this.prop("name")) as ApplicationData; | ||
const { versions } = data; | ||
const these: string[] = versions.map((v) => v.version); | ||
return lodash.uniq(these); | ||
} | ||
|
||
static getUniqueAvailableNames() { | ||
return allApplications; | ||
} | ||
|
||
getExecutableByName(name?: string) { | ||
return new Application.Executable( | ||
getExecutableConfig({ | ||
appName: this.prop("name"), | ||
execName: name, | ||
}), | ||
); | ||
} | ||
|
||
getExecutableByConfig(config: {name: string} | null | undefined = null) { | ||
return config ? this.getExecutableByName(config.name) : this.defaultExecutable; | ||
} | ||
} | ||
|
||
export const Application = ApplicationMixin(NamedDefaultableHashedInMemoryEntity); | ||
export type Application = InstanceType<typeof Application>; | ||
get defaultExecutable() { | ||
return this.getExecutableByName(); | ||
} | ||
|
||
// override upon inheritance | ||
// eslint-disable-next-line class-methods-use-this | ||
get allowedModelTypes() { | ||
return []; | ||
} | ||
|
||
get summary() { | ||
return this.prop("summary"); | ||
} | ||
|
||
get version() { | ||
return this.prop("version"); | ||
} | ||
|
||
get build() { | ||
return this.prop("build"); | ||
} | ||
|
||
get shortName() { | ||
return this.prop("shortName", this.prop("name")); | ||
} | ||
|
||
get executables() { | ||
const tree = getAppTree(this.prop("name")); | ||
return Object.keys(tree) | ||
.filter((key) => { | ||
const { supportedApplicationVersions } = tree[key]; | ||
return ( | ||
!supportedApplicationVersions || | ||
supportedApplicationVersions.includes(this.prop("version")) | ||
); | ||
}) | ||
.map((key) => { | ||
return new Application.Executable({ ...tree[key], name: key }); | ||
}); | ||
} | ||
|
||
get hasAdvancedComputeOptions() { | ||
return this.prop("hasAdvancedComputeOptions"); | ||
} | ||
|
||
get isLicensed() { | ||
return this.prop("isLicensed"); | ||
} | ||
|
||
get isUsingMaterial() { | ||
const materialUsingApplications = ["vasp", "nwchem", "espresso", "exabyteml"]; | ||
return materialUsingApplications.includes(this.name); | ||
} | ||
} |
Oops, something went wrong.