Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add url handling #24

Merged
merged 23 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
on: [push, pull_request, workflow_dispatch]

jobs:
pytest:
name: pytest
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: pip install package
run: pip install .[test]
- name: run pytest
run: pytest

demo_job:
name: action
runs-on: ${{ matrix.os }}
Expand Down
167 changes: 167 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# custom folders
demo/

pydeps2env/_version.py

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
69 changes: 64 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 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 `pyproject.toml` or `setup.cfg` file.
Creates a conda `environment.yml` file from python package dependencies listed in on or multiple different source formats like `pyproject.toml`, `setup.cfg`, `environment.yaml` or `requirements.txt` files.

The project contains
- GitHub action
Expand Down Expand Up @@ -42,7 +42,7 @@ test = ["pytest"]
pip_only = ["bidict"]
```

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

```yaml
channels:
Expand Down Expand Up @@ -74,13 +74,71 @@ dependencies:
- bidict
```

## configuration options
## basic usage (python)

Create an `Environment` using Python and export it to an `environment.yaml` file.

```python
from pydeps2env import Environment
env = Environment("./test/pyproject.toml[doc]")
env.export("my_environment.yaml")
```

## basic usage (command line)

Combine multiple source files into a single environment file (including build dependencies).
Install pandas using `pip`.

```bash
pydeps2env ./test/setup.cfg ./test/pyproject.toml[doc] ./test/environment.yaml ./test/requirements.txt -o output.yaml -c defaults --extras test -b include --pip pandas
```

## advanced usage (definition file)

Users can store complex configurations in a single yaml file and create the desired output using `create_from_definition`.
Example definition file:

```yaml
# the target file to create
output: test-configuration.yaml
# default name of the environment
name: test-env
# conda channels to include
channels:
- conda-forge
- defaults
# list of source files that define sub environments
# these will be loaded as Environment()
sources:
- ./test/environment.yaml
- ./test/local.yaml
- ./test/pyproject.toml[doc]
- ./test/requirements.txt
- https://github.com/CagtayFabry/pydeps2env/blob/custom_deps/pyproject.toml
# extras to apply to all sources and packages
extras:
- test
# dependencies that should be removed after collection
remove:
- pyyaml
additional_requirements:
- urllib3
# include build system dependencies
# list of dependencies that must be pip installed (excluding auto-sorted depedencies like urls)
pip:
- urllib3
include_build_system: include
```

## configuration options (GitHub action)

To customize the output the input options are available to the action:

### files

Specify the location of the `'setup.cfg'` or `'pyproject.toml'` files to parse. (defaults to `'pyproject.toml'`)
Specify the location of the dependencies files to parse. (defaults to 'pyproject.toml')
Multiple files can be listed. This will result in a combined environment file.

### output:
Expand All @@ -105,7 +163,8 @@ is `'omit'` so no setup dependencies will be installed).

### pip
List of packages to install via `pip` instead of `conda`.
The dependencies will be listet under the `pip:` section in the environment file.
The dependencies will be listed under the `pip:` section in the environment file.
If a dependency is listed with its URN, it will always be installed via pip (e.g. `pydeps2env @ git+https://github.com/CagtayFabry/pydeps2env`)

## example

Expand Down
15 changes: 9 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ inputs:
files:
description: >-
Specify the location of the dependencies files to parse. (defaults to 'pyproject.toml')
Separate a list of multiple source files by spaces (e.g. 'pyproject.toml[test] requirements.txt').
required: true
default: pyproject.toml
output:
Expand All @@ -16,25 +17,27 @@ inputs:
default: environment.yml
channels:
description: >-
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').
required: true
default: defaults
default: conda-forge
extras:
description: >-
Specify one or more optional [extras_require] sections to add to the environment
(e.g. 'test' to include package that you would normally install with 'pip install pkg[test]')
Specify one or more optional [extras_require] sections to add to all source files (s.a.).
(e.g. 'test' to include package that you would normally install with 'pip install pkg[test]').
Note that for individual sources in 'files', the '[extra]' syntax is also possible.
required: false
build_system:
description: >-
if set to 'include' the dependencies listed under [build-system] or [options]:setup_requires will be added to the environment
(default is 'omit' so no setup dependencies will be installed)
if set to 'include' the dependencies listed under [build-system] (for 'pyproject.toml') or [options]:setup_requires (for 'setup.cfg') will be added to the environment
(default is 'omit' so no build system dependencies will be installed)
required: false
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.
If a dependency is listed with its URN, it will always be installed via pip (e.g. 'pydeps2env @ git+https://github.com/CagtayFabry/pydeps2env')
required: false
runs:
using: composite
Expand Down
12 changes: 11 additions & 1 deletion pydeps2env/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
"""pydeps2env: helps to generate conda environment files from python package dependencies."""

from .environment import Environment
from .generate_environment import (
create_environment,
create_environment_file,
create_from_definition,
)

__all__ = ["Environment"]
__all__ = [
"Environment",
"create_environment",
"create_environment_file",
"create_from_definition",
]

try:
from ._version import __version__
Expand Down
Loading