Skip to content

Commit 1fcffc2

Browse files
authored
rework as python package (#13)
* add basic code * add extras parsing * add pyproject.toml and scripts * update github action * refactor script location * update action * update action * add shell to setup * allow version not provided * add setup.cfg parsing * install packaging in action * add packaging dependency * update and fmt * annotations * update cmd options * update cmd script * use setup-python action * update * update README.md
1 parent d160bcb commit 1fcffc2

File tree

10 files changed

+395
-169
lines changed

10 files changed

+395
-169
lines changed

.github/workflows/test.yml

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,40 @@ jobs:
88
fail-fast: false
99
matrix:
1010
os: [ubuntu-latest, macos-latest, windows-latest]
11-
config_file: ['./test/setup.cfg', './test/pyproject.toml']
11+
config_file: [./test/setup.cfg, ./test/pyproject.toml]
1212
steps:
13-
- uses: actions/checkout@v3
14-
- name: run local action code
15-
uses: ./
16-
with:
17-
file: ${{ matrix.config_file }}
18-
output: 'environment_test.yml'
19-
channels: 'conda-forge defaults'
20-
extras: 'test pip_only'
21-
setup_requires: 'include'
22-
pip: 'bidict'
23-
- uses: mamba-org/setup-micromamba@v1.4.3
24-
with:
25-
environment-file: ./environment_test.yml
26-
environment-name: demo
27-
init-shell: >-
28-
bash
29-
powershell
30-
cache-environment: true
13+
- uses: actions/checkout@v4
14+
- name: run local action code
15+
uses: ./
16+
with:
17+
file: ${{ matrix.config_file }}
18+
output: environment_test.yml
19+
channels: conda-forge defaults
20+
extras: test pip_only
21+
setup_requires: include
22+
pip: bidict
23+
- uses: mamba-org/setup-micromamba@v1.8.0
24+
with:
25+
environment-file: ./environment_test.yml
26+
environment-name: demo
27+
init-shell: >-
28+
bash
29+
powershell
30+
cache-environment: true
31+
32+
test_script:
33+
name: create test env
34+
runs-on: ubuntu-latest
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
config_file: [./test/setup.cfg, ./test/pyproject.toml]
39+
steps:
40+
- uses: actions/checkout@v4
41+
- uses: actions/setup-python@v5
42+
with:
43+
python-version: '3.10'
44+
- name: pip install package
45+
run: pip install .
46+
- name: test cmd script
47+
run: pydeps2env ${{ matrix.config_file }} output.yaml -c defaults --extras test -b include --pip pandas

.pre-commit-config.yaml

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.1.0
4-
hooks:
5-
- id: trailing-whitespace
6-
args: [--markdown-linebreak-ext=md]
7-
- id: end-of-file-fixer
8-
- id: check-yaml
9-
- repo: https://github.com/psf/black
10-
rev: 22.1.0
11-
hooks:
12-
- id: black
13-
- repo: https://github.com/pycqa/isort
14-
rev: 5.10.1
15-
hooks:
16-
- id: isort
17-
- repo: https://github.com/PyCQA/flake8
18-
rev: 4.0.1
19-
hooks:
20-
- id: flake8
21-
args: [--max-line-length=88]
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.1.0
4+
hooks:
5+
- id: trailing-whitespace
6+
args: [--markdown-linebreak-ext=md]
7+
- id: end-of-file-fixer
8+
- id: check-yaml
9+
# ----- Python formatting -----
10+
- repo: https://github.com/charliermarsh/ruff-pre-commit
11+
rev: v0.1.13
12+
hooks:
13+
# Run ruff linter.
14+
- id: ruff
15+
args:
16+
- --quiet
17+
- --fix
18+
# Run ruff formatter.
19+
- id: ruff-format
20+
# ----- repo maintenance -----
21+
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
22+
rev: v2.12.0
23+
hooks:
24+
- id: pretty-format-yaml
25+
args: [--autofix, --indent, '2']
26+
- repo: https://github.com/tox-dev/pyproject-fmt
27+
rev: 1.6.0
28+
hooks:
29+
- id: pyproject-fmt
30+
- repo: https://github.com/abravalheri/validate-pyproject
31+
rev: v0.15
32+
hooks:
33+
- id: validate-pyproject

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ of a simple setup:
1010

1111
```yaml
1212
steps:
13-
- uses: CagtayFabry/pydeps2env@v0.2.2
13+
- uses: CagtayFabry/pydeps2env@v0.3.0
1414
```
1515
1616
```toml
@@ -27,17 +27,17 @@ test = ["pytest"]
2727
pip_only = ["bidict"]
2828
```
2929

30-
The default parameters will output this sorted `environment.yml`:
30+
The default parameters will output this sorted `environment.yml` (note that the `python` dependency will always be the first item on the list):
3131

3232
```yaml
3333
channels:
3434
- defaults
3535
dependencies:
36+
- python>=3.8,<3.10
3637
- boltons
3738
- IPython
3839
- numpy>=1.20
3940
- pandas>=1.0
40-
- python>=3.8,<3.10
4141
```
4242
4343
A full output with options `--setup_requires include --extras test pip_only --pip bidict`
@@ -46,12 +46,12 @@ A full output with options `--setup_requires include --extras test pip_only --pi
4646
channels:
4747
- defaults
4848
dependencies:
49+
- python>=3.8,<3.10
4950
- boltons
5051
- IPython
5152
- numpy>=1.20
5253
- pandas>=1.0
5354
- pytest
54-
- python>=3.8,<3.10
5555
- setuptools>=40.9.0
5656
- setuptools_scm
5757
- wheel
@@ -65,15 +65,15 @@ To customize the output the input options are available to the action:
6565

6666
### file
6767

68-
Specify the location of the `'setup.cfg'` or `'pyproject.toml` file to parse. (defaults to `'setup.cfg'`)
68+
Specify the location of the `'setup.cfg'` or `'pyproject.toml'` file to parse. (defaults to `'pyproject.toml'`)
6969

7070
### output:
7171

7272
Specify the location and name of the conda environment file to generate. (defaults to `'environment.yml'`)
7373

7474
### channels:
7575

76-
List the conda channels to include in the environment file. (defaults to `'defaults'`)
76+
List the conda channels to include in the environment file. (defaults to `'conda-forge'`)
7777
Separate a list of multiple channels by spaces (e.g. `'conda-forge defaults'`).
7878

7979
### extras:
@@ -83,7 +83,7 @@ you would normally install with `pip install pkg[test]`)
8383

8484
### setup_requires:
8585

86-
If set to `'include'` the dependencies listed under `[options]:setup_requires` will be added to the environment (default
86+
If set to `'include'` the dependencies listed under `[options:setup_requires]` will be added to the environment (default
8787
is `'omit'` so no setup dependencies will be installed).
8888

8989
### pip
@@ -123,12 +123,12 @@ channels:
123123
- conda-forge
124124
- defaults
125125
dependencies:
126+
- python>=3.8,<3.10
126127
- boltons
127128
- IPython
128129
- numpy>=1.20
129130
- pandas>=1.0
130131
- pytest
131-
- python>=3.8,<3.10
132132
- setuptools>=40.9.0
133133
- setuptools_scm
134134
- wheel

action.yml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
name: 'pydeps2env'
2-
description: 'create conda environment file from python project dependencies'
1+
name: pydeps2env
2+
description: create conda environment file from python project dependencies
33
inputs:
44
file:
55
description: >-
66
Specify the location of the 'setup.cfg' file to parse. (defaults to 'setup.cfg')
77
required: true
8-
default: 'setup.cfg'
8+
default: setup.cfg
99
output:
1010
description: >-
1111
Specify the location and name of the conda environment file to generate. (defaults to 'environment.yml')
1212
required: true
13-
default: 'environment.yml'
13+
default: environment.yml
1414
channels:
1515
description: >-
1616
List the conda channels to include in the environment file. (defaults to 'defaults')
1717
Separate a list of multiple channels by spaces (e.g. 'conda-forge defaults').
1818
required: true
19-
default: 'defaults'
19+
default: defaults
2020
extras:
2121
description: >-
2222
Specify one or more optional [extras_require] sections to add to the environment
@@ -27,24 +27,24 @@ inputs:
2727
if set to 'include' the dependencies listed under [options]:setup_requires will be added to the environment
2828
(default is 'omit' so no setup dependencies will be installed)
2929
required: false
30-
default: 'omit'
30+
default: omit
3131
pip:
3232
description: >-
3333
List of packages to install via pip instead of conda.
3434
The dependencies will be listet under the pip section in the environment file.
3535
required: false
3636
runs:
37-
using: "composite"
37+
using: composite
3838
steps:
39-
- name: create environment file
40-
run: >
41-
pip3 install tomli &&
42-
python3 $GITHUB_ACTION_PATH/create_conda_env_file.py ${{ inputs.file }} ${{ inputs.output }}
43-
--channels ${{ inputs.channels }}
44-
--extras ${{ inputs.extras }}
45-
--setup_requires ${{ inputs.setup_requires }}
46-
--pip ${{ inputs.pip }}
47-
shell: bash
48-
- name: show environment file
49-
run: cat ${{ inputs.output }}
50-
shell: bash
39+
- name: create environment file
40+
run: >
41+
pip3 install tomli packaging pyyaml &&
42+
python3 $GITHUB_ACTION_PATH/pydeps2env/generate_environment.py ${{ inputs.file }} ${{ inputs.output }}
43+
--channels ${{ inputs.channels }}
44+
--extras ${{ inputs.extras }}
45+
--setup_requires ${{ inputs.setup_requires }}
46+
--pip ${{ inputs.pip }}
47+
shell: bash
48+
- name: show environment file
49+
run: cat ${{ inputs.output }}
50+
shell: bash

create_conda_env_file.py

Lines changed: 0 additions & 89 deletions
This file was deleted.

pydeps2env/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""pydeps2env: helps to generate conda environment files from python package dependencies."""
2+
3+
from .environment import Environment
4+
5+
__all__ = ["Environment"]
6+
7+
try:
8+
from ._version import __version__
9+
except ModuleNotFoundError:
10+
__version__ = ""

0 commit comments

Comments
 (0)