Skip to content

Commit 442430b

Browse files
committed
feat(project-info): pip (python) project support
1 parent 4f7d805 commit 442430b

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

lib/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,6 @@ export enum CheckType {
111111
export enum ProjectType {
112112
NPM = 'npm',
113113
MAVEN = 'MAVEN',
114+
PIP = 'pip',
114115
REPO = 'repo',
115116
}

lib/services/project.service.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export const isNpmWorkspace = (): boolean => {
1818
return !!findPackageJsonFiles()?.length;
1919
};
2020

21+
export const isPipWorkspace = (): boolean => {
22+
return !!findSetupPyFiles()?.length;
23+
};
24+
2125
export const findProjectNamesNpm = (): string[] => {
2226
return findPackageJsonFiles()
2327
.map((f) => readJson(f)?.name)
@@ -41,6 +45,21 @@ export const findProjectNamesMaven = (): string[] => {
4145
.filter(Boolean);
4246
};
4347

48+
export const findProjectNamesPip = (): string[] => {
49+
return Array.from(
50+
new Set(
51+
findSetupPyFiles()
52+
.map((f) => readFile(f))
53+
.map((content) => /name=\s?"(?<name>.*)"/.exec(content)?.groups?.name!)
54+
.filter(Boolean)
55+
)
56+
);
57+
};
58+
59+
export const findProjectNamesRepo = (): string[] => {
60+
return [currentFolderName()];
61+
};
62+
4463
export const findProjectRepositoriesNpm = () => {
4564
return Array.from(
4665
new Set(
@@ -76,7 +95,7 @@ export const findProjectRepositoriesRepo = (): string[] => {
7695
const gitConfig = readFile(gitConfigPath);
7796
const repoUrl = /url\s?=\s?(?<url>.*)/.exec(gitConfig)?.groups?.url;
7897
if (repoUrl && repoUrl.length) {
79-
return [repoUrl];
98+
return [sanitizeRepositoryUrl(repoUrl)];
8099
} else {
81100
return [];
82101
}
@@ -99,13 +118,18 @@ function findPomXmlFiles() {
99118
);
100119
}
101120

121+
function findSetupPyFiles() {
122+
return findFiles(
123+
'setup.py',
124+
'i',
125+
PROJECT_INFO_TASK_EXCLUDE_PATTERN,
126+
PROJECT_INFO_TASK_PATTERN_FLAGS
127+
);
128+
}
129+
102130
function sanitizeRepositoryUrl(rawUrl: string) {
103131
return rawUrl
104132
.replace('git+', '')
105133
.replace('git@', 'https://')
106134
.replace(/(?<!https?):/gi, '/');
107135
}
108-
109-
export const findProjectNamesRepo = (): string[] => {
110-
return [currentFolderName()];
111-
};

lib/tasks/project-info.task.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import { Context, ProjectType } from '../interface';
44
import {
55
findProjectNamesMaven,
66
findProjectNamesNpm,
7+
findProjectNamesPip,
78
findProjectNamesRepo,
89
findProjectRepositoriesMaven,
910
findProjectRepositoriesNpm,
1011
findProjectRepositoriesRepo,
1112
isMavenWorkspace,
1213
isNpmWorkspace,
14+
isPipWorkspace,
1315
} from '../services/project.service';
1416

1517
export const projectInfoTask: ListrTask = {
@@ -37,6 +39,14 @@ export const projectInfoTask: ListrTask = {
3739
name: names[0],
3840
names,
3941
};
42+
} else if (isPipWorkspace()) {
43+
names = findProjectNamesPip();
44+
ctx.results.name = names[0];
45+
ctx.results.info = {
46+
type: ProjectType.PIP,
47+
name: names[0],
48+
names,
49+
};
4050
} else {
4151
names = findProjectNamesRepo();
4252
ctx.results.name = names[0];

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"start": "node -r ts-node/register lib/index.ts",
1515
"build": "tsc",
1616
"watch": "tsc --watch",
17-
"format": "prettier lib/**/*.{ts,json} --write",
17+
"format:test": "prettier lib/**/*.{ts,json}",
18+
"format:write": "prettier lib/**/*.{ts,json} --write",
1819
"release": "npm run format && npm run build && standard-version -a && git push --follow-tags origin master && npm publish --access public"
1920
},
2021
"dependencies": {

0 commit comments

Comments
 (0)