Skip to content

Commit

Permalink
rework as python package (#13)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
CagtayFabry committed Jan 31, 2024
1 parent d160bcb commit 1fcffc2
Show file tree
Hide file tree
Showing 10 changed files with 395 additions and 169 deletions.
55 changes: 36 additions & 19 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,40 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
config_file: ['./test/setup.cfg', './test/pyproject.toml']
config_file: [./test/setup.cfg, ./test/pyproject.toml]
steps:
- uses: actions/checkout@v3
- name: run local action code
uses: ./
with:
file: ${{ matrix.config_file }}
output: 'environment_test.yml'
channels: 'conda-forge defaults'
extras: 'test pip_only'
setup_requires: 'include'
pip: 'bidict'
- uses: mamba-org/setup-micromamba@v1.4.3
with:
environment-file: ./environment_test.yml
environment-name: demo
init-shell: >-
bash
powershell
cache-environment: true
- uses: actions/checkout@v4
- name: run local action code
uses: ./
with:
file: ${{ matrix.config_file }}
output: environment_test.yml
channels: conda-forge defaults
extras: test pip_only
setup_requires: include
pip: bidict
- uses: mamba-org/setup-micromamba@v1.8.0
with:
environment-file: ./environment_test.yml
environment-name: demo
init-shell: >-
bash
powershell
cache-environment: true

test_script:
name: create test env
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
config_file: [./test/setup.cfg, ./test/pyproject.toml]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: pip install package
run: pip install .
- name: test cmd script
run: pydeps2env ${{ matrix.config_file }} output.yaml -c defaults --extras test -b include --pip pandas
52 changes: 32 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/psf/black
rev: 22.1.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
args: [--max-line-length=88]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: end-of-file-fixer
- id: check-yaml
# ----- Python formatting -----
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.13
hooks:
# Run ruff linter.
- id: ruff
args:
- --quiet
- --fix
# Run ruff formatter.
- id: ruff-format
# ----- repo maintenance -----
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.12.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, '2']
- repo: https://github.com/tox-dev/pyproject-fmt
rev: 1.6.0
hooks:
- id: pyproject-fmt
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.15
hooks:
- id: validate-pyproject
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ of a simple setup:

```yaml
steps:
- uses: CagtayFabry/pydeps2env@v0.2.2
- uses: CagtayFabry/pydeps2env@v0.3.0
```
```toml
Expand All @@ -27,17 +27,17 @@ test = ["pytest"]
pip_only = ["bidict"]
```

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

```yaml
channels:
- defaults
dependencies:
- python>=3.8,<3.10
- 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`
Expand All @@ -46,12 +46,12 @@ A full output with options `--setup_requires include --extras test pip_only --pi
channels:
- defaults
dependencies:
- python>=3.8,<3.10
- boltons
- IPython
- numpy>=1.20
- pandas>=1.0
- pytest
- python>=3.8,<3.10
- setuptools>=40.9.0
- setuptools_scm
- wheel
Expand All @@ -65,15 +65,15 @@ To customize the output the input options are available to the action:

### file

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

### output:

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

### channels:

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

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

### setup_requires:

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

### pip
Expand Down Expand Up @@ -123,12 +123,12 @@ channels:
- conda-forge
- defaults
dependencies:
- python>=3.8,<3.10
- boltons
- IPython
- numpy>=1.20
- pandas>=1.0
- pytest
- python>=3.8,<3.10
- setuptools>=40.9.0
- setuptools_scm
- wheel
Expand Down
38 changes: 19 additions & 19 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
name: 'pydeps2env'
description: 'create conda environment file from python project dependencies'
name: pydeps2env
description: create conda environment file from python project dependencies
inputs:
file:
description: >-
Specify the location of the 'setup.cfg' file to parse. (defaults to 'setup.cfg')
required: true
default: 'setup.cfg'
default: setup.cfg
output:
description: >-
Specify the location and name of the conda environment file to generate. (defaults to 'environment.yml')
required: true
default: 'environment.yml'
default: environment.yml
channels:
description: >-
List the conda channels to include in the environment file. (defaults to 'defaults')
Separate a list of multiple channels by spaces (e.g. 'conda-forge defaults').
required: true
default: 'defaults'
default: defaults
extras:
description: >-
Specify one or more optional [extras_require] sections to add to the environment
Expand All @@ -27,24 +27,24 @@ inputs:
if set to 'include' the dependencies listed under [options]:setup_requires will be added to the environment
(default is 'omit' so no setup dependencies will be installed)
required: false
default: 'omit'
default: omit
pip:
description: >-
List of packages to install via pip instead of conda.
The dependencies will be listet under the pip section in the environment file.
required: false
runs:
using: "composite"
using: composite
steps:
- name: create environment file
run: >
pip3 install tomli &&
python3 $GITHUB_ACTION_PATH/create_conda_env_file.py ${{ inputs.file }} ${{ inputs.output }}
--channels ${{ inputs.channels }}
--extras ${{ inputs.extras }}
--setup_requires ${{ inputs.setup_requires }}
--pip ${{ inputs.pip }}
shell: bash
- name: show environment file
run: cat ${{ inputs.output }}
shell: bash
- name: create environment file
run: >
pip3 install tomli packaging pyyaml &&
python3 $GITHUB_ACTION_PATH/pydeps2env/generate_environment.py ${{ inputs.file }} ${{ inputs.output }}
--channels ${{ inputs.channels }}
--extras ${{ inputs.extras }}
--setup_requires ${{ inputs.setup_requires }}
--pip ${{ inputs.pip }}
shell: bash
- name: show environment file
run: cat ${{ inputs.output }}
shell: bash
89 changes: 0 additions & 89 deletions create_conda_env_file.py

This file was deleted.

10 changes: 10 additions & 0 deletions pydeps2env/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""pydeps2env: helps to generate conda environment files from python package dependencies."""

from .environment import Environment

__all__ = ["Environment"]

try:
from ._version import __version__
except ModuleNotFoundError:
__version__ = ""
Loading

0 comments on commit 1fcffc2

Please sign in to comment.