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

Commit

Permalink
Merge pull request #31 from dephell/travis-command
Browse files Browse the repository at this point in the history
Travis command
  • Loading branch information
orsinium committed Apr 21, 2019
2 parents cb9fe20 + 2b8ae73 commit 2f671a7
Show file tree
Hide file tree
Showing 58 changed files with 442 additions and 78 deletions.
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
+ Manage packages: [install](https://dephell.readthedocs.io/en/latest/cmd-package-install.html), [list](https://dephell.readthedocs.io/en/latest/cmd-package-list.html), [search](https://dephell.readthedocs.io/en/latest/cmd-package-search.html) on PyPI.
+ [Build](https://dephell.readthedocs.io/en/latest/cmd-project-build.html) packages (to upload on PyPI), [test](https://dephell.readthedocs.io/en/latest/cmd-project-test.html), [bump project version](https://dephell.readthedocs.io/en/latest/cmd-project-bump.html).
+ [Discover licenses](https://dephell.readthedocs.io/en/latest/cmd-deps-licenses.html) of all project dependencies, show [outdated](https://dephell.readthedocs.io/en/latest/cmd-deps-outdated.html) packages, [find security issues](https://dephell.readthedocs.io/en/latest/cmd-deps-audit.html).
+ Generate [.editorconfig](https://dephell.readthedocs.io/en/latest/cmd-generate-editorconfig.html), [LICENSE](https://dephell.readthedocs.io/en/latest/cmd-generate-license.html), [AUTHORS](https://dephell.readthedocs.io/en/latest/cmd-generate-authors.html).
+ Generate [.editorconfig](https://dephell.readthedocs.io/en/latest/cmd-generate-editorconfig.html), [LICENSE](https://dephell.readthedocs.io/en/latest/cmd-generate-license.html), [AUTHORS](https://dephell.readthedocs.io/en/latest/cmd-generate-authors.html), [.travis.yml](https://dephell.readthedocs.io/en/latest/cmd-generate-travis.html).

See [documentation](https://dephell.readthedocs.io/) for more details.

Expand All @@ -26,6 +26,26 @@ python3 -m pip install --user dephell[full]

See [installation documentation](https://dephell.readthedocs.io/en/latest/installation.html) for better ways.

## Supported formats

1. Archives:
1. [*.egg-info](https://setuptools.readthedocs.io/en/latest/formats.html) (`egginfo`)
1. [*.tar.gz](https://packaging.python.org/glossary/#term-distribution-package) (`sdist`)
1. [*.whl](https://pythonwheels.com) (`wheel`)
1. [pip](https://pip.pypa.io/en/stable/):
1. [requirements.txt](https://pip.pypa.io/en/stable/user_guide/#requirements-files) (`pip`)
1. [requirements.lock](https://nvie.com/posts/pin-your-packages/) (`piplock`)
1. [pipenv](https://pipenv.readthedocs.io/en/latest/):
1. [Pipfile](https://github.com/pypa/pipfile) (`pipfile`)
1. [Pipfile.lock](https://stackoverflow.com/a/49867443/8704691) (`pipfilelock`)
1. [poetry](https://github.com/sdispater/poetry):
1. [pyproject.toml](https://poetry.eustace.io/docs/pyproject/) (`poetry`)
1. [poetry.lock](https://poetry.eustace.io/docs/basic-usage/#installing-without-poetrylock) (`poetrylock`)
1. Other:
1. [setup.py](https://docs.python.org/3/distutils/setupscript.html) (`setuppy`)
1. [pyproject.toml build-system requires](https://www.python.org/dev/peps/pep-0518/#build-system-table) (`pyproject`)
1. Installed packages (`installed`). It works like [pip freeze](https://pip.pypa.io/en/stable/reference/pip_freeze/). Dephell can only read from this format, of course. If you want to install packages, use [install command](cmd-deps-install).

## Usage

First of all, install DepHell and activate autocomplete:
Expand Down Expand Up @@ -209,3 +229,21 @@ INFO builded
Now, we can upload these packages on [PyPI](https://pypi.org/) with [twine](https://github.com/pypa/twine/).

This is some of the most useful commands. See [documentation](https://dephell.readthedocs.io/) for more details.

## Compatibility

DepHell tested on Linux and Mac OS X with Python 3.5, 3.6, 3.7. And one of the coolest things that DepHell ran by DepHell on Travis CI.

## How can I help

1. Star project on Github. Developers believe in the stars.
1. Tell your fellows that [Gram](http://github.com/orsinium) made [cool thing](https://github.com/dephell/dephell) for you.
1. [Open an issue](https://github.com/dephell/dephell/issues/new) if you have thoughts how to make DepHell better.
1. Things that you can contribute in any project in [DepHell ecosystem](https://github.com/dephell):
1. Fix grammar and typos.
1. Document new things.
1. Tests, we always need more tests.
1. Make READMEs more nice and friendly.
1. Anything what you want. If it is a new feature, please, open an issue before writing code.

Thank you :heart:
6 changes: 4 additions & 2 deletions dephell/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
from ._downloads import get_downloads_by_category, get_total_downloads
from ._editorconfig import make_editorconfig
from ._entrypoints import get_entrypoints
from ._git import git_tag, git_commit
from ._git import git_commit, git_tag
from ._json import make_json
from ._package import get_package, get_packages, get_resolver
from ._python import get_python, get_python_env
from ._roman import arabic2roman, roman2arabic
from ._shutil import get_path_size, format_size
from ._shutil import format_size, get_path_size
from ._travis import make_travis
from ._venv import get_venv
from ._version import bump_file, bump_project, bump_version, get_version_from_file, get_version_from_project

Expand Down Expand Up @@ -42,6 +43,7 @@
'make_bash_autocomplete',
'make_editorconfig',
'make_json',
'make_travis',
'make_zsh_autocomplete',
'read_dotenv',
'roman2arabic',
Expand Down
1 change: 1 addition & 0 deletions dephell/actions/_dotenv.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# built-in
import shlex
from codecs import decode
from pathlib import Path
Expand Down
2 changes: 1 addition & 1 deletion dephell/actions/_entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from logging import getLogger
from typing import Tuple

# project
# external
from dephell_venvs import VEnv

# app
Expand Down
1 change: 1 addition & 0 deletions dephell/actions/_git.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# built-in
import subprocess
from logging import getLogger
from pathlib import Path
Expand Down
6 changes: 3 additions & 3 deletions dephell/actions/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ def make_json(data, key: str = None, sep: Optional[str] = '-') -> str:
json_params = dict(indent=2, sort_keys=True, ensure_ascii=False)
# print all config
if not key:
return json.dumps(data, **json_params)
return json.dumps(data, **json_params) # type: ignore

if sep is None:
return json.dumps(data[key], **json_params)
return json.dumps(data[key], **json_params) # type: ignore

keys = key.replace('.', sep).split(sep)
value = reduce(getitem, keys, data)
# print config section
if isinstance(value, (dict, list)):
return json.dumps(value, **json_params)
return json.dumps(value, **json_params) # type: ignore

# print one value
return str(value)
2 changes: 1 addition & 1 deletion dephell/actions/_package.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# built-in
from typing import List, Iterable
from typing import Iterable, List

# app
from ..controllers import Resolver
Expand Down
1 change: 1 addition & 0 deletions dephell/actions/_shutil.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# built-in
from os.path import getsize
from pathlib import Path

Expand Down
102 changes: 102 additions & 0 deletions dephell/actions/_travis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# built-in
from typing import Any, Dict, Optional


HEADER = """
# Config for Travis CI, tests powered by DepHell.
# https://travis-ci.org/
# https://github.com/dephell/dephell
language: python
before_install:
# show a little bit more information about environment
- sudo apt-get install -y tree
- env
- tree
# install DepHell
# https://github.com/travis-ci/travis-ci/issues/8589
- curl https://raw.githubusercontent.com/dephell/dephell/master/install.py | /opt/python/3.6/bin/python
- dephell inspect self
install:
- dephell venv create --env=$ENV --python="/opt/python/$TRAVIS_PYTHON_VERSION/bin/python"
- dephell deps install --env=$ENV
script:
- dephell venv run --env=$ENV
matrix:
"""

PYTEST = """
- python: "3.5"
env: ENV={env}
- python: "3.6"
env: ENV={env}
- python: "3.7-dev"
env: ENV={env}
- python: "pypy3.5"
env: ENV={env}
- os: osx
language: generic
env: ENV={env}
before_install:
- curl https://raw.githubusercontent.com/dephell/dephell/master/install.py | /usr/local/bin/python3
- dephell inspect self
install:
- dephell venv create --env=$ENV --python=/usr/local/bin/python3 --level=DEBUG --traceback
- dephell deps install --env=$ENV --level=DEBUG --traceback
"""

OTHER = """
- python: "3.6"
env: ENV={env}
"""

LOCKFILE = """
allow_failures:
- name: security
- name: outdated
include:
- name: security
install:
- "true"
script:
- dephell deps audit
- name: outdated
install:
- "true"
script:
- dephell deps outdated
"""


def make_travis(config: Dict[str, Dict[str, Any]]) -> Optional[str]:
content = HEADER.strip()
locked = 'lock' in config.get('main', {}).get('to', {}).get('format', '')
content += LOCKFILE if locked else '\n include:\n'

tested = False
for env, section in config.items():
if 'command' not in section:
continue
if 'from' not in section and 'to' not in section:
continue
if 'pypy' in section.get('python', ''):
continue

executable = section['command'].split()[0]
if executable in ('sphinx-build', 'twine'):
continue

if executable == 'pytest':
content += PYTEST.format(env=env)
else:
content += OTHER.format(env=env)
tested = True

if not locked and not tested:
return None

return content
2 changes: 1 addition & 1 deletion dephell/actions/_venv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# built-in
from pathlib import Path

# project
# external
from dephell_venvs import VEnv, VEnvs

# app
Expand Down
3 changes: 3 additions & 0 deletions dephell/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .generate_config import GenerateConfigCommand
from .generate_editorconfig import GenerateEditorconfigCommand
from .generate_license import GenerateLicenseCommand
from .generate_travis import GenerateTravisCommand
from .inspect_config import InspectConfigCommand
from .inspect_gadget import InspectGadgetCommand
from .inspect_self import InspectSelfCommand
Expand Down Expand Up @@ -52,6 +53,7 @@
'GenerateConfigCommand',
'GenerateEditorconfigCommand',
'GenerateLicenseCommand',
'GenerateTravisCommand',
'InspectConfigCommand',
'InspectGadgetCommand',
'InspectSelfCommand',
Expand Down Expand Up @@ -92,6 +94,7 @@
'generate config': GenerateConfigCommand,
'generate editorconfig': GenerateEditorconfigCommand,
'generate license': GenerateLicenseCommand,
'generate travis': GenerateTravisCommand,
'inspect config': InspectConfigCommand,
'inspect self': InspectSelfCommand,
'inspect venv': InspectVenvCommand,
Expand Down
2 changes: 1 addition & 1 deletion dephell/commands/generate_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from getpass import getuser
from pathlib import Path

# project
# external
from dephell_licenses import licenses

# app
Expand Down
53 changes: 53 additions & 0 deletions dephell/commands/generate_travis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# built-in
from argparse import ArgumentParser
from pathlib import Path

# external
import tomlkit

# app
from ..actions import make_travis
from ..config import builders
from .base import BaseCommand


class GenerateTravisCommand(BaseCommand):
"""Create .travis.yml for DepHell-based project.
https://dephell.readthedocs.io/en/latest/cmd-generate-travis.html
https://docs.travis-ci.com/user/languages/python/
https://docs.travis-ci.com/user/customizing-the-build
"""
@classmethod
def get_parser(cls) -> ArgumentParser:
parser = ArgumentParser(
prog='dephell generate travis',
description=cls.__doc__,
)
builders.build_config(parser)
builders.build_output(parser)
builders.build_other(parser)
return parser

def __call__(self) -> bool:
if self.args.config:
path = Path(self.args.config)
else:
path = Path(self.config['project']) / 'pyproject.toml'
if not path.exists():
self.logger.error('cannot generate .travis.yml without config')
return False

with path.open('r', encoding='utf8') as stream:
config = tomlkit.parse(stream.read())
config = dict(config['tool']['dephell'])
content = make_travis(config=config)
if content is None:
self.logger.error('cannot find appreciate envs in config')
return False

path = Path(self.config['project']) / '.travis.yml'
path.write_text(content)
self.logger.info('Travis CI config (.travis.yml) generated')
return True
2 changes: 1 addition & 1 deletion dephell/commands/inspect_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# app
from ..__version__ import __version__
from ..actions import make_json, get_path_size, format_size
from ..actions import format_size, get_path_size, make_json
from ..config import builders
from ..constants import DEPHELL_ECOSYSTEM
from ..converters import InstalledConverter
Expand Down
2 changes: 1 addition & 1 deletion dephell/commands/inspect_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dephell_shells import Shells

# app
from ..actions import get_venv, make_json, get_path_size, format_size
from ..actions import format_size, get_path_size, get_venv, make_json
from ..config import builders
from .base import BaseCommand

Expand Down
2 changes: 1 addition & 1 deletion dephell/commands/jail_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from argparse import REMAINDER, ArgumentParser
from pathlib import Path

# project
# external
from dephell_venvs import VEnvs

# app
Expand Down
6 changes: 2 additions & 4 deletions dephell/commands/jail_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
from pathlib import Path

# external
from packaging.utils import canonicalize_name

# project
from dephell_venvs import VEnvs
from packaging.utils import canonicalize_name

# app
from ..config import builders
Expand All @@ -29,7 +27,7 @@ def get_parser(cls) -> ArgumentParser:
builders.build_venv(parser)
builders.build_output(parser)
builders.build_other(parser)
parser.add_argument('name', help='jails names to uninstall')
parser.add_argument('name', nargs='+', help='jails names to uninstall')
return parser

def __call__(self) -> bool:
Expand Down

0 comments on commit 2f671a7

Please sign in to comment.