Skip to content

Commit

Permalink
Process PEP440 versions
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Apr 12, 2024
1 parent fd284f8 commit 93568ec
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dictionary
Submodule dictionary updated 1 files
+1 −0 libraries.txt
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
"hooks": "git config core.hooksPath .githooks || true",
"no-hooks": "git config core.hooksPath .git/hooks",
"prepare": "yarn hooks"
},
"dependencies": {
"semver": "^7.6.0"
}
}
1 change: 1 addition & 0 deletions typescript/base/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {
"error",
"separate-lines"
],
"no-warning-comments": ["warn"],
"object-curly-spacing": [
"error",
"always"
Expand Down
1 change: 1 addition & 0 deletions typescript/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"types": "lib/index.d.ts",
"version": "1.0.1",
"dependencies": {
"@renovatebot/pep440": "^3.0.19",
"axios": "^1.4.0"
}
}
51 changes: 48 additions & 3 deletions typescript/base/src/instance.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import * as semver from "semver";
import {
ContractAddress,
ContractName,
MainContractAddress,
SkaleABIFile
} from "./domain/types";
import { parse, stringify } from "@renovatebot/pep440/lib/version";
import { Pep440Version } from "@renovatebot/pep440";
import { Project } from "./project";

export type InstanceData = {
Expand All @@ -27,6 +30,40 @@ const defaultVersionAbi = [
}
];

const processSemver = (semVersion: semver.SemVer) => {
if (!semVersion.prerelease.length) {
const defaultPrerelease = 0;
semVersion.prerelease = [
"stable",
defaultPrerelease
];
}
return semVersion.format();
};

const processPep440 = (pyVersion: Pep440Version) => {
const replaceMap = new Map<string, string>([
[
"a",
"develop"
],
[
"b",
"beta"
]
]);
pyVersion.pre = pyVersion.pre.map((value: string | number) => {
if (typeof value === "string" && replaceMap.has(value)) {
return `-${replaceMap.get(value)!}.`;
}
return value;
});
// TODO: remove any after the fix in the @renovatebot/pep440 library

Check warning on line 61 in typescript/base/src/instance.ts

View workflow job for this annotation

GitHub Actions / typescript (16)

Unexpected 'todo' comment: 'TODO: remove any after the fix in the...'

Check warning on line 61 in typescript/base/src/instance.ts

View workflow job for this annotation

GitHub Actions / typescript (18)

Unexpected 'todo' comment: 'TODO: remove any after the fix in the...'

Check warning on line 61 in typescript/base/src/instance.ts

View workflow job for this annotation

GitHub Actions / typescript (20)

Unexpected 'todo' comment: 'TODO: remove any after the fix in the...'

Check warning on line 61 in typescript/base/src/instance.ts

View workflow job for this annotation

GitHub Actions / typescript (19)

Unexpected 'todo' comment: 'TODO: remove any after the fix in the...'

Check warning on line 61 in typescript/base/src/instance.ts

View workflow job for this annotation

GitHub Actions / typescript (16)

Unexpected 'todo' comment: 'TODO: remove any after the fix in the...'

Check warning on line 61 in typescript/base/src/instance.ts

View workflow job for this annotation

GitHub Actions / typescript (20)

Unexpected 'todo' comment: 'TODO: remove any after the fix in the...'

Check warning on line 61 in typescript/base/src/instance.ts

View workflow job for this annotation

GitHub Actions / typescript (18)

Unexpected 'todo' comment: 'TODO: remove any after the fix in the...'

Check warning on line 61 in typescript/base/src/instance.ts

View workflow job for this annotation

GitHub Actions / typescript (19)

Unexpected 'todo' comment: 'TODO: remove any after the fix in the...'
// https://github.com/renovatebot/pep440/pull/555
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return stringify(pyVersion as any)!;
};

export abstract class Instance<ContractType> {
protected project: Project<ContractType>;

Expand Down Expand Up @@ -87,9 +124,17 @@ export abstract class Instance<ContractType> {

private async getVersion () {
if (typeof this.version === "undefined") {
this.version = await this.queryVersion();
if (!this.version.includes("-")) {
this.version = `${this.version}-stable.0`;
const rawVersion = await this.queryVersion();
const semVersion = semver.parse(rawVersion);
if (semVersion) {
this.version = processSemver(semVersion);
} else {
const pyVersion = parse(rawVersion);
if (pyVersion) {
this.version = processPep440(pyVersion);
} else {
throw new Error(`Can't parse version ${rawVersion}`);
}
}
}
return this.version;
Expand Down
3 changes: 3 additions & 0 deletions typescript/base/src/projects/ima/schain/SchainImaInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export class SchainImaInstance<ContractType> extends
]);

getContractAddress (name: string): Promise<string> {
if (name === "MessageProxyForSchain") {
return Promise.resolve(this.address);
}
if (SchainImaInstance.PREDEPLOYED.has(name)) {
return Promise.resolve(SchainImaInstance.PREDEPLOYED.
get(name) as string);
Expand Down
8 changes: 8 additions & 0 deletions typescript/base/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,18 @@ __metadata:
languageName: node
linkType: hard

"@renovatebot/pep440@npm:^3.0.19":
version: 3.0.19
resolution: "@renovatebot/pep440@npm:3.0.19"
checksum: d4465f4bec8fe231ac5428c6ed1b9844508b0e0357eeb69818ce24a373faf41dbc2d2b60b2af474bf997aea918aaadb4d75ea005bfa6358deef9a5652f53d141
languageName: node
linkType: hard

"@skalenetwork/skale-contracts@workspace:.":
version: 0.0.0-use.local
resolution: "@skalenetwork/skale-contracts@workspace:."
dependencies:
"@renovatebot/pep440": ^3.0.19
"@tsconfig/recommended": ^1.0.2
"@types/node": ^20.2.5
"@typescript-eslint/eslint-plugin": ^6.0.0
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ __metadata:
resolution: "development@workspace:."
dependencies:
cspell: ^6.31.1
semver: ^7.6.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -1371,6 +1372,17 @@ __metadata:
languageName: node
linkType: hard

"semver@npm:^7.6.0":
version: 7.6.0
resolution: "semver@npm:7.6.0"
dependencies:
lru-cache: ^6.0.0
bin:
semver: bin/semver.js
checksum: 7427f05b70786c696640edc29fdd4bc33b2acf3bbe1740b955029044f80575fc664e1a512e4113c3af21e767154a94b4aa214bf6cd6e42a1f6dba5914e0b208c
languageName: node
linkType: hard

"signal-exit@npm:^3.0.2":
version: 3.0.7
resolution: "signal-exit@npm:3.0.7"
Expand Down

0 comments on commit 93568ec

Please sign in to comment.