diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000000..62d6044f821 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ + +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# https://editorconfig.org +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.py] +indent_style = space +indent_size = 4 + +[*.{ini,toml}] +indent_style = space +indent_size = 4 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000000..4a2f2966b08 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,44 @@ +# Config for Travis CI, tests powered by DepHell. +# https://travis-ci.org/ +# https://github.com/dephell/dephell + +language: python +dist: xenial + +# do not run Travis for PR's twice (as for push and as for PR) +branches: + only: + - master + +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 -L dephell.org/install | /opt/python/3.7/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: + include: + + - python: "3.5" + env: ENV=pytest + + - python: "3.6.7" + env: ENV=pytest + + - python: "3.7" + env: ENV=pytest + + - python: "3.8-dev" + env: ENV=pytest + + - python: "3.7" + env: ENV=flake8 diff --git a/README.md b/README.md new file mode 100644 index 00000000000..cf81e101204 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# dephell_setuptools + +Extract meta information from `setup.py`. + +Install: + +``` +python3 -m pip install --user dephell_setuptools +``` + +CLI: + +``` +python3 -m dephell_setuptools ./setup.py +``` + +Lib: + +```python +from pathlib import Path +from dephell_setuptools import read_setup + +result = read_setup(path=Path('setup.py')) +``` diff --git a/dephell_setuptools/__init__.py b/dephell_setuptools/__init__.py index e0a0e759b87..0b9f1881086 100644 --- a/dephell_setuptools/__init__.py +++ b/dephell_setuptools/__init__.py @@ -1,3 +1,6 @@ +"""Read metainfo from setup.py +""" +# app from ._cfg import CfgReader from ._cmd import CommandReader from ._constants import FIELDS @@ -6,6 +9,9 @@ from ._static import StaticReader +__version__ = '0.1.1' + + __all__ = [ 'FIELDS', 'read_setup', diff --git a/dephell_setuptools/__main__.py b/dephell_setuptools/__main__.py index 5316eb63676..6716a342e96 100644 --- a/dephell_setuptools/__main__.py +++ b/dephell_setuptools/__main__.py @@ -1,3 +1,4 @@ +# app from ._cli import main diff --git a/dephell_setuptools/_base.py b/dephell_setuptools/_base.py index 68cea9181d0..51f9054f908 100644 --- a/dephell_setuptools/_base.py +++ b/dephell_setuptools/_base.py @@ -1,6 +1,8 @@ +# built-in from pathlib import Path from typing import Union +# app from ._constants import FIELDS diff --git a/dephell_setuptools/_cfg.py b/dephell_setuptools/_cfg.py index f8b9ed5efc5..9788a5c846b 100644 --- a/dephell_setuptools/_cfg.py +++ b/dephell_setuptools/_cfg.py @@ -1,10 +1,13 @@ -from copy import deepcopy +# built-in from configparser import ConfigParser +from copy import deepcopy from pathlib import Path from typing import Dict, List, Optional, Union -from setuptools.config import ConfigOptionsHandler, ConfigMetadataHandler +# external +from setuptools.config import ConfigMetadataHandler, ConfigOptionsHandler +# app from ._base import BaseReader from ._constants import FIELDS diff --git a/dephell_setuptools/_cli.py b/dephell_setuptools/_cli.py index 12d1ba803d2..d1116fdc3a3 100644 --- a/dephell_setuptools/_cli.py +++ b/dephell_setuptools/_cli.py @@ -1,6 +1,8 @@ +# built-in import json import sys +# app from ._manager import read_setup diff --git a/dephell_setuptools/_cmd.py b/dephell_setuptools/_cmd.py index d781ccde3f5..a9bcc75ba5e 100644 --- a/dephell_setuptools/_cmd.py +++ b/dephell_setuptools/_cmd.py @@ -1,3 +1,4 @@ +# built-in import json import os import subprocess @@ -7,6 +8,7 @@ from pathlib import Path from tempfile import NamedTemporaryFile +# app from ._base import BaseReader from ._constants import FIELDS diff --git a/dephell_setuptools/_manager.py b/dephell_setuptools/_manager.py index 6b0f2d81370..8ccdaa4ed8a 100644 --- a/dephell_setuptools/_manager.py +++ b/dephell_setuptools/_manager.py @@ -1,7 +1,9 @@ +# built-in from logging import getLogger from pathlib import Path -from typing import Any, Callable, Iterable +from typing import Any, Callable, Iterable, Union +# app from ._cfg import CfgReader from ._cmd import CommandReader from ._pkginfo import PkgInfoReader @@ -18,7 +20,7 @@ def read_setup(*, - path: Path, + path: Union[str, Path], error_handler: Callable[[Exception], Any] = logger.exception, readers: Iterable = ALL_READERS): result = dict() diff --git a/dephell_setuptools/_pkginfo.py b/dephell_setuptools/_pkginfo.py index bbb5275b12f..3b35ae6bb56 100644 --- a/dephell_setuptools/_pkginfo.py +++ b/dephell_setuptools/_pkginfo.py @@ -1,6 +1,8 @@ +# built-in import json import subprocess +# app from ._base import BaseReader diff --git a/dephell_setuptools/_static.py b/dephell_setuptools/_static.py index 1cca951ad63..19fc59264e6 100644 --- a/dephell_setuptools/_static.py +++ b/dephell_setuptools/_static.py @@ -1,8 +1,10 @@ +# built-in import ast from typing import Any, Dict, List, Optional, Union -from ._cached_property import cached_property +# app from ._base import BaseReader +from ._cached_property import cached_property class StaticReader(BaseReader): @@ -52,8 +54,9 @@ def _get_call(self, elements) -> Optional[ast.Call]: def _node_to_value(self, node): if node is None: return None - if isinstance(node, ast.Constant): - return node.value + if hasattr(ast, 'Constant'): + if isinstance(node, ast.Constant): + return node.value if isinstance(node, ast.Str): return node.s if isinstance(node, ast.Num): diff --git a/dephell_setuptools/distutils_cmd.py b/dephell_setuptools/distutils_cmd.py index 7033f850cbb..8e39c316ef6 100644 --- a/dephell_setuptools/distutils_cmd.py +++ b/dephell_setuptools/distutils_cmd.py @@ -1,3 +1,4 @@ +# app from ._cmd import JSONCommand diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000000..009eca86fb1 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,45 @@ +[tool.dephell.main] +from = {format = "flit", path = "pyproject.toml"} +to = {format = "setuppy", path = "setup.py"} + +[tool.dephell.pytest] +from = {format = "flit", path = "pyproject.toml"} +envs = ["main", "dev"] +tests = ["tests"] +command = "python -m pytest tests/" + +[tool.dephell.flake8] +from = {format = "pip", path = "requirements-flake.txt"} +python = ">=3.6" +command = "flake8" + +# -- FLIT -- # + +[tool.flit.metadata] +module="dephell_setuptools" +author="Gram (@orsinium)" +author-email="master_fess@mail.ru" +home-page="https://github.com/dephell/dephell_setuptools" +requires-python=">=3.5" +requires=[ + "setuptools", +] +description-file="README.md" +classifiers=[ + "Development Status :: 4 - Beta", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3", + "Programming Language :: Python", + "Topic :: Software Development :: Libraries :: Python Modules", +] + +[tool.flit.metadata.requires-extra] +dev = [ + "pkginfo", + "pytest", +] diff --git a/requirements-flake.txt b/requirements-flake.txt new file mode 100644 index 00000000000..8c6c3ba211b --- /dev/null +++ b/requirements-flake.txt @@ -0,0 +1,15 @@ +flake8 + +flake8-alfred # https://github.com/datatheorem/flake8-alfred +flake8-blind-except # https://github.com/elijahandrews/flake8-blind-except +flake8-broken-line # https://github.com/sobolevn/flake8-broken-line +flake8-bugbear # https://github.com/PyCQA/flake8-bugbear +flake8-commas # https://github.com/PyCQA/flake8-commas +flake8-comprehensions # https://github.com/adamchainz/flake8-comprehensions +flake8-debugger # https://github.com/JBKahn/flake8-debugger +flake8-logging-format # https://github.com/globality-corp/flake8-logging-format +flake8-mutable # https://github.com/ebeweber/flake8-mutable +flake8-pep3101 # https://github.com/gforcada/flake8-pep3101 +flake8-quotes # https://github.com/zheller/flake8-quotes +flake8-tidy-imports # https://github.com/adamchainz/flake8-tidy-imports +pep8-naming # https://github.com/PyCQA/pep8-naming diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000000..cb2af1b4d0f --- /dev/null +++ b/setup.cfg @@ -0,0 +1,27 @@ +[metadata] +description-file = README.md +license_file = LICENSE + +[flake8] +max-line-length=120 +ignore=E241,C401,C408 +exclude= + .tox + .dephell + .pytest_cache + build + setup.py + tests/setups + +[isort] +skip=.tox,.pytest_cache,.dephell,tests/setups +line_length=120 +combine_as_imports=true +balanced_wrapping=true +lines_after_imports=2 +not_skip=__init__.py +multi_line_output=5 +import_heading_stdlib=built-in +import_heading_thirdparty=external +import_heading_firstparty=project +import_heading_localfolder=app diff --git a/tests/test_cfg.py b/tests/test_cfg.py index 7f730c9eeb3..829085b7288 100644 --- a/tests/test_cfg.py +++ b/tests/test_cfg.py @@ -1,5 +1,7 @@ +# built-in from pathlib import Path +# project from dephell_setuptools import CfgReader diff --git a/tests/test_cmd.py b/tests/test_cmd.py index d2af371dd2c..83153b0c82b 100644 --- a/tests/test_cmd.py +++ b/tests/test_cmd.py @@ -1,5 +1,7 @@ +# built-in from pathlib import Path +# project from dephell_setuptools import CommandReader diff --git a/tests/test_static.py b/tests/test_static.py index 7df44e8cf93..7151f4ff853 100644 --- a/tests/test_static.py +++ b/tests/test_static.py @@ -1,5 +1,7 @@ +# built-in from pathlib import Path +# project from dephell_setuptools import StaticReader