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

Commit

Permalink
Ci (#26)
Browse files Browse the repository at this point in the history
+Travis CI
  • Loading branch information
orsinium committed Apr 14, 2019
1 parent d5673d4 commit 03eaab5
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 26 deletions.
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
language: python

before_install:
- sudo apt-get install -y tree
- env
- tree

# - curl https://raw.githubusercontent.com/dephell/dephell/master/install.py | /opt/python/3.6/bin/python
- /opt/python/3.6/bin/python install.py
install:
- dephell venv create --env=$ENV --python="/opt/python/$TRAVIS_PYTHON_VERSION/bin/python" --level=DEBUG
- dephell deps install --env=$ENV --level=DEBUG
script:
- dephell venv run --env=$ENV --level=DEBUG

matrix:
include:
- python: "3.5"
env: ENV=pytest
- python: "3.6"
env: ENV=pytest
- python: "3.7-dev"
env: ENV=pytest

- python: "3.6"
env: ENV=flake8
12 changes: 11 additions & 1 deletion dephell/commands/venv_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,18 @@ def __call__(self) -> bool:
if not result:
return False

if not executable.exists():
self.logge.error('package installed, but executable is not found')
return False

self.logger.info('running...')
result = subprocess.run([str(executable)] + command[1:])
return not result.returncode
if result.returncode != 0:
self.logger.error('command failed', extra=dict(code=result.returncode))
return False

self.logger.info('command successfully completed')
return True

def _install(self, name: str, python_path: Path) -> bool:
# resolve
Expand Down
2 changes: 1 addition & 1 deletion dephell/config/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def attach_file(self, path: str, env: str, silent: bool = False) -> Optional[dic

# get env
if env not in data:
raise KeyError('env not found')
raise KeyError('env `{}` not found'.format(env))
data = data[env]

self.attach(data)
Expand Down
2 changes: 1 addition & 1 deletion dephell/converters/egginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def load(self, path) -> RootDependency:
path = Path(str(path))
if path.is_dir():
# load from *.egg-info dir
if path.suffix == '.egg-info':
if (path / 'PKG-INFO').exists():
return self.load_dir(path)
# find *.egg-info in current dir
paths = list(path.glob('*.egg-info'))
Expand Down
2 changes: 1 addition & 1 deletion dephell/converters/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def dump(self, reqs, path: Path, project: RootDependency) -> None:
if isinstance(path, str):
path = Path(path)
if not path.name.endswith('.tar.gz'):
path /= '{}-{}.tar.gz'.format(project.name, str(project.version))
path /= '{}-{}.tar.gz'.format(project.name.replace('-', '_'), str(project.version))
path.parent.mkdir(exist_ok=True, parents=True)
if path.exists():
path.unlink()
Expand Down
61 changes: 42 additions & 19 deletions install.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,78 @@
# built-in
import subprocess
from pathlib import Path
from os import environ, pathsep
from venv import create


# install pip
try:
import pip # noQA: F401
except ImportError:
print('install pip')
from ensurepip import bootstrap
bootstrap()

try:
from pip._internal import main
except ImportError:
print('update pip')
from ensurepip import bootstrap
bootstrap(upgrade=True)

# get dephell's jail path
def get_data_dir() -> Path:
try:
from appdirs import user_data_dir
except ImportError:

try:
from appdirs import user_data_dir
except ImportError:
print('install appdirs')
main(['install', 'appdirs'])
from appdirs import user_data_dir
path = Path.home() / '.local' / 'share'
if path.exists():
return path / 'dephell'

try:
from pip._internal import main
except ImportError:
from pip import main

main(['install', 'appdirs'])
from appdirs import user_data_dir

return Path(user_data_dir('dephell'))


print('make venv')
path = Path(user_data_dir('dephell')) / 'venvs' / 'dephell'
path = get_data_dir() / 'venvs' / 'dephell'
create(str(path), with_pip=True)

print('install pip in venv')

print('update pip')
python_path = list(path.glob('*/python3'))[0]
result = subprocess.run([str(python_path), '-m', 'ensurepip'])
result = subprocess.run([str(python_path), '-m', 'pip', 'install', '-U', 'pip'])
if result.returncode != 0:
exit(result.returncode)


print('install dephell')
pip_path = list(path.glob('*/pip3'))[0]
result = subprocess.run([str(pip_path), 'install', 'dephell[full]'])
result = subprocess.run([str(python_path), '-m', 'pip', 'install', 'dephell[full]'])
if result.returncode != 0:
exit(result.returncode)


def get_bin_dir() -> Path:
path = Path.home() / '.local' / 'bin'
if path.exists():
return path
paths = [Path(path) for path in environ.get('PATH', '').split(pathsep)]
for path in paths:
if path.exists() and '.local' in path.parts:
return path
for path in paths:
if path.exists():
return path
raise LookupError('cannot find place to install binary', paths)


print('copy binary dephell')
local_path = pip_path.parent / 'dephell'
local_path = python_path.parent / 'dephell'
if not local_path.exists():
print('DepHell binary not found')
exit(1)
global_path = Path.home() / '.local' / 'bin' / 'dephell'
global_path = get_bin_dir() / 'dephell'
if global_path.exists() or global_path.is_symlink():
global_path.unlink()
global_path.symlink_to(local_path)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ from = {format = "poetry", path = "pyproject.toml"}
# copy files that requred for tests
tests = ["tests", "README.md"]
# run command `pytest`
command = "pytest -x tests/"
command = "pytest tests/"

# Install `docs` extra dependencies in the separated venv and run sphinx:
# $ dephell venv create --env=docs
Expand Down
2 changes: 1 addition & 1 deletion tests/test_commands/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ def test_build_command(temp_path: Path):
assert result is True
assert (temp_path / 'setup.py').exists()
assert (temp_path / 'my_package.egg-info' / 'PKG-INFO').exists()
assert (temp_path / 'dist' / 'my-package-0.1.0.tar.gz').exists()
assert (temp_path / 'dist' / 'my_package-0.1.0.tar.gz').exists()
assert (temp_path / 'dist' / 'my_package-0.1.0-py3-none-any.whl').exists()
2 changes: 1 addition & 1 deletion tests/test_converters/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_load_dump_load_deps(converter, path):
(converters.PoetryLockConverter(), './tests/requirements/poetry.lock.toml', []),
(converters.SetupPyConverter(), './tests/requirements/setup.py', []),
(converters.EggInfoConverter(), './tests/requirements/egg-info/', ['package', 'entrypoints']),
(converters.EggInfoConverter(), './tests/requirements/egg-info/', ['package', 'entrypoints', 'readme']),
(converters.WheelConverter(), './tests/requirements/wheel.whl', ['package', 'entrypoints']),
])
def test_load_dump_load_metainfo(converter, path, exclude):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_repositories/test_git_git.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# built-in
import asyncio
from pathlib import Path
from os import environ

import pytest

# project
from dephell.repositories.git.git import GitRepo
Expand All @@ -18,6 +21,7 @@ class Dep:
raw_name = 'DepHell'


@pytest.mark.skipif('TRAVIS_PYTHON_VERSION' in environ, reason='Travis CI has broken git repo')
def test_releases():
link = PatchedVCSLink(server=None, author=None, project=None, name='dephell')
repo = GitRepo(link)
Expand All @@ -31,6 +35,7 @@ def test_releases():
assert str(releases[1].version) == '0.1.5'


@pytest.mark.skipif('TRAVIS_PYTHON_VERSION' in environ, reason='Travis CI has broken git repo')
def test_deps():
link = PatchedVCSLink(server=None, author=None, project=None, name='dephell')
repo = GitRepo(link)
Expand All @@ -41,6 +46,7 @@ def test_deps():
assert set(dep.name for dep in deps) == {'attrs', 'cached-property', 'packaging', 'requests'}


@pytest.mark.skipif('TRAVIS_PYTHON_VERSION' in environ, reason='Travis CI has broken git repo')
def test_metaversion():
link = PatchedVCSLink(server=None, author=None, project=None, name='dephell')
repo = GitRepo(link)
Expand Down

0 comments on commit 03eaab5

Please sign in to comment.