envkeep 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. envkeep-0.1.1/.github/workflows/ci.yml +70 -0
  2. envkeep-0.1.1/.github/workflows/release.yml +74 -0
  3. envkeep-0.1.1/.gitignore +13 -0
  4. envkeep-0.1.1/CHANGELOG.md +22 -0
  5. envkeep-0.1.1/LICENSE +21 -0
  6. envkeep-0.1.1/PKG-INFO +273 -0
  7. envkeep-0.1.1/README.md +239 -0
  8. envkeep-0.1.1/examples/.env.example +9 -0
  9. envkeep-0.1.1/examples/compose.demo.env +4 -0
  10. envkeep-0.1.1/examples/compose.yaml +18 -0
  11. envkeep-0.1.1/examples/envkeep.yml +15 -0
  12. envkeep-0.1.1/examples/secrets.env +1 -0
  13. envkeep-0.1.1/examples/web.env +1 -0
  14. envkeep-0.1.1/pyproject.toml +62 -0
  15. envkeep-0.1.1/scripts/compare_parsers.py +14 -0
  16. envkeep-0.1.1/scripts/try_check.py +13 -0
  17. envkeep-0.1.1/src/envkeep/__init__.py +0 -0
  18. envkeep-0.1.1/src/envkeep/checks.py +64 -0
  19. envkeep-0.1.1/src/envkeep/cli.py +298 -0
  20. envkeep-0.1.1/src/envkeep/compare.py +13 -0
  21. envkeep-0.1.1/src/envkeep/compose.py +170 -0
  22. envkeep-0.1.1/src/envkeep/differ.py +25 -0
  23. envkeep-0.1.1/src/envkeep/fileio.py +28 -0
  24. envkeep-0.1.1/src/envkeep/generator.py +21 -0
  25. envkeep-0.1.1/src/envkeep/interpolate.py +142 -0
  26. envkeep-0.1.1/src/envkeep/models.py +15 -0
  27. envkeep-0.1.1/src/envkeep/output.py +179 -0
  28. envkeep-0.1.1/src/envkeep/parser.py +127 -0
  29. envkeep-0.1.1/src/envkeep/schema.py +125 -0
  30. envkeep-0.1.1/src/envkeep/syncer.py +45 -0
  31. envkeep-0.1.1/src/envkeep/validate.py +39 -0
  32. envkeep-0.1.1/src/envkeep/yamlutil.py +101 -0
  33. envkeep-0.1.1/tests/conftest.py +13 -0
  34. envkeep-0.1.1/tests/fixtures/dev.env +4 -0
  35. envkeep-0.1.1/tests/fixtures/example.env +4 -0
  36. envkeep-0.1.1/tests/fixtures/good.env +4 -0
  37. envkeep-0.1.1/tests/fixtures/tricky.env +7 -0
  38. envkeep-0.1.1/tests/test_checks.py +67 -0
  39. envkeep-0.1.1/tests/test_cli.py +482 -0
  40. envkeep-0.1.1/tests/test_compare.py +39 -0
  41. envkeep-0.1.1/tests/test_compose.py +343 -0
  42. envkeep-0.1.1/tests/test_differ.py +33 -0
  43. envkeep-0.1.1/tests/test_fileio.py +64 -0
  44. envkeep-0.1.1/tests/test_generator.py +53 -0
  45. envkeep-0.1.1/tests/test_interpolate.py +103 -0
  46. envkeep-0.1.1/tests/test_parser.py +114 -0
  47. envkeep-0.1.1/tests/test_schema.py +210 -0
  48. envkeep-0.1.1/tests/test_syncer.py +141 -0
  49. envkeep-0.1.1/tests/test_validate.py +62 -0
  50. envkeep-0.1.1/tests/test_yamlutil.py +109 -0
@@ -0,0 +1,70 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ name: Test (Python ${{ matrix.python }}, ${{ matrix.os }})
14
+ runs-on: ${{ matrix.os }}
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ os: [ubuntu-latest, windows-latest]
19
+ python: ["3.10", "3.11", "3.12", "3.13"]
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+ - uses: actions/setup-python@v5
23
+ with:
24
+ python-version: ${{ matrix.python }}
25
+ cache: pip
26
+ - run: python -m pip install --upgrade pip
27
+ - run: pip install -e ".[dev]"
28
+ - run: pytest
29
+
30
+ lint:
31
+ name: Lint
32
+ runs-on: ubuntu-latest
33
+ steps:
34
+ - uses: actions/checkout@v4
35
+ - uses: actions/setup-python@v5
36
+ with:
37
+ python-version: "3.13"
38
+ cache: pip
39
+ - run: pip install ruff
40
+ - run: ruff check .
41
+ - run: ruff format --check .
42
+
43
+ build:
44
+ name: Build and check the package
45
+ runs-on: ubuntu-latest
46
+ steps:
47
+ - uses: actions/checkout@v4
48
+ - uses: actions/setup-python@v5
49
+ with:
50
+ python-version: "3.13"
51
+ - run: pip install build twine
52
+ - run: python -m build
53
+ - run: twine check dist/*
54
+ - name: Install the built wheel and run the CLI
55
+ run: |
56
+ python -m venv /tmp/smoke
57
+ /tmp/smoke/bin/pip install dist/*.whl
58
+ /tmp/smoke/bin/envkeep --help
59
+
60
+ minimum-versions:
61
+ name: Minimum dependency versions
62
+ runs-on: ubuntu-latest
63
+ steps:
64
+ - uses: actions/checkout@v4
65
+ - uses: actions/setup-python@v5
66
+ with:
67
+ python-version: "3.10"
68
+ cache: pip
69
+ - run: pip install -e ".[dev]" "typer==0.12.0" "rich==13.0.0" "pyyaml==6.0" "click<8.2"
70
+ - run: pytest
@@ -0,0 +1,74 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: actions/setup-python@v5
16
+ with:
17
+ python-version: "3.13"
18
+ - name: Check that the tag matches the package version
19
+ run: |
20
+ VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
21
+ if [ "v$VERSION" != "$GITHUB_REF_NAME" ]; then
22
+ echo "Tag $GITHUB_REF_NAME does not match version $VERSION in pyproject.toml"
23
+ exit 1
24
+ fi
25
+ - run: pip install build twine
26
+ - run: python -m build
27
+ - run: twine check dist/*
28
+ - uses: actions/upload-artifact@v4
29
+ with:
30
+ name: dist
31
+ path: dist/
32
+
33
+ publish-testpypi:
34
+ needs: build
35
+ runs-on: ubuntu-latest
36
+ environment: testpypi
37
+ permissions:
38
+ id-token: write # lets GitHub prove its identity to TestPyPI
39
+ steps:
40
+ - uses: actions/download-artifact@v4
41
+ with:
42
+ name: dist
43
+ path: dist/
44
+ - uses: pypa/gh-action-pypi-publish@release/v1
45
+ with:
46
+ repository-url: https://test.pypi.org/legacy/
47
+
48
+ publish-pypi:
49
+ needs: publish-testpypi
50
+ runs-on: ubuntu-latest
51
+ environment: pypi # pauses here until you approve (see the setup below)
52
+ permissions:
53
+ id-token: write # lets GitHub prove its identity to PyPI
54
+ steps:
55
+ - uses: actions/download-artifact@v4
56
+ with:
57
+ name: dist
58
+ path: dist/
59
+ - uses: pypa/gh-action-pypi-publish@release/v1
60
+
61
+ github-release:
62
+ needs: publish-pypi
63
+ runs-on: ubuntu-latest
64
+ permissions:
65
+ contents: write # needed to create the release
66
+ steps:
67
+ - uses: actions/download-artifact@v4
68
+ with:
69
+ name: dist
70
+ path: dist/
71
+ - name: Create the GitHub release
72
+ env:
73
+ GH_TOKEN: ${{ github.token }}
74
+ run: gh release create "$GITHUB_REF_NAME" dist/* --repo "${{ github.repository }}" --generate-notes
@@ -0,0 +1,13 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+
10
+
11
+ .env
12
+ !.env.example
13
+ !examples/.env.example
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here.
4
+ The format follows [Keep a Changelog](https://keepachangelog.com/), and the project
5
+ uses [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [0.1.1] - 2026-12-05
8
+
9
+ First release.
10
+
11
+ ### Added
12
+
13
+ - `envkeep check`: compare a `.env` file against `.env.example` or an `envkeep.yml`
14
+ schema, reporting missing, empty, invalid, and extra variables, with CI-friendly exit codes.
15
+ - `envkeep generate`: build `.env.example` from `.env`, keeping comments and removing values.
16
+ - `envkeep sync`: add missing variables without changing existing ones, with `--dry-run`,
17
+ line-ending preservation, and atomic writes.
18
+ - `envkeep diff`: compare two env files, with values hidden by default.
19
+ - `envkeep compose`: find undefined `${VAR}` references and missing `env_file` entries in
20
+ Docker Compose files, including nested expressions.
21
+ - `envkeep.yml` schema with `str`, `int`, `float`, `bool`, and `url` types, defaults, and
22
+ optional variables.
envkeep-0.1.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Avishka Chamod
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
envkeep-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,273 @@
1
+ Metadata-Version: 2.5
2
+ Name: envkeep
3
+ Version: 0.1.1
4
+ Summary: Check, sync, and document your .env files against .env.example
5
+ Project-URL: Homepage, https://github.com/Avishka14/envkeep
6
+ Project-URL: Issues, https://github.com/Avishka14/envkeep/issues
7
+ Project-URL: Changelog, https://github.com/Avishka14/envkeep/blob/main/CHANGELOG.md
8
+ Author: Avishka Chamod
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: cli,devops,docker,docker-compose,dotenv,env,environment-variables
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Quality Assurance
22
+ Classifier: Topic :: Utilities
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: python-dotenv>=1.0
25
+ Requires-Dist: pyyaml>=6
26
+ Requires-Dist: rich>=13
27
+ Requires-Dist: typer>=0.12
28
+ Provides-Extra: dev
29
+ Requires-Dist: build; extra == 'dev'
30
+ Requires-Dist: pytest; extra == 'dev'
31
+ Requires-Dist: ruff; extra == 'dev'
32
+ Requires-Dist: twine; extra == 'dev'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # envkeep
36
+
37
+ [![CI](https://github.com/Avishka14/envkeep/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/Avishka14/envkeep/actions/workflows/ci.yml)
38
+ [![PyPI](https://img.shields.io/pypi/v/envkeep)](https://pypi.org/project/envkeep/)
39
+ [![Python](https://img.shields.io/pypi/pyversions/envkeep)](https://pypi.org/project/envkeep/)
40
+ [![License: MIT](https://img.shields.io/github/license/Avishka14/envkeep)](https://github.com/Avishka14/envkeep/blob/main/LICENSE)
41
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
42
+
43
+ **Keep your `.env` files in sync with `.env.example`, and catch undefined Docker Compose variables before they break your deploy.**
44
+
45
+ envkeep treats your `.env.example` (or a small schema file) as the source of truth. It checks your real `.env` for missing, empty, and invalid variables, syncs and generates example files without touching your existing values, compares environments, and scans `docker-compose.yml` for `${VAR}` references that are never defined. Every command uses exit codes, so it drops straight into CI and pre-commit hooks.
46
+
47
+ ## Contents
48
+
49
+ - [Install](#install)
50
+ - [Quick start](#quick-start)
51
+ - [Commands](#commands)
52
+ - [Schema file](#schema-file)
53
+ - [Exit codes](#exit-codes)
54
+ - [Use it in CI](#use-it-in-ci)
55
+ - [Privacy](#privacy)
56
+ - [Development](#development)
57
+ - [License](#license)
58
+
59
+ ## Install
60
+
61
+ Requires Python 3.10 or newer. This installs the `envkeep` command.
62
+
63
+ ```bash
64
+ pip install envkeep
65
+ ```
66
+
67
+ Or, to keep it out of your project's environment:
68
+
69
+ ```bash
70
+ pipx install envkeep
71
+ ```
72
+
73
+ From source:
74
+
75
+ ```bash
76
+ pip install git+https://github.com/Avishka14/envkeep.git
77
+ ```
78
+
79
+ ## Quick start
80
+
81
+ ```bash
82
+ envkeep check # compare .env against .env.example
83
+ envkeep sync # add any missing variables to .env
84
+ envkeep compose # find undefined variables in docker-compose.yml
85
+ ```
86
+
87
+ ## Commands
88
+
89
+ | Command | What it does |
90
+ |---|---|
91
+ | `envkeep check` | Compares `.env` to `.env.example` (or an `envkeep.yml` schema). Reports missing, empty, invalid, and extra variables. |
92
+ | `envkeep generate` | Builds `.env.example` from `.env`, stripping values and keeping comments. |
93
+ | `envkeep sync` | Adds variables that exist in `.env.example` but not in `.env`. Never changes existing values. |
94
+ | `envkeep diff A B` | Shows differences between two env files, for example dev and staging. |
95
+ | `envkeep compose` | Finds `${VAR}` references and `env_file:` entries in a Compose file that are undefined or missing. |
96
+
97
+ Run `envkeep <command> --help` for every option.
98
+
99
+ ### check
100
+
101
+ ```bash
102
+ envkeep check --env .env --example .env.example
103
+ envkeep check --env .env --schema envkeep.yml
104
+ ```
105
+
106
+ ```text
107
+ tests/fixtures/dev.env vs tests/fixtures/example.env
108
+ ┏━━━━━━━━━┳━━━━━━━━━━━━┓
109
+ ┃ Status ┃ Variable ┃
110
+ ┡━━━━━━━━━╇━━━━━━━━━━━━┩
111
+ │ missing │ SECRET_KEY │
112
+ │ empty │ PORT │
113
+ │ extra │ REDIS_URL │
114
+ └─────────┴────────────┘
115
+ FAILED 1 missing, 1 empty, 1 extra
116
+ ```
117
+
118
+ Missing and empty variables fail the check. Extra variables (in `.env` but not in the example) are warnings only.
119
+
120
+ ### generate
121
+
122
+ ```bash
123
+ envkeep generate --env .env --output .env.example
124
+ ```
125
+
126
+ Keeps comments, blank lines, key order, and `export` prefixes. Values are removed, or replaced with `--placeholder`. It refuses to overwrite an existing file without `--force`, and refuses outright if the input and output are the same file.
127
+
128
+ ### sync
129
+
130
+ ```bash
131
+ envkeep sync --dry-run # show what would be added
132
+ envkeep sync # add it
133
+ ```
134
+
135
+ `sync` only appends, so existing lines, comments, and values are never modified. Line endings (LF or CRLF) are preserved, and the file is replaced atomically, so a failed write can't leave a half-written `.env`.
136
+
137
+ ### diff
138
+
139
+ ```bash
140
+ envkeep diff dev.env staging.env
141
+ envkeep diff dev.env staging.env --keys-only
142
+ ```
143
+
144
+ Values are hidden by default because they may be secrets. Use `--show-values` to see them, or `--keys-only` to compare just which variables exist.
145
+
146
+ ### compose
147
+
148
+ ```bash
149
+ envkeep compose # finds compose.yaml / docker-compose.yml
150
+ envkeep compose docker-compose.yml --env .env.production
151
+ envkeep compose --shell-env # also count variables set in your shell
152
+ ```
153
+
154
+ ```text
155
+ examples/compose.yaml
156
+ ┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
157
+ ┃ Status ┃ Name ┃ Where ┃
158
+ ┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
159
+ │ undefined │ DB_PASSWORD │ services.db.environment.POSTGRES_… │
160
+ │ empty │ SECRET_KEY │ services.web.environment.SECRET_KEY │
161
+ │ missing file │ ./secrets.env │ services.db.env_file │
162
+ │ missing file │ ./web.env │ services.web.env_file │
163
+ └──────────────┴───────────────┴─────────────────────────────────────┘
164
+ FAILED 1 undefined, 1 empty, 2 missing env_file (1 with defaults)
165
+ ```
166
+
167
+ envkeep follows Compose's interpolation rules:
168
+
169
+ | Syntax | Reported when |
170
+ |---|---|
171
+ | `$VAR`, `${VAR}` | The variable is undefined |
172
+ | `${VAR:?msg}` | Undefined, or defined but empty |
173
+ | `${VAR?msg}` | Undefined (empty is accepted) |
174
+ | `${VAR:-x}`, `${VAR-x}`, `${VAR:+x}`, `${VAR+x}` | Never (counted as optional) |
175
+ | `env_file:` entry | The file is missing (unless `required: false`) |
176
+
177
+ Variables in an `env_file` path are expanded first. If one is undefined, that variable is reported instead of the file. Nested expressions such as `${IMAGE:-${FALLBACK:?set FALLBACK}}` are evaluated only when their branch is active. Values are never printed.
178
+
179
+ ## Schema file
180
+
181
+ A schema adds types and rules. Pass it with `--schema`:
182
+
183
+ ```yaml
184
+ # envkeep.yml
185
+ variables:
186
+ DATABASE_URL:
187
+ type: url # str (default), int, float, bool, url
188
+ PORT:
189
+ type: int
190
+ default: 8000 # has a default, so it may be missing or empty
191
+ DEBUG:
192
+ type: bool
193
+ default: false
194
+ SECRET_KEY: # no rules: a required string
195
+ REDIS_URL:
196
+ type: url
197
+ required: false # optional: may be missing or empty
198
+ ```
199
+
200
+ A variable is required unless it has a `default` or `required: false`. Typos in rule names, unknown types, duplicate keys, and contradictory rules are rejected with a clear message.
201
+
202
+ ## Exit codes
203
+
204
+ | Code | Meaning |
205
+ |---|---|
206
+ | 0 | Everything is fine |
207
+ | 1 | A check failed: missing, empty, or invalid variables, files that differ, or undefined Compose variables |
208
+ | 2 | Usage error: a file is missing or unreadable, a file can't be parsed, or the output would overwrite something |
209
+
210
+ ## Use it in CI
211
+
212
+ Save this as `.github/workflows/env.yml` in your project:
213
+
214
+ ```yaml
215
+ name: env
216
+
217
+ on:
218
+ push:
219
+ pull_request:
220
+
221
+ permissions:
222
+ contents: read
223
+
224
+ jobs:
225
+ check:
226
+ runs-on: ubuntu-latest
227
+ steps:
228
+ - uses: actions/checkout@v4
229
+ - uses: actions/setup-python@v5
230
+ with:
231
+ python-version: "3.13"
232
+ - run: pip install envkeep
233
+ - run: envkeep check --env .env.ci --example .env.example
234
+ - run: envkeep compose docker-compose.yml --env .env.ci
235
+ ```
236
+
237
+ `.env.ci` is a committed env file with safe, non-secret values for CI. Never commit a real `.env`.
238
+ The job fails when a variable is missing, empty, or invalid, because envkeep exits with code 1.
239
+
240
+ ## Privacy
241
+
242
+ envkeep never prints variable values by default, in `check`, `diff`, `compose`, or error messages. YAML errors report a line and column, never the source text.
243
+
244
+ ## Development
245
+
246
+ ```bash
247
+ git clone https://github.com/Avishka14/envkeep
248
+ cd envkeep
249
+ python -m venv .venv
250
+ source .venv/bin/activate # Windows: .venv\Scripts\activate
251
+ pip install -e ".[dev]"
252
+ pytest
253
+ ruff check . && ruff format --check .
254
+ ```
255
+
256
+ CI runs the tests on Linux and Windows (Python 3.10 to 3.13), the linter, a package build check, and a run against the oldest supported dependency versions.
257
+
258
+ ### Releasing
259
+
260
+ 1. Bump `version` in `pyproject.toml` and add an entry to `CHANGELOG.md`.
261
+ 2. Merge the change into `main`.
262
+ 3. Tag the release from `main` and push the tag:
263
+
264
+ ```bash
265
+ git tag -a v0.1.1 -m "envkeep 0.1.1"
266
+ git push origin v0.1.1
267
+ ```
268
+
269
+ The release workflow checks that the tag matches the version, builds the package, publishes it to TestPyPI, waits for a maintainer's approval, publishes it to PyPI, and then creates the GitHub release. Publishing uses PyPI trusted publishing, so no API token is stored anywhere.
270
+
271
+ ## License
272
+
273
+ MIT. See [LICENSE](https://github.com/Avishka14/envkeep/blob/main/LICENSE).