Skip to content

Commit

Permalink
fix: eslint issues in src and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
unsigned6 committed Nov 15, 2022
1 parent b8ede55 commit 49e5a43
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 57 deletions.
41 changes: 20 additions & 21 deletions src/application.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
import lodash from "lodash";
import { getAppTree, getAppData, allApplications } from "@exabyte-io/application-flavors.js";
import { allApplications, getAppData, getAppTree } from "@exabyte-io/application-flavors.js";
import { NamedDefaultableInMemoryEntity } from "@exabyte-io/code.js/dist/entity";
import lodash from "lodash";

import { Executable } from "./executable";
import { getApplicationConfig, getExecutableConfig } from "./tree";


export class Application extends NamedDefaultableInMemoryEntity {
static Executable = Executable;

constructor(config) {
const staticConfig = getApplicationConfig(config);
super({...staticConfig, ...config});
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: '5.4.0',
summary: 'Quantum Espresso',
build: 'Default',
}
name: "espresso",
shortName: "qe",
version: "5.4.0",
summary: "Quantum Espresso",
build: "Default",
};
}

static create(config) {
return this.createFromNameVersionBuild(config);
}

static createFromNameVersionBuild({name, version = null, build = "Default"}) {
return new Application({name, version, build});
static createFromNameVersionBuild({ name, version = null, build = "Default" }) {
return new Application({ name, version, build });
}

getExecutables() {
Expand All @@ -39,15 +38,15 @@ export class Application extends NamedDefaultableInMemoryEntity {

getBuilds() {
const data = getAppData(this.prop("name"));
const {versions} = data;
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"));
const {versions} = data;
const { versions } = data;
const these = versions.map((v) => v.version);
return lodash.uniq(these);
}
Expand All @@ -61,7 +60,7 @@ export class Application extends NamedDefaultableInMemoryEntity {
getExecutableConfig({
appName: this.prop("name"),
execName: name,
})
}),
);
}

Expand All @@ -74,8 +73,9 @@ export class Application extends NamedDefaultableInMemoryEntity {
}

// override upon inheritance
// eslint-disable-next-line class-methods-use-this
get allowedModelTypes() {
return []
return [];
}

get summary() {
Expand All @@ -96,11 +96,11 @@ export class Application extends NamedDefaultableInMemoryEntity {

get executables() {
const tree = getAppTree(this.prop("name"));
return Object.keys(tree).map(key => {
return Object.keys(tree).map((key) => {
return new this.constructor.Executable(
Object.assign({}, tree[key], {name: key})
)
})
{ ...tree[key], name: key },
);
});
}

get hasAdvancedComputeOptions() {
Expand All @@ -110,5 +110,4 @@ export class Application extends NamedDefaultableInMemoryEntity {
get isLicensed() {
return this.prop("isLicensed");
}

}
2 changes: 1 addition & 1 deletion src/context.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { NWChemTotalEnergyContextProvider } from "./context/providers/nwchem/providers";
export { QEPWXContextProvider, QENEBContextProvider } from "./context/providers/espresso/providers";
export { VASPContextProvider, VASPNEBContextProvider } from "./context/providers/vasp/providers";
export { ExecutableContextProvider } from "./context/providers"
export { ExecutableContextProvider } from "./context/providers";
2 changes: 1 addition & 1 deletion src/context/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export class ExecutableContextProvider extends ContextProvider {
constructor(config) {
super({
...config,
domain: "executable"
domain: "executable",
});
}
}
1 change: 1 addition & 0 deletions src/context/providers/espresso/providers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-classes-per-file */
import {
JobContextMixin,
MaterialContextMixin,
Expand Down
1 change: 1 addition & 0 deletions src/context/providers/vasp/providers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-classes-per-file */
import {
JobContextMixin,
MaterialContextMixin,
Expand Down
19 changes: 9 additions & 10 deletions src/flavor.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { mix } from "mixwith";
import { NamedDefaultableInMemoryEntity, RuntimeItemsMixin } from "@exabyte-io/code.js/dist/entity";
import { mix } from "mixwith";

import { Template } from "./template";

export class Flavor extends mix(NamedDefaultableInMemoryEntity).with(RuntimeItemsMixin) {

constructor(config) {
super(config);
}

get input() { return this.prop("input", []) }
get input() { return this.prop("input", []); }

// TODO : prevent this from running in client
get inputAsTemplates() {
Expand All @@ -26,8 +22,11 @@ export class Flavor extends mix(NamedDefaultableInMemoryEntity).with(RuntimeItem
});
}

getInputAsRenderedTemplates(context) {return this.inputAsTemplates.map(t => t.getRenderedJSON(context))}

get disableRenderMaterials() {return this.prop("isMultiMaterial", false)}
getInputAsRenderedTemplates(context) {
return this.inputAsTemplates.map((t) => t.getRenderedJSON(context));
}

get disableRenderMaterials() {
return this.prop("isMultiMaterial", false);
}
}
12 changes: 7 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { allApplications, allTemplates, allowedResults, allowedMonitors } from "@exabyte-io/application-flavors.js";
import {
allApplications, allowedMonitors, allowedResults, allTemplates,
} from "@exabyte-io/application-flavors.js";

import { Application } from "./application";
import * as context from "./context";
import { ExecutableContextProvider } from "./context/providers";
import { ContextProviderRegistry } from "./context/registry";
import { Executable } from "./executable";
import { Flavor } from "./flavor";
import { Template } from "./template";
import { getAllApplications, getApplication } from "./tree";
import { ExecutableContextProvider } from "./context/providers";
import * as context from "./context";
import { ContextProviderRegistry } from "./context/registry";

export {
Application,
Expand All @@ -23,4 +25,4 @@ export {
ExecutableContextProvider,
ContextProviderRegistry,
context,
}
};
14 changes: 7 additions & 7 deletions src/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export class Template extends NamedInMemoryEntity {

render(externalContext) {
const renderingContext = this.getRenderingContext(externalContext);
let template, rendered;
let template,
rendered;
if (!this.isManuallyChanged) {
try {
template = jinja.compile(this.content);
Expand Down Expand Up @@ -84,10 +85,9 @@ export class Template extends NamedInMemoryEntity {

static fromFlavor(appName, execName, inputName) {
const filtered = allTemplates.filter(
(temp) =>
temp.applicationName === appName &&
temp.executableName === execName &&
temp.name === inputName,
(temp) => temp.applicationName === appName
&& temp.executableName === execName
&& temp.name === inputName,
);
if (filtered.length !== 1) {
console.log(
Expand All @@ -105,8 +105,8 @@ export class Template extends NamedInMemoryEntity {
getContextProvidersAsClassInstances(providerContext) {
const me = this;
return this.contextProviders.map((p) => {
const { constructor, config } =
me.constructor.providerRegistry.findProviderInstanceByName(p.name);
const { constructor, config } = me.constructor.providerRegistry
.findProviderInstanceByName(p.name);
const clsInstance = new constructor({
...config,
context: providerContext,
Expand Down
29 changes: 18 additions & 11 deletions src/tree.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable new-cap */
import { allApplications, getAppData, getAppTree } from "@exabyte-io/application-flavors.js";

import { getOneMatchFromObject } from "@exabyte-io/code.js/dist/utils";


/**
* @summary Return all applications as both a nested object of Applications and an array of config objects
* @param cls {*} optional class to use to create applications
Expand All @@ -11,11 +10,13 @@ import { getOneMatchFromObject } from "@exabyte-io/code.js/dist/utils";
export function getAllApplications(cls = null) {
const applicationsTree = {};
const applicationsArray = [];
allApplications.map((appName) => {
allApplications.forEach((appName) => {
applicationsTree[appName] = {};
const { versions, defaultVersion, build = "Default", ...appData } = getAppData(appName);
applicationsTree[appName]["defaultVersion"] = defaultVersion;
versions.map((options) => {
const {
versions, defaultVersion, build = "Default", ...appData
} = getAppData(appName);
applicationsTree[appName].defaultVersion = defaultVersion;
versions.forEach((options) => {
const { version } = options;
if (!(version in applicationsTree[appName])) applicationsTree[appName][version] = {};
const config = { ...appData, build, ...options };
Expand All @@ -28,7 +29,7 @@ export function getAllApplications(cls = null) {
}
});
});
return { applicationsTree, applicationsArray }
return { applicationsTree, applicationsArray };
}

/**
Expand All @@ -39,9 +40,12 @@ export function getAllApplications(cls = null) {
* @param build {String} the build to use (optional, defaults to Default)
* @return {*} an application
*/
export function getApplication({ applicationsTree, name, version = null, build = "Default" }) {
export function getApplication({
applicationsTree, name, version = null, build = "Default",
}) {
const app = applicationsTree[name];
if (!version) version = app["defaultVersion"];
// eslint-disable-next-line no-param-reassign
if (!version) version = app.defaultVersion;
return app[version][build];
}

Expand All @@ -55,7 +59,9 @@ const { applicationsTree } = getAllApplications(null);
* @returns {*}
*/
export function getApplicationConfig({ name, version = null, build = "Default" }) {
return getApplication({ applicationsTree, name, version, build });
return getApplication({
applicationsTree, name, version, build,
});
}

/**
Expand All @@ -66,7 +72,7 @@ export function getApplicationConfig({ name, version = null, build = "Default" }
*/
export function getExecutableConfig({ appName, execName }) {
const appTree = getAppTree(appName);
Object.entries(appTree).map(([name, exec]) => { exec.name = name });
Object.entries(appTree).forEach(([name, exec]) => { exec.name = name; });
if (!execName) return getOneMatchFromObject(appTree, "isDefault", true);
return appTree[execName];
}
Expand All @@ -77,6 +83,7 @@ export function getExecutableConfig({ appName, execName }) {
* @param execName
* @param flavorName
*/
// eslint-disable-next-line no-unused-vars
export function getFlavorConfig({ appName, execName, flavorName }) {
// TODO : reduce redundancy of object construction in getting flavors from executable
}
2 changes: 1 addition & 1 deletion tests/setup.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// eslint-disable-next-line no-unused-vars
import chai from "chai";

0 comments on commit 49e5a43

Please sign in to comment.