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

Commit

Permalink
Merge branch 'pypy'
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Apr 15, 2019
2 parents 03eaab5 + aafa872 commit d56a58a
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 20 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ dist/
build/
pip-wheel-metadata/

Pipfile.lock
poetry.lock
poetry.lock.toml
/Pipfile.lock
/poetry.lock
/poetry.lock.toml

.tox
.mypy_cache

.dephell_cache/
.dephell_report/

README.rst
setup.py
/README.rst
/setup.py
13 changes: 9 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
language: python

before_install:
# show a little bit more information about environment
- sudo apt-get install -y tree
- env
- tree

# install DepHell
# - curl https://raw.githubusercontent.com/dephell/dephell/master/install.py | /opt/python/3.6/bin/python
# https://github.com/travis-ci/travis-ci/issues/8589
- /opt/python/3.6/bin/python install.py
- dephell inspect self
install:
- dephell venv create --env=$ENV --python="/opt/python/$TRAVIS_PYTHON_VERSION/bin/python" --level=DEBUG
- dephell deps install --env=$ENV --level=DEBUG
- dephell venv create --env=$ENV --python="/opt/python/$TRAVIS_PYTHON_VERSION/bin/python" --level=DEBUG --traceback
- dephell deps install --env=$ENV --level=DEBUG --traceback
script:
- dephell venv run --env=$ENV --level=DEBUG
- dephell venv run --env=$ENV --level=DEBUG --traceback

matrix:
include:
Expand All @@ -21,6 +24,8 @@ matrix:
env: ENV=pytest
- python: "3.7-dev"
env: ENV=pytest
- python: "pypy3.5"
env: ENV=pytest

- python: "3.6"
env: ENV=flake8
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ![DepHell](./assets/logo.png)

[![MIT License](https://img.shields.io/pypi/l/dephell.svg)](https://github.com/dephell/dephell/blob/master/LICENSE)
[![Travis CI](https://travis-ci.org/dephell/dephell.svg?branch=master)](https://travis-ci.org/dephell/dephell)
[![Powered by DepHell](./assets/badge.svg)](./docs/badge.md)

**DepHell** -- dependency management for Python.
Expand Down
3 changes: 3 additions & 0 deletions dephell/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .package_downloads import PackageDownloadsCommand
from .package_install import PackageInstallCommand
from .package_list import PackageListCommand
from .package_releases import PackageReleasesCommand
from .package_search import PackageSearchCommand
from .package_show import PackageShowCommand
from .project_build import ProjectBuildCommand
Expand Down Expand Up @@ -56,6 +57,7 @@
'PackageDownloadsCommand',
'PackageInstallCommand',
'PackageListCommand',
'PackageReleasesCommand',
'PackageSearchCommand',
'PackageShowCommand',
'ProjectBuildCommand',
Expand Down Expand Up @@ -94,6 +96,7 @@
'package downloads': PackageDownloadsCommand,
'package install': PackageInstallCommand,
'package list': PackageListCommand,
'package releases': PackageReleasesCommand,
'package search': PackageSearchCommand,
'package show': PackageShowCommand,
'project build': ProjectBuildCommand,
Expand Down
8 changes: 8 additions & 0 deletions dephell/commands/inspect_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from ..__version__ import __version__
from ..actions import make_json, get_path_size, format_size
from ..config import builders
from ..constants import DEPHELL_ECOSYSTEM
from ..converters import InstalledConverter
from .base import BaseCommand


Expand All @@ -27,10 +29,16 @@ def get_parser(cls) -> ArgumentParser:
return parser

def __call__(self) -> bool:
installed = InstalledConverter().load(names=DEPHELL_ECOSYSTEM)
versions = dict()
for dep in installed.dependencies:
versions[dep.name] = str(dep.constraint).replace('=', '')

data = dict(
path=str(Path(__file__).parent.parent),
python=sys.executable,
version=__version__,
versions=versions,
cache=format_size(get_path_size(Path(self.config['cache']['path']))),
)
print(make_json(data=data, key=self.config.get('filter')))
Expand Down
43 changes: 43 additions & 0 deletions dephell/commands/package_releases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# built-in
from argparse import ArgumentParser

# app
from ..actions import get_package, make_json
from ..config import builders
from ..repositories import WareHouseRepo
from .base import BaseCommand


class PackageReleasesCommand(BaseCommand):
"""Show package releases.
https://dephell.readthedocs.io/en/latest/cmd-package-releases.html
"""
@classmethod
def get_parser(cls) -> ArgumentParser:
parser = ArgumentParser(
prog='dephell package releases',
description=cls.__doc__,
)
builders.build_config(parser)
builders.build_output(parser)
builders.build_api(parser)
builders.build_other(parser)
parser.add_argument('name', help='package name')
return parser

def __call__(self) -> bool:
dep = get_package(self.args.name)
repo = WareHouseRepo()
releases = repo.get_releases(dep)

data = []
for release in releases:
data.append(dict(
date=str(release.time.date()),
version=str(release.version),
python=str(release.python) if release.python else '*',
))

print(make_json(data=data, key=self.config.get('filter')))
return True
5 changes: 4 additions & 1 deletion dephell/commands/venv_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def __call__(self) -> bool:

self.logger.info('creating venv for project...', extra=dict(path=venv.path))
python = get_python(self.config)
self.logger.debug('choosen python', extra=dict(version=python.version))
self.logger.info('chosen python', extra=dict(
version=python.version,
path=str(python.path),
))
venv.create(python_path=python.path)
self.logger.info('venv created', extra=dict(path=venv.path))
return True
13 changes: 13 additions & 0 deletions dephell/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,16 @@ class JoinTypes(Enum):
calver='{}.{}'.format(date.today().year, date.today().month),
roman='I',
))


DEPHELL_ECOSYSTEM = (
'dephell_archive',
'dephell_discover',
'dephell_licenses',
'dephell_links',
'dephell_markers',
'dephell_pythons',
'dephell_shells',
'dephell_specifier',
'dephell_venvs',
)
23 changes: 18 additions & 5 deletions dephell/context_tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# built-in
import os
import sys
from contextlib import contextmanager


Expand Down Expand Up @@ -29,8 +30,20 @@ def nullcontext(value=None):
def env_var(key, value):
old_value = os.environ.get(key)
os.environ[key] = value
yield
if old_value is None:
del os.environ[key]
else:
os.environ[key] = old_value
try:
yield
finally:
if old_value is None:
del os.environ[key]
else:
os.environ[key] = old_value


@contextmanager
def override_argv(value):
old_value = sys.argv
sys.argv = value
try:
yield
finally:
sys.argv = old_value
2 changes: 1 addition & 1 deletion dephell/controllers/readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
readme = ''
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, '${fname}'), encoding='utf-8') as stream:
with open(os.path.join(here, '${fname}'), 'r', 'utf-8') as stream:
readme = stream.read()
"""

Expand Down
10 changes: 9 additions & 1 deletion dephell/converters/egginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,24 @@ def load(self, path) -> RootDependency:
return self.loads(stream.read())

def load_dir(self, *paths) -> RootDependency:
# drop duplicates
paths = list({str(path): path for path in paths}.values())
if not paths:
raise FileNotFoundError('cannot find egg-info')
# maybe it's possible, so we will have to process it
if len(paths) > 1:
min_parts = min(len(path.parts) for path in paths)
paths = [path for path in paths if len(path.parts) == min_parts]
if len(paths) > 1:
raise FileExistsError('too many egg-info', *paths)
raise FileExistsError('too many egg-info', paths)
path = paths[0]

# sometimes pypy stores only pkg-info as *.egg-info file
if not (path / 'PKG-INFO').exists():
with path.open('r') as stream:
content = stream.read()
return self.parse_info(content)

# pkg-info
with (path / 'PKG-INFO').open('r') as stream:
content = stream.read()
Expand Down
40 changes: 37 additions & 3 deletions dephell/converters/setuppy.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# built-in
from collections import defaultdict
from distutils.core import run_setup
from io import StringIO
from itertools import chain
from logging import getLogger
from pathlib import Path
from typing import Optional

# external
from dephell_specifier import RangeSpecifier
from packaging.requirements import Requirement
from setuptools.dist import Distribution

# app
from ..context_tools import chdir
Expand All @@ -27,6 +30,9 @@
fix_code = None


logger = getLogger('dephell.converters.setuppy')


TEMPLATE = """
# -*- coding: utf-8 -*-
Expand Down Expand Up @@ -65,8 +71,11 @@ def can_parse(self, path: Path, content: Optional[str] = None) -> bool:
@classmethod
def load(cls, path) -> RootDependency:
path = Path(str(path))
with chdir(path.parent):
info = run_setup(path.name)

info = cls._execute(path=path)
if info is None:
with chdir(path.parent):
info = run_setup(path.name)

root = RootDependency(
raw_name=cls._get(info, 'name'),
Expand Down Expand Up @@ -99,7 +108,7 @@ def load(cls, path) -> RootDependency:

# entrypoints
entrypoints = []
for group, content in getattr(info, 'entry_points', {}).items():
for group, content in (getattr(info, 'entry_points', {}) or {}).items():
for entrypoint in content:
entrypoints.append(EntryPoint.parse(text=entrypoint, group=group))
root.entrypoints = tuple(entrypoints)
Expand Down Expand Up @@ -215,6 +224,31 @@ def dumps(self, reqs, project: RootDependency, content=None) -> str:

# private methods

@staticmethod
def _execute(path: Path):
source = path.read_text('utf-8')
new_source = source.replace('setup(', '_dist = dict(')
if new_source == source:
logger.error('cannot modify source')
return None

globe = {
'__file__': str(path),
'__name__': '__main__',
'open': lambda fname, *args, **kwargs: StringIO(fname),
}
with chdir(path.parent):
try:
exec(compile(new_source, path.name, 'exec'), globe)
except Exception as e:
logger.error('{}: {}'.format(type(e).__name__, str(e)))

dist = globe.get('_dist')
if dist is None:
logger.error('distribution was not called')
return None
return Distribution(dist)

@staticmethod
def _get(msg, name: str) -> str:
value = getattr(msg.metadata, name, None)
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ tests = ["tests", "README.md"]
# run command `pytest`
command = "pytest tests/"

[tool.dephell.pypy]
from = {format = "poetry", path = "pyproject.toml"}
# force python interpreter for env
python = "pypy3"
command = "pytest -x tests/"

# Install `docs` extra dependencies in the separated venv and run sphinx:
# $ dephell venv create --env=docs
# $ dephell deps install --env=docs
Expand Down
35 changes: 35 additions & 0 deletions tests/requirements/egg-info/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# built-in
from io import open
from os import path

# external
from setuptools import setup


here = path.abspath(path.dirname(__file__))
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()


# TODO: more info

setup(
name='dephell',
version='0.2.0',
description='Dependency resolution for Python',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/orsinium/dephell',
author='orsinium',

packages=['dephell'],
install_requires=[
'attrs',
'cached_property',
'packaging',
'requests',
],
entry_points={
'console_scripts': ['dephell = dephell.cli:main'],
},
)

0 comments on commit d56a58a

Please sign in to comment.