Skip to content

Commit 01da5cb

Browse files
authored
Merge pull request #4 from dev-ankit/claude/config-utils-cli-tool-9Pjeo
Create config-utils CLI tool for environment capture
2 parents b3b959a + a42b3b1 commit 01da5cb

5 files changed

Lines changed: 386 additions & 12 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@ on:
99
jobs:
1010
test:
1111
runs-on: ubuntu-latest
12-
strategy:
13-
matrix:
14-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
15-
1612
steps:
1713
- uses: actions/checkout@v4
1814

19-
- name: Set up Python ${{ matrix.python-version }}
15+
- name: Set up Python 3.12
2016
uses: actions/setup-python@v5
2117
with:
22-
python-version: ${{ matrix.python-version }}
18+
python-version: 3.12
2319

2420
- name: Install and test locust-compare
2521
working-directory: tools/locust-compare

README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ A collection of small, independent Python utilities. Each tool is self-contained
77
| Tool | Description |
88
|------|-------------|
99
| [locust-compare](tools/locust-compare/) | Compare performance metrics between two Locust runs |
10+
| [config-utils](tools/config-utils/) | CLI tool for capturing environment variables and Django settings |
1011

1112
## Installation
1213

@@ -16,18 +17,28 @@ Each tool can be installed independently using `uvx` directly from GitHub:
1617

1718
For example:
1819
```bash
20+
# Install locust-compare
1921
uv tool install 'git+https://github.com/dev-ankit/python-tools.git#subdirectory=tools/locust-compare'
22+
23+
# Install config-utils
24+
uv tool install 'git+https://github.com/dev-ankit/python-tools.git#subdirectory=tools/config-utils'
2025
```
21-
After that, you can run from anywhere:
26+
27+
After installation, you can run from anywhere:
28+
```bash
2229
locust-compare <base_dir> <current_dir>
30+
config-utils capture-env
31+
```
2332

2433
To update to the latest from GitHub:
2534

26-
```
35+
```bash
2736
uv tool upgrade locust-compare
37+
uv tool upgrade config-utils
2838

2939
# Or force reinstall:
3040
uv tool install --force 'git+https://github.com/dev-ankit/python-tools.git#subdirectory=tools/locust-compare'
41+
uv tool install --force 'git+https://github.com/dev-ankit/python-tools.git#subdirectory=tools/config-utils'
3142

3243
# To see installed tools:
3344
uv tool list
@@ -42,7 +53,11 @@ uvx --from 'git+https://github.com/dev-ankit/python-tools.git#subdirectory=tools
4253
For example:
4354

4455
```bash
56+
# Run locust-compare
4557
uvx --from 'git+https://github.com/dev-ankit/python-tools.git#subdirectory=tools/locust-compare' locust-compare <base_dir> <current_dir>
58+
59+
# Run config-utils
60+
uvx --from 'git+https://github.com/dev-ankit/python-tools.git#subdirectory=tools/config-utils' config-utils capture-env
4661
```
4762

4863
Option 3: Clone and run locally:
@@ -62,11 +77,15 @@ python-tools/
6277
├── .github/
6378
│ └── workflows/
6479
└── tools/
65-
└── locust-compare/ # Locust performance comparison tool
66-
├── compare_runs.py
80+
├── locust-compare/ # Locust performance comparison tool
81+
│ ├── compare_runs.py
82+
│ ├── pyproject.toml
83+
│ ├── README.md
84+
│ └── tests/
85+
└── config-utils/ # CLI tool for capturing environment variables and Django settings
86+
├── cli.py
6787
├── pyproject.toml
68-
├── README.md
69-
└── tests/
88+
└── README.md
7089
```
7190

7291
## Adding a New Tool

tools/config-utils/README.md

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# config-utils
2+
3+
A CLI tool for capturing environment variables and Django settings in YAML format.
4+
5+
## Features
6+
7+
- **capture-env**: Capture all environment variables and export them to YAML
8+
- **capture-django-settings**: Capture Django project settings and export them to YAML
9+
10+
## Installation
11+
12+
### Using uv tool install (Recommended)
13+
14+
Install the tool globally using `uv`:
15+
16+
```bash
17+
uv tool install .
18+
```
19+
20+
Or install from a remote location:
21+
22+
```bash
23+
uv tool install config-utils
24+
```
25+
26+
This will install the `config-utils` executable in your PATH.
27+
28+
### Using uvx
29+
30+
Run the tool directly without installation:
31+
32+
```bash
33+
uvx --from . config-utils capture-env
34+
```
35+
36+
### Using pip
37+
38+
Install from the local directory:
39+
40+
```bash
41+
pip install .
42+
```
43+
44+
Or install in editable mode for development:
45+
46+
```bash
47+
pip install -e .
48+
```
49+
50+
51+
## Usage
52+
53+
### Capture Environment Variables
54+
55+
Capture all environment variables to a YAML file:
56+
57+
```bash
58+
config-utils capture-env
59+
```
60+
61+
This will create `env_config.yaml` with all your environment variables.
62+
63+
#### Options
64+
65+
- `-o, --output PATH`: Specify output file path (default: `env_config.yaml`)
66+
- `-f, --format`: Output format, yaml or yml (default: `yaml`)
67+
68+
#### Examples
69+
70+
```bash
71+
# Capture to custom file
72+
config-utils capture-env -o my_env.yaml
73+
74+
# Capture with yml extension
75+
config-utils capture-env -o config.yml -f yml
76+
```
77+
78+
### Capture Django Settings
79+
80+
Capture Django project settings to a YAML file using `python manage.py shell`:
81+
82+
```bash
83+
# Run from your Django project directory
84+
cd /path/to/your/django/project
85+
config-utils capture-django-settings
86+
```
87+
88+
This will create `django_settings.yaml` with all Django settings.
89+
90+
#### Options
91+
92+
- `-o, --output PATH`: Specify output file path (default: `django_settings.yaml`)
93+
- `-f, --format`: Output format, yaml or yml (default: `yaml`)
94+
- `-m, --manage-py PATH`: Path to manage.py (default: `manage.py`)
95+
- `-s, --settings`: Django settings module (e.g., `myproject.settings`)
96+
97+
#### Examples
98+
99+
```bash
100+
# From Django project root directory
101+
config-utils capture-django-settings
102+
103+
# Specifying settings module via command line
104+
config-utils capture-django-settings -s myproject.settings
105+
106+
# Custom output file
107+
config-utils capture-django-settings -o my_django_config.yaml
108+
109+
# Specify manage.py path if not in current directory
110+
config-utils capture-django-settings -m /path/to/manage.py
111+
112+
# Using DJANGO_SETTINGS_MODULE environment variable
113+
export DJANGO_SETTINGS_MODULE=myproject.settings
114+
config-utils capture-django-settings
115+
```
116+
117+
**Note**: This command must be run from your Django project directory or you must specify the path to `manage.py` using the `--manage-py` option.
118+
119+
### Using with uvx
120+
121+
You can run the tool directly without installation:
122+
123+
```bash
124+
# Capture environment variables
125+
uvx --from . config-utils capture-env
126+
127+
# With options
128+
uvx --from . config-utils capture-env -o custom.yaml
129+
130+
# Django settings (from Django project directory)
131+
cd /path/to/django/project
132+
uvx --from /path/to/config-utils config-utils capture-django-settings
133+
134+
# Or specify manage.py path
135+
uvx --from /path/to/config-utils config-utils capture-django-settings -m /path/to/manage.py
136+
```
137+
138+
## Requirements
139+
140+
- Python >= 3.8
141+
- click >= 8.0.0
142+
- pyyaml >= 6.0
143+
144+
**For Django settings capture**: The command uses `python manage.py shell`, so Django must be installed in your Django project's environment. The config-utils tool itself does not need Django as a dependency.
145+
146+
## Development
147+
148+
### Setup
149+
150+
```bash
151+
# Clone or navigate to the project directory
152+
cd config-utils
153+
154+
# Install in editable mode with development dependencies
155+
pip install -e .
156+
```
157+
158+
### Project Structure
159+
160+
```
161+
config-utils/
162+
├── cli.py
163+
├── config_utils/
164+
├── pyproject.toml
165+
└── README.md
166+
```
167+
168+
## License
169+
170+
MIT License
171+
172+
## Contributing
173+
174+
Contributions are welcome! Please feel free to submit a Pull Request.

0 commit comments

Comments
 (0)