Metadata-Version: 2.4
Name: pin-env-yml
Version: 0.1.0
Summary: Pin conda/micromamba environment.yml packages to their currently installed versions
Project-URL: Homepage, https://github.com/Santt997/pin-env-yml
Project-URL: Repository, https://github.com/Santt997/pin-env-yml
Project-URL: Bug Tracker, https://github.com/Santt997/pin-env-yml/issues
Project-URL: Changelog, https://github.com/Santt997/pin-env-yml/blob/main/CHANGELOG.md
Author-email: Santt997 <santiago.burastero@gmail.com>
License: MIT
License-File: LICENSE
Keywords: conda,environment,micromamba,pin,reproducibility,yml
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: System :: Systems Administration
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# pin-env-yml

[![PyPI version](https://badge.fury.io/py/pin-env-yml.svg)](https://pypi.org/project/pin-env-yml/)
[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![GitHub](https://img.shields.io/badge/GitHub-Santt997%2Fpin--env--yml-181717?logo=github)](https://github.com/Santt997/pin-env-yml)

> Pin conda/micromamba `environment.yml` packages to their currently installed versions — in-place, without bloat.

---

## The Problem

Sharing a conda `environment.yml` with unpinned versions leads to non-reproducible environments:

```yaml
# ❌ Unpinned — different installs on different machines
dependencies:
  - numpy
  - pandas
  - scikit-learn
```

Tools like `conda-lock` solve this by generating a *separate* lockfile. But sometimes you just want to **pin the versions directly in your existing `environment.yml`**, without changing your workflow.

That's exactly what `pin-env-yml` does.

---

## Installation

```bash
pip install pin-env-yml
```

> Requires Python 3.8+. No external dependencies — only Python stdlib.

---

## Usage

### CLI

```bash
# Reads env name from the 'name:' field in the YML
pin-env-yml environment.yml

# Or specify the env name explicitly
pin-env-yml environment.yml myenv
```

### Python API

```python
from pin_env_yml import pin_yml

# Pin in-place
pinned_count = pin_yml("environment.yml")
pinned_count = pin_yml("environment.yml", target_env_name="myenv")
```

---

## Example

**Before** (`environment.yml`):
```yaml
name: myproject
channels:
  - conda-forge
  - defaults
dependencies:
  - python
  - numpy
  - pandas
  - pip:
    - requests
    - httpx
```

**Run:**
```bash
pin-env-yml environment.yml
# 🔍 Analyzing YML file: environment.yml
# 📦 Matching against installed packages in env: myproject
#   📌 Pinned python → 3.11.9 (conda)
#   📌 Pinned numpy → 1.26.4 (conda)
#   📌 Pinned pandas → 2.2.2 (conda)
#   📌 Pinned requests → 2.32.3 (pip)
#   📌 Pinned httpx → 0.27.0 (pip)
#
# ✨ Done! Pinned 5 explicit dependencies in: environment.yml
```

**After** (`environment.yml`):
```yaml
name: myproject
channels:
  - conda-forge
  - defaults
dependencies:
  - python=3.11.9
  - numpy=1.26.4
  - pandas=2.2.2
  - pip:
    - requests==2.32.3
    - httpx==0.27.0
```

---

## How It Works

1. Reads the `environment.yml` file
2. Queries `micromamba list -n <env> --json` (falls back to `conda list`)
3. For each explicit dependency in the YML, substitutes the currently installed version
4. Writes the updated file back in-place
5. Uses `=` for conda packages and `==` for pip packages (correct convention for each)

---

## Requirements

- Python 3.8+
- `micromamba` or `conda` must be in your PATH and the target environment must exist

---

## License

MIT © [Santt997](https://github.com/Santt997)
