From faf6c7ce68de3b8022e0e4db8207db49e1220182 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 0000000..62d6044 --- /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 0000000..28eec45 --- /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 0000000..4f4827a --- /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 0000000..f8944e5 --- /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 80096b8921fda7fc94bdf7440aac21e21a515d7b Mon Sep 17 00:00:00 2001 From: Gram Date: Wed, 13 Nov 2019 15:59:41 +0100 Subject: [PATCH 2/8] release --- .gitignore | 4 ++++ README.md | 24 ++++++++++++++++++++++++ dephell_setuptools/__init__.py | 5 +++++ dephell_setuptools/_manager.py | 4 ++-- pyproject.toml | 2 +- 5 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 README.md diff --git a/.gitignore b/.gitignore index 6c56ff1..76c77c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ __pycache__/ .pytest_cache/ +/README.rst +/setup.py +*.egg-info +/dist/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..cf81e10 --- /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 e0a0e75..20b5bdd 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 6b0f2d8..2cd10c0 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 4f4827a..009eca8 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 ce3713f14de1c6f18b6c5e75e575f63947a1c4b3 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 28eec45..e12c3b0 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 0f3d2afe6d67e353f23719007431398dad1e5095 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 20b5bdd..0b9f188 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 5316eb6..6716a34 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 68cea91..51f9054 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 f8b9ed5..9788a5c 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 12d1ba8..d1116fd 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 d781ccd..a9bcc75 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 2cd10c0..8ccdaa4 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 bbb5275..3b35ae6 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 1cca951..4ef615a 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 7033f85..8e39c31 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 0000000..6184c7e --- /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 7f730c9..829085b 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 d2af371..83153b0 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 7df44e8..7151f4f 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 5fec4e89aefb50dbc43ecab8fd70adf3f35cc946 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 f8944e5..8c6c3ba 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 6184c7e..cb2af1b 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 7891df69d7cff41dbe83c9a314419c701c3639c9 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 e12c3b0..4a2f296 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 6c33675758b6c3aec537f7c11dcf63abcb7329ee 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 a905e8b49d0fbef42f42dcfa90cc414707ec0109 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 4ef615a..19fc592 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):