Skip to content

Commit

Permalink
update tests and local pip handling
Browse files Browse the repository at this point in the history
  • Loading branch information
CagtayFabry committed May 21, 2024
1 parent a46462b commit aba23cb
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 13 deletions.
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/
31 changes: 26 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,33 @@ 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
```

## 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 +125,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
2 changes: 1 addition & 1 deletion pydeps2env/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def _get_dependencies(
if (
not isinstance(r, Requirement) or r.name in _pip_packages
) and r.name not in remove:
pip.append(str(r))
pip.append(str(r) if not r.url else f"{r.name}@ {r.url}")
pip.sort(key=str.lower)

return deps, pip
Expand Down
8 changes: 8 additions & 0 deletions test/local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
channels:
- conda-forge
dependencies:
- python>3.7
- pydeps2env>=1.0.0
- pip
- pip:
- testproject @ file:/..//test_package
17 changes: 16 additions & 1 deletion test/test_environment.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pytest
from pydeps2env import Environment
from pydeps2env import Environment, create_environment

_inputs = [
"./test/pyproject.toml[test]",
"./test/setup.cfg[test]",
"./test/requirements.txt",
"./test/environment.yaml",
"./test/local.yaml",
"https://raw.githubusercontent.com/BAMWelDX/weldx/master/pyproject.toml[test]",
"https://github.com/BAMWelDX/weldx/blob/master/pyproject.toml[test]",
"https://raw.githubusercontent.com/BAMWelDX/weldx/v0.3.2/setup.cfg[test]",
Expand Down Expand Up @@ -35,3 +36,17 @@ def test_init(
assert (
"pydeps2env@ git+https://github.com/CagtayFabry/pydeps2env.git" in pip
)


def test_multiple_sources():
env = create_environment(_inputs, extras=["test"], pip=["urllib3", "pandas"])

for req in ["python", "pydeps2env", "testproject", "urllib3", "pytest"]:
assert req in env.requirements

for req in ["testproject", "pydeps2env", "requests", "pandas"]:
assert req in env.pip_packages

conda, pip = env._get_dependencies()
assert "pydeps2env@ git+https://github.com/CagtayFabry/pydeps2env.git" in pip
assert "testproject@ file:/..//test_package" in pip
31 changes: 31 additions & 0 deletions test/test_package/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = [
"setuptools>=64",
"setuptools-scm[toml]>=6.2",
]

[project]
name = "testproject"
version = "0.1.0"
description = "A stub package to test local dependency parsing and installation."
authors = [
{ name = "Çağtay Fabry", email = "[email protected]" },
]
requires-python = ">=3.9"
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"bidict",
]
7 changes: 7 additions & 0 deletions test/test_package/testproject/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Testproject."""

CONST = "A CONSTANT VALUE"


def func():
return CONST

0 comments on commit aba23cb

Please sign in to comment.