This repository has been archived by the owner on Jan 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from dephell/travis-command
Travis command
- Loading branch information
Showing
58 changed files
with
442 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.