Skip to content

Commit 900441a

Browse files
committed
feat: Added python tools
1 parent 8c6d7b1 commit 900441a

7 files changed

Lines changed: 230 additions & 5 deletions

File tree

src/resources/python/pip-sync/pip-sync.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CreatePlan, DestroyPlan, getPty, RefreshContext, Resource, ResourceSettings } from '@codifycli/plugin-core';
1+
import { CreatePlan, DestroyPlan, ExampleConfig, getPty, RefreshContext, Resource, ResourceSettings } from '@codifycli/plugin-core';
22
import { OS, ResourceConfig } from '@codifycli/schemas';
33

44
import schema from './pip-sync-schema.json'
@@ -10,10 +10,30 @@ export interface PipSyncConfig extends ResourceConfig {
1010
cwd?: string;
1111
}
1212

13+
const defaultConfig: Partial<PipSyncConfig> = {
14+
requirementFiles: ['requirements.txt'],
15+
cwd: '<Replace me here!>'
16+
}
17+
18+
const exampleWithVirtualenv: ExampleConfig = {
19+
title: 'Sync packages into a virtualenv',
20+
description: 'Install pip-tools and sync dependencies from a compiled requirements file into a dedicated virtualenv.',
21+
configs: [{
22+
type: 'pip-sync',
23+
requirementFiles: ['requirements.txt'],
24+
virtualEnv: '.venv',
25+
cwd: '<Replace me here!>',
26+
}]
27+
}
28+
1329
export class PipSync extends Resource<PipSyncConfig> {
1430
getSettings(): ResourceSettings<PipSyncConfig> {
1531
return {
1632
id: 'pip-sync',
33+
defaultConfig,
34+
exampleConfigs: {
35+
example1: exampleWithVirtualenv,
36+
},
1737
operatingSystems: [OS.Darwin, OS.Linux],
1838
schema,
1939
parameterSettings: {

src/resources/python/pip/pip.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
CreatePlan,
33
DestroyPlan,
4+
ExampleConfig,
45
ModifyPlan,
56
ParameterChange,
67
Resource,
@@ -23,11 +24,55 @@ export interface PipResourceConfig extends ResourceConfig {
2324
virtualEnv?: string;
2425
}
2526

27+
const defaultConfig: Partial<PipResourceConfig> = {
28+
install: [],
29+
installFiles: [],
30+
}
31+
32+
const exampleBasic: ExampleConfig = {
33+
title: 'Install packages with pip',
34+
description: 'Install a set of Python packages globally using pip.',
35+
configs: [{
36+
type: 'pip',
37+
install: ['requests', 'boto3', 'click'],
38+
}]
39+
}
40+
41+
const exampleWithPyenvAndVirtualenv: ExampleConfig = {
42+
title: 'Full Python setup with pyenv, virtualenv, and pip',
43+
description: 'Install Python via pyenv, create a project virtualenv, then install packages into it with pip.',
44+
configs: [
45+
{
46+
type: 'pyenv',
47+
pythonVersions: ['3.12'],
48+
global: '3.12',
49+
},
50+
{
51+
type: 'virtualenv-project',
52+
dest: '.venv',
53+
cwd: '<Replace me here!>',
54+
automaticallyInstallRequirementsTxt: false,
55+
dependsOn: ['pyenv'],
56+
},
57+
{
58+
type: 'pip',
59+
install: ['requests', 'boto3', 'click'],
60+
virtualEnv: '.venv',
61+
dependsOn: ['virtualenv-project'],
62+
},
63+
]
64+
}
65+
2666
export class Pip extends Resource<PipResourceConfig> {
2767

2868
getSettings(): ResourceSettings<PipResourceConfig> {
2969
return {
3070
id: 'pip',
71+
defaultConfig,
72+
exampleConfigs: {
73+
example1: exampleBasic,
74+
example2: exampleWithPyenvAndVirtualenv,
75+
},
3176
operatingSystems: [OS.Darwin, OS.Linux],
3277
schema,
3378
parameterSettings: {

src/resources/python/pyenv/pyenv.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getPty, Resource, ResourceSettings, SpawnStatus, Utils } from '@codifycli/plugin-core';
1+
import { ExampleConfig, getPty, Resource, ResourceSettings, SpawnStatus, Utils } from '@codifycli/plugin-core';
22
import { OS, ResourceConfig } from '@codifycli/schemas';
33
import * as fs from 'node:fs';
44
import os from 'node:os';
@@ -15,10 +15,39 @@ export interface PyenvConfig extends ResourceConfig {
1515
// TODO: Add option here to use homebrew to install instead. Default to true. Maybe add option to set default values to resource config.
1616
}
1717

18+
const defaultConfig: Partial<PyenvConfig> = {
19+
pythonVersions: [],
20+
}
21+
22+
const exampleBasic: ExampleConfig = {
23+
title: 'Install pyenv with a Python version',
24+
description: 'Install pyenv and pin a Python version as the global default.',
25+
configs: [{
26+
type: 'pyenv',
27+
pythonVersions: ['3.12'],
28+
global: '3.12',
29+
}]
30+
}
31+
32+
const exampleMultiVersion: ExampleConfig = {
33+
title: 'Install pyenv with multiple Python versions',
34+
description: 'Install pyenv with several Python versions available, pinning one as the global default.',
35+
configs: [{
36+
type: 'pyenv',
37+
pythonVersions: ['3.12', '3.11', '3.10'],
38+
global: '3.12',
39+
}]
40+
}
41+
1842
export class PyenvResource extends Resource<PyenvConfig> {
1943
getSettings(): ResourceSettings<PyenvConfig> {
2044
return {
2145
id: 'pyenv',
46+
defaultConfig,
47+
exampleConfigs: {
48+
example1: exampleBasic,
49+
example2: exampleMultiVersion,
50+
},
2251
operatingSystems: [OS.Darwin, OS.Linux],
2352
schema: Schema,
2453
parameterSettings: {

src/resources/python/uv/uv.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FileUtils, getPty, Resource, ResourceSettings, SpawnStatus, z } from '@codifycli/plugin-core';
1+
import { ExampleConfig, FileUtils, getPty, Resource, ResourceSettings, SpawnStatus, z } from '@codifycli/plugin-core';
22
import { OS } from '@codifycli/schemas';
33
import fs from 'node:fs/promises';
44
import os from 'node:os';
@@ -26,10 +26,39 @@ const schema = z.object({
2626

2727
export type UvConfig = z.infer<typeof schema>;
2828

29+
const defaultConfig: Partial<UvConfig> = {
30+
pythonVersions: [],
31+
tools: [],
32+
}
33+
34+
const examplePython: ExampleConfig = {
35+
title: 'Install uv with Python versions',
36+
description: 'Install uv and pin one or more Python versions for use across projects.',
37+
configs: [{
38+
type: 'uv',
39+
pythonVersions: ['3.12', '3.11'],
40+
}]
41+
}
42+
43+
const exampleWithTools: ExampleConfig = {
44+
title: 'Install uv with Python and global tools',
45+
description: 'Install uv, pin a Python version, and install commonly used global CLI tools like ruff and black.',
46+
configs: [{
47+
type: 'uv',
48+
pythonVersions: ['3.12'],
49+
tools: ['ruff', 'black', 'httpie'],
50+
}]
51+
}
52+
2953
export class UvResource extends Resource<UvConfig> {
3054
getSettings(): ResourceSettings<UvConfig> {
3155
return {
3256
id: 'uv',
57+
defaultConfig,
58+
exampleConfigs: {
59+
example1: examplePython,
60+
example2: exampleWithTools,
61+
},
3362
operatingSystems: [OS.Darwin, OS.Linux],
3463
schema,
3564
parameterSettings: {

src/resources/python/venv/venv-project.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
CreatePlan,
33
DestroyPlan,
4+
ExampleConfig,
45
Resource,
56
ResourceSettings,
67
getPty
@@ -26,11 +27,54 @@ export interface VenvProjectConfig extends ResourceConfig {
2627
automaticallyInstallRequirementsTxt?: boolean;
2728
}
2829

30+
const defaultConfig: Partial<VenvProjectConfig> = {
31+
envDir: '.venv',
32+
upgradeDeps: true,
33+
automaticallyInstallRequirementsTxt: true,
34+
}
35+
36+
const exampleBasic: ExampleConfig = {
37+
title: 'Create a virtual environment',
38+
description: 'Create a Python virtual environment in the project directory and automatically install dependencies from requirements.txt.',
39+
configs: [{
40+
type: 'venv-project',
41+
envDir: '.venv',
42+
cwd: '~/projects/my-project',
43+
automaticallyInstallRequirementsTxt: true,
44+
upgradeDeps: true,
45+
}]
46+
}
47+
48+
const exampleWithRepo: ExampleConfig = {
49+
title: 'Clone a repo and set up a virtual environment',
50+
description: 'Clone a Python project and immediately create a virtual environment with its dependencies installed.',
51+
configs: [
52+
{
53+
type: 'git-repository',
54+
repository: 'git@github.com:org/my-python-project.git',
55+
directory: '~/projects/my-python-project',
56+
},
57+
{
58+
type: 'venv-project',
59+
envDir: '.venv',
60+
cwd: '~/projects/my-python-project',
61+
automaticallyInstallRequirementsTxt: true,
62+
upgradeDeps: true,
63+
dependsOn: ['git-repository'],
64+
},
65+
]
66+
}
67+
2968
export class VenvProject extends Resource<VenvProjectConfig> {
3069

3170
getSettings(): ResourceSettings<VenvProjectConfig> {
3271
return {
3372
id: 'venv-project',
73+
defaultConfig,
74+
exampleConfigs: {
75+
example1: exampleBasic,
76+
example2: exampleWithRepo,
77+
},
3478
operatingSystems: [OS.Darwin, OS.Linux],
3579
schema,
3680
parameterSettings: {

src/resources/python/virtualenv/virtualenv-project.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
CreatePlan, DestroyPlan, ModifyPlan, ParameterChange, RefreshContext, Resource,
2+
CreatePlan, DestroyPlan, ExampleConfig, ModifyPlan, ParameterChange, RefreshContext, Resource,
33
ResourceSettings,
44
getPty
55
} from '@codifycli/plugin-core';
@@ -20,12 +20,50 @@ export interface VirtualenvProjectConfig extends ResourceConfig {
2020
automaticallyInstallRequirementsTxt?: boolean;
2121
}
2222

23+
const defaultConfig: Partial<VirtualenvProjectConfig> = {
24+
dest: '.venv',
25+
automaticallyInstallRequirementsTxt: true,
26+
}
27+
28+
const exampleBasic: ExampleConfig = {
29+
title: 'Create a virtualenv environment for a project',
30+
description: 'Create an isolated Python environment in a project directory and install dependencies from requirements.txt.',
31+
configs: [{
32+
type: 'virtualenv-project',
33+
dest: '.venv',
34+
cwd: '~/projects/my-python-project',
35+
automaticallyInstallRequirementsTxt: true,
36+
}]
37+
}
38+
39+
const exampleWithVirtualenv: ExampleConfig = {
40+
title: 'Install virtualenv and set up a project environment',
41+
description: 'Install virtualenv and create an isolated environment for a Python project, automatically installing dependencies from requirements.txt.',
42+
configs: [
43+
{
44+
type: 'virtualenv',
45+
},
46+
{
47+
type: 'virtualenv-project',
48+
dest: '.venv',
49+
cwd: '~/projects/my-python-project',
50+
automaticallyInstallRequirementsTxt: true,
51+
dependsOn: ['virtualenv'],
52+
},
53+
]
54+
}
55+
2356
// TODO: Remove path.resolve from cwd.
2457
export class VirtualenvProject extends Resource<VirtualenvProjectConfig> {
2558

2659
getSettings(): ResourceSettings<VirtualenvProjectConfig> {
2760
return {
2861
id: 'virtualenv-project',
62+
defaultConfig,
63+
exampleConfigs: {
64+
example1: exampleBasic,
65+
example2: exampleWithVirtualenv,
66+
},
2967
operatingSystems: [OS.Darwin, OS.Linux],
3068
schema,
3169
parameterSettings: {

src/resources/python/virtualenv/virtualenv.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
1-
import { CreatePlan, DestroyPlan, getPty, Resource, ResourceSettings, Utils } from '@codifycli/plugin-core';
1+
import { CreatePlan, DestroyPlan, ExampleConfig, getPty, Resource, ResourceSettings, Utils } from '@codifycli/plugin-core';
22
import { OS, ResourceConfig } from '@codifycli/schemas';
33

44
import schema from './virtualenv-schema.json';
55

66
export interface VirtualenvConfig extends ResourceConfig {}
77

8+
const exampleWithProject: ExampleConfig = {
9+
title: 'Install virtualenv and set up a project environment',
10+
description: 'Install virtualenv and create an isolated environment for a Python project, automatically installing dependencies from requirements.txt.',
11+
configs: [
12+
{
13+
type: 'virtualenv',
14+
},
15+
{
16+
type: 'virtualenv-project',
17+
dest: '.venv',
18+
cwd: '~/projects/my-python-project',
19+
automaticallyInstallRequirementsTxt: true,
20+
dependsOn: ['virtualenv'],
21+
},
22+
]
23+
}
24+
825
export class Virtualenv extends Resource<VirtualenvConfig> {
926

1027
getSettings(): ResourceSettings<VirtualenvConfig> {
1128
return {
1229
id: 'virtualenv',
30+
exampleConfigs: {
31+
example1: exampleWithProject,
32+
},
1333
operatingSystems: [OS.Darwin, OS.Linux],
1434
schema,
1535
dependencies: ['homebrew'],

0 commit comments

Comments
 (0)