Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
Merge branch 'commands-docs'
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Mar 28, 2019
2 parents d29aede + 4c4f5e5 commit 9adcde7
Show file tree
Hide file tree
Showing 26 changed files with 488 additions and 47 deletions.
6 changes: 3 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ indent_size = 4
indent_style = space
indent_size = 4

[*.ini]
[*.{ini,toml}]
indent_style = space
indent_size = 4

[*.{json,yml,yaml,toml}]
[*.{json,yml,yaml}]
indent_style = space
indent_size = 2
indent_size = 2
21 changes: 17 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
MIT License
MIT License

Copyright (c) 2019 Gram

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 9 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
# ![DepHell](./assets/logo.png)

Dependency resolution for Python.
**DepHell** -- dependency management for Python.

+ Manage dependencies: convert between formats, install, lock, resolve conflicts.
+ Manage virtual environments: create, remove, run shell, run commands inside.
+ Install CLI tools into isolated environments.
+ Build packages (to upload on PyPI).
+ Discover licenses of all project dependencies.
+ Generate .editorconfig, LICENSE, AUTHORS.

## Installation

```bash
sudo pip3 install dephell
```

## Python lib usage

```python
from dephell import PIPConverter, Requirement

loader = PIPConverter(lock=False)
resolver = loader.load_resolver(path='requirements.in')

resolver.resolve()
reqs = Requirement.from_graph(resolver.graph, lock=True)

dumper = PIPConverter(lock=True)
dumper.dump(reqs=reqs, path='requirements.txt')
python3 -m pip install --user dephell
```
8 changes: 6 additions & 2 deletions dephell/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from functools import reduce
from logging import getLogger
from operator import getitem
from typing import Optional

# app
from ..config import config
Expand Down Expand Up @@ -44,12 +45,15 @@ def validate(self):
return is_valid

@staticmethod
def get_value(data, key):
def get_value(data, key, sep: Optional[str] = '-'):
# print all config
if not key:
return json.dumps(data, indent=2, sort_keys=True)

keys = key.split('-')
if sep is None:
return json.dumps(data[key], indent=2, sort_keys=True)

keys = key.split(sep)
value = reduce(getitem, keys, data)
# print config section
if type(value) is dict:
Expand Down
8 changes: 4 additions & 4 deletions dephell/commands/deps_licenses.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# built-in
import json
from argparse import ArgumentParser
from collections import defaultdict

Expand All @@ -23,6 +22,7 @@ def get_parser(cls):
builders.build_api(parser)
builders.build_output(parser)
builders.build_other(parser)
parser.add_argument('key', nargs='*')
return parser

def __call__(self):
Expand All @@ -49,10 +49,10 @@ def __call__(self):
licenses = defaultdict(set)
for dep in resolver.graph:
if dep.license:
license = dep.license if isinstance(dep.license, str) else dep.license.name
license = dep.license if isinstance(dep.license, str) else dep.license.id
licenses[license].add(dep.name)
else:
licenses['Unknown License'].add(dep.name)
licenses['Unknown'].add(dep.name)
licenses = {name: sorted(deps) for name, deps in licenses.items()}
print(json.dumps(licenses, sort_keys=True, indent=2))
print(self.get_value(data=licenses, key=' '.join(self.args.key), sep=None))
return True
4 changes: 2 additions & 2 deletions dephell/commands/generate_editorconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
RULES = (
('*.py', ('indent_style = space', 'indent_size = 4')),
('*.{md,rst,txt}', ('indent_style = space', 'indent_size = 4')),
('*.ini', ('indent_style = space', 'indent_size = 4')),
('*.{ini,toml}', ('indent_style = space', 'indent_size = 4')),

('*.js', ('indent_style = space', 'indent_size = 2')),
('*.{json,yml,yaml,toml}', ('indent_style = space', 'indent_size = 2')),
('*.{json,yml,yaml}', ('indent_style = space', 'indent_size = 2')),
('*.{html,j2}', ('indent_style = space', 'indent_size = 2')),

('Makefile', ('indent_style = tab')),
Expand Down
4 changes: 2 additions & 2 deletions dephell/commands/generate_license.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# built-in
from argparse import ArgumentParser, REMAINDER
from argparse import ArgumentParser
from datetime import datetime
from getpass import getuser
from pathlib import Path
Expand All @@ -22,7 +22,7 @@ def get_parser(cls):
builders.build_config(parser)
builders.build_output(parser)
builders.build_other(parser)
parser.add_argument('name', nargs=REMAINDER, help='package to install')
parser.add_argument('name', nargs=1, help='licnse name')
return parser

def __call__(self):
Expand Down
1 change: 1 addition & 0 deletions dephell/config/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def _expand_converter(text: str) -> Dict[str, str]:
content = None if not path.is_file() else path.read_text()
if converter.can_parse(path=path, content=content):
return {'format': text, 'path': str(path)}
raise LookupError('cannot find file for converter: ' + str(text))

# if passed only filename
path = Path(text)
Expand Down
10 changes: 10 additions & 0 deletions dephell/converters/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def loads(self, content) -> RootDependency:
if path.exists():
root.readme = Readme(path=path)

# read links
for field in ('homepage', 'repository', 'documentation'):
if field in section:
root.links[field] = section[field]

# read entrypoints
root.entrypoints = []
for name, content in section.get('scripts', {}).items():
Expand Down Expand Up @@ -121,6 +126,11 @@ def dumps(self, reqs, project: RootDependency, content=None) -> str:
elif field in section:
del section[field]

# write links
for name in ('homepage', 'repository', 'documentation'):
if name in project.links:
section[name] = project.links[name]

if project.authors:
section['authors'] = [str(author) for author in project.authors]
elif 'authors' in section:
Expand Down
2 changes: 1 addition & 1 deletion dephell/converters/poetrylock.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,6 @@ def _format_req(self, req):
if deps:
result['dependencies'] = tomlkit.table()
for dep in deps:
result['dependencies'][dep.name] = str(dep.constraint)
result['dependencies'][dep.name] = str(dep.constraint) or '*'

return result
2 changes: 1 addition & 1 deletion dephell/converters/setuppy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# DO NOT EDIT THIS FILE!
# This file has been autogenerated by dephell <3
# https://github.com/orsinium/dephell
# https://github.com/dephell/dephell
try:
from setuptools import setup
Expand Down
2 changes: 1 addition & 1 deletion docs/command-autocomplete.md → docs/cmd-autocomplete.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# autocomplete
# dephell autocomplete

Enable dephell autocompletion for current shell. Supported shells:

Expand Down
2 changes: 1 addition & 1 deletion docs/command-build.md → docs/cmd-build.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# build
# dephell build

Build package for project:

Expand Down
2 changes: 1 addition & 1 deletion docs/command-deps-convert.md → docs/cmd-deps-convert.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# deps convert
# dephell deps convert

Convert dependencies between formats. Dephell will automagically lock them if needed and resolve all conflicts.

Expand Down
11 changes: 11 additions & 0 deletions docs/cmd-deps-install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# dephell deps install

Install project dependencies.

Dependencies from `to` option will be used if available. This is because when you specified in config file source dependencies in `from` and locked dependencies in `to` then, of course, you want to install dependencies from lock file. However, if `to` (and `to-format` and `to-file`) isn't specified in the config and CLI arguments then `from` will be used.

Place to install lookup:

1. If some virtual environment already active in the current shell then this environment will be used.
1. If virtual environment for current project and environment exists then this virtual environment will be used. This is the reason why you have to [create virtual environment](cmd-venv-create) before dependencies installation.
1. If virtual environment isn't found then your current python will be used.
49 changes: 49 additions & 0 deletions docs/cmd-deps-licenses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# dephell deps licenses

This command shows license for all your project's dependencies (from `from` section of current environment) in JSON format. Dephell detects the same license described in the different ways, like "MIT" and "MIT License", and combine these dependencies together. Dephell shows licenses **for all project's dependencies** including dependencies of dependencies.

```bash
$ dephell deps licenses

INFO resolved
{
"Apache-2.0": [
"aiofiles",
"aiohttp",
...
],
...
"Python Software Foundation License": [
"backports-weakref",
"editorconfig",
"typing",
"typing-extensions"
],
}
```

If you want to process this JSON to other tool disable dephell's helping output with `--level` and `--silent` arguments:

```bash
$ dephell deps licenses --level=WARNING --silent | jq --compact-output '."Apache-2.0"'
["aiofiles","aiohttp",...]
```

This example uses [jq](https://stedolan.github.io/jq/) to filter only one license from output. However, for simple filtering by license name you can just pass this name as positional argument in the command:

```bash
$ dephell deps licenses Apache-2.0

INFO resolved
[
"aiofiles",
"aiohttp",
...
]
```

## More info

1. [How dephell works with config and parameters](config)
1. [Full list of config parameters](params)
1. [Example of this command usage](use-licenses)
9 changes: 9 additions & 0 deletions docs/cmd-generate-authors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# dephell generate authors

This command looks into your git commits history, get list of all contributors, removes duplicates by e-mail and saves it into `AUTHORS` file.

```bash
$ dephell generate authors
```

Easy :)
14 changes: 14 additions & 0 deletions docs/cmd-generate-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# dephell generate config

This command scans project directory for known dependencies files, try to combine them into known most common combinations like `Pipfile + Pipfile.lock` and makes dephell config for them.

```bash
$ dephell generate config
```

Good for quick start.

## More info

1. [How dephell works with config and parameters](config)
1. [Full list of config parameters](params)
61 changes: 61 additions & 0 deletions docs/cmd-inspect-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# dephell inspect config

Shows current dephell config options. You can combine it with different arguments to inspect dephell behavior.

## Show all config

```bash
$ dephell inspect config
{
"bin": "/home/gram/.local/bin",
"bitbucket": "https://api.bitbucket.org/2.0",
"cache": {
"path": "/home/gram/.local/share/dephell/cache",
"ttl": 3600
},
"envs": [
"main"
],
...
"warehouse": "https://pypi.org/pypi/"
}
```

## Filter output

Show one section:

```bash
$ dephell inspect config from
{
"format": "poetry",
"path": "pyproject.toml"
}

```

Show one value:

```bash
$ dephell inspect config from-format
poetry

$ dephell inspect config warehouse
https://pypi.org/pypi/
```

## Combine it with arguments

```bash
$ dephell inspect config --from-path=lol from
{
"format": "poetry",
"path": "lol"
}

$ dephell inspect config --from=setup.py from
{
"format": "setuppy",
"path": "setup.py"
}
```
3 changes: 3 additions & 0 deletions docs/cmd-venv-create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# dephell venv create

Create virtual environment for current project and environment.

0 comments on commit 9adcde7

Please sign in to comment.