Skip to content

Commit

Permalink
add casefold to sorting (#11)
Browse files Browse the repository at this point in the history
* add casefold to sorting

* add IPython to test

* change test

* update README.md
  • Loading branch information
CagtayFabry authored Feb 2, 2023
1 parent 63ccce9 commit c1e06c3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 43 deletions.
95 changes: 59 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,63 @@
# pydeps2env

An easy way to create conda environment files from you python project dependencies.
Creates a conda `environment.yml` file from python package dependencies listed in a `setup.cfg` or `pyproject.toml` file.
Creates a conda `environment.yml` file from python package dependencies listed in a `pyproject.toml` or `setup.cfg` file.

## basic usage

By default, the action will parse a `setup.cfg` file in your root directory into `environment.yml`. Here is an example
By default, the action will parse a `pyproject.toml` file in your root directory into `environment.yml`. Here is an example
of a simple setup:

```yaml
steps:
- uses: CagtayFabry/[email protected].0
- uses: CagtayFabry/[email protected].2
```
```cfg
[options]
python_requires = >=3.8,<3.10
setup_requires =
setuptools >=38.3.0
setuptools_scm
install_requires =
numpy >=1.20
pandas >=1.0

[options.extras_require]
test =
pytest
```toml
[project]
requires-python = ">=3.8,<3.10"
dependencies = [
"numpy >=1.20",
"pandas >=1.0",
"IPython",
"boltons",
]
[project.optional-dependencies]
test = ["pytest"]
pip_only = ["bidict"]
]
```

The default parameters will output this `environment.yml`:
The default parameters will output this sorted `environment.yml`:

```yaml
channels:
- defaults
dependencies:
- python>=3.8
- boltons
- IPython
- numpy>=1.20
- pandas>=1.0
- python>=3.8,<3.10
```
A full output with options `--setup_requires include --extras test pip_only --pip bidict`

```yaml
channels:
- defaults
dependencies:
- boltons
- IPython
- numpy>=1.20
- pandas>=1.0
- pytest
- python>=3.8,<3.10
- setuptools>=40.9.0
- setuptools_scm
- wheel
- pip:
- bidict
```

## configuration options
Expand Down Expand Up @@ -84,33 +105,35 @@ steps:
pip: 'bidict'
```

```cfg
[options]
python_requires = >=3.8,<3.10
setup_requires =
setuptools >=38.3.0
setuptools_scm
install_requires =
numpy >=1.20
pandas >=1.0
bidict
[options.extras_require]
test =
pytest
```toml
[project]
requires-python = ">=3.8,<3.10"
dependencies = [
"numpy >=1.20",
"pandas >=1.0",
"IPython",
"boltons",
]
[project.optional-dependencies]
test = ["pytest"]
pip_only = ["bidict"]
]
```

```yaml
channels:
- conda-forge
- defaults
dependencies:
- python>=3.8,<3.10
- setuptools>=38.3.0
- setuptools_scm
- boltons
- IPython
- numpy>=1.20
- pandas>=1.0
- pytest
- python>=3.8,<3.10
- setuptools>=40.9.0
- setuptools_scm
- wheel
- pip:
- bidict
- bidict
```
4 changes: 2 additions & 2 deletions create_conda_env_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class MetadataType:
env["dependencies"] = list(set(env["dependencies"]) - set(pip))

# sort output
env["dependencies"] = sorted(env["dependencies"])
pip = sorted(pip)
env["dependencies"] = sorted(env["dependencies"], key=str.casefold)
pip = sorted(pip, key=str.casefold)

output = "channels:"
output += "\n - ".join([""] + env["channels"])
Expand Down
10 changes: 5 additions & 5 deletions test/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ author = "Cagtay Fabry <[email protected]>"
author_email = "[email protected]"

requires-python = ">=3.8,<3.10"

dependencies = [
"numpy >=1.20",
"pandas >=1.0",
"IPython",
"boltons",
]

[project.urls]
home_page = "https://github.com/CagtayFabry/pydeps2env"

[project.optional-dependencies]
test = ["pytest"]
pip_only = ["bidict"]

[project.urls]
home_page = "https://github.com/CagtayFabry/pydeps2env"

# Build system config, pip creates a temporary env with "requires" pkgs.
[build-system]
requires = [
Expand Down

0 comments on commit c1e06c3

Please sign in to comment.