From e686539ec63949e820c7cf64890d2e636b11dfcd Mon Sep 17 00:00:00 2001 From: Gram Date: Wed, 13 Nov 2019 15:49:47 +0100 Subject: [PATCH 1/8] add metainfo and ci --- .editorconfig | 19 ++++++++++++++++++ .travis.yml | 30 ++++++++++++++++++++++++++++ pyproject.toml | 45 ++++++++++++++++++++++++++++++++++++++++++ requirements-flake.txt | 16 +++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 .editorconfig create mode 100644 .travis.yml create mode 100644 pyproject.toml create mode 100644 requirements-flake.txt 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..28eec45c14c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,30 @@ +# Config for Travis CI, tests powered by DepHell. +# https://travis-ci.org/ +# https://github.com/dephell/dephell + +language: python +dist: xenial + +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.7" + env: ENV=pytest + + - python: "3.7" + env: ENV=flake8 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000000..4f4827a6fb7 --- /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="flakehell" +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..f8944e5a42e --- /dev/null +++ b/requirements-flake.txt @@ -0,0 +1,16 @@ +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 +flake8-variables-names # https://github.com/best-doctor/flake8-variables-names +pep8-naming # https://github.com/PyCQA/pep8-naming From 1b61d12518800e4d3d6cf3e2ca09fb19dd9235f6 Mon Sep 17 00:00:00 2001 From: Gram Date: Wed, 13 Nov 2019 15:59:41 +0100 Subject: [PATCH 2/8] release --- README.md | 24 ++++++++++++++++++++++++ dephell_setuptools/__init__.py | 5 +++++ dephell_setuptools/_manager.py | 4 ++-- pyproject.toml | 2 +- 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 README.md 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..20b5bdd6391 100644 --- a/dephell_setuptools/__init__.py +++ b/dephell_setuptools/__init__.py @@ -1,3 +1,5 @@ +"""Read metainfo from setup.py +""" from ._cfg import CfgReader from ._cmd import CommandReader from ._constants import FIELDS @@ -6,6 +8,9 @@ from ._static import StaticReader +__version__ = '0.1.1' + + __all__ = [ 'FIELDS', 'read_setup', diff --git a/dephell_setuptools/_manager.py b/dephell_setuptools/_manager.py index 6b0f2d81370..2cd10c08fdf 100644 --- a/dephell_setuptools/_manager.py +++ b/dephell_setuptools/_manager.py @@ -1,6 +1,6 @@ from logging import getLogger from pathlib import Path -from typing import Any, Callable, Iterable +from typing import Any, Callable, Iterable, Union from ._cfg import CfgReader from ._cmd import CommandReader @@ -18,7 +18,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/pyproject.toml b/pyproject.toml index 4f4827a6fb7..009eca86fb1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ command = "flake8" # -- FLIT -- # [tool.flit.metadata] -module="flakehell" +module="dephell_setuptools" author="Gram (@orsinium)" author-email="master_fess@mail.ru" home-page="https://github.com/dephell/dephell_setuptools" From 2a5c88a94892a813c7ce6302836565ca641a3e8d Mon Sep 17 00:00:00 2001 From: Gram Date: Wed, 13 Nov 2019 16:03:44 +0100 Subject: [PATCH 3/8] build ci only once --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 28eec45c14c..e12c3b06209 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,11 @@ 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 From 23a662d7da92d0f699e1749a9138f84f377b0e4e Mon Sep 17 00:00:00 2001 From: Gram Date: Wed, 13 Nov 2019 16:09:16 +0100 Subject: [PATCH 4/8] sort imports --- dephell_setuptools/__init__.py | 1 + dephell_setuptools/__main__.py | 1 + dephell_setuptools/_base.py | 2 ++ dephell_setuptools/_cfg.py | 7 +++++-- dephell_setuptools/_cli.py | 2 ++ dephell_setuptools/_cmd.py | 2 ++ dephell_setuptools/_manager.py | 2 ++ dephell_setuptools/_pkginfo.py | 2 ++ dephell_setuptools/_static.py | 4 +++- dephell_setuptools/distutils_cmd.py | 1 + setup.cfg | 26 ++++++++++++++++++++++++++ tests/test_cfg.py | 2 ++ tests/test_cmd.py | 2 ++ tests/test_static.py | 2 ++ 14 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 setup.cfg diff --git a/dephell_setuptools/__init__.py b/dephell_setuptools/__init__.py index 20b5bdd6391..0b9f1881086 100644 --- a/dephell_setuptools/__init__.py +++ b/dephell_setuptools/__init__.py @@ -1,5 +1,6 @@ """Read metainfo from setup.py """ +# app from ._cfg import CfgReader from ._cmd import CommandReader from ._constants import FIELDS 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 2cd10c08fdf..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, Union +# app from ._cfg import CfgReader from ._cmd import CommandReader from ._pkginfo import PkgInfoReader 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..4ef615a91d2 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): 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/setup.cfg b/setup.cfg new file mode 100644 index 00000000000..6184c7efef1 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,26 @@ +[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 + +[isort] +skip=.tox,.pytest_cache,.dephell +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 From 5da30a7fd226e1b719d3ff7a957517e15e2259e7 Mon Sep 17 00:00:00 2001 From: Gram Date: Wed, 13 Nov 2019 16:11:37 +0100 Subject: [PATCH 5/8] fix flake8 --- requirements-flake.txt | 1 - setup.cfg | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-flake.txt b/requirements-flake.txt index f8944e5a42e..8c6c3ba211b 100644 --- a/requirements-flake.txt +++ b/requirements-flake.txt @@ -12,5 +12,4 @@ 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 -flake8-variables-names # https://github.com/best-doctor/flake8-variables-names pep8-naming # https://github.com/PyCQA/pep8-naming diff --git a/setup.cfg b/setup.cfg index 6184c7efef1..cb2af1b4d0f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,9 +11,10 @@ exclude= .pytest_cache build setup.py + tests/setups [isort] -skip=.tox,.pytest_cache,.dephell +skip=.tox,.pytest_cache,.dephell,tests/setups line_length=120 combine_as_imports=true balanced_wrapping=true From 2ef82d924ddc4dad95c30da78788efa616e22fc4 Mon Sep 17 00:00:00 2001 From: Gram Date: Wed, 13 Nov 2019 16:15:31 +0100 Subject: [PATCH 6/8] check more pythons --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.travis.yml b/.travis.yml index e12c3b06209..4a2f2966b08 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,8 +28,17 @@ script: 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 From 04771666c07abbeadcc30b2c9b2120c818515943 Mon Sep 17 00:00:00 2001 From: Gram Date: Wed, 13 Nov 2019 16:17:19 +0100 Subject: [PATCH 7/8] trigger ci From f94b2e207d5ee9d16f2ff21670a675ade3d87e2b Mon Sep 17 00:00:00 2001 From: Gram Date: Wed, 13 Nov 2019 16:58:36 +0100 Subject: [PATCH 8/8] py 3.5 compat --- dephell_setuptools/_static.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dephell_setuptools/_static.py b/dephell_setuptools/_static.py index 4ef615a91d2..19fc59264e6 100644 --- a/dephell_setuptools/_static.py +++ b/dephell_setuptools/_static.py @@ -54,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):