oblalex /
verboselib
| 1 | import itertools |
||
| 2 | import os |
||
| 3 | import shlex |
||
| 4 | import sys |
||
| 5 | |||
| 6 | if sys.version_info >= (3, 9): |
||
| 7 | List = list |
||
| 8 | Tuple = tuple |
||
| 9 | else: |
||
| 10 | from typing import List |
||
| 11 | from typing import Tuple |
||
| 12 | |||
| 13 | from pathlib import Path |
||
| 14 | from setuptools import setup |
||
| 15 | from subprocess import check_output |
||
| 16 | from typing import Optional |
||
| 17 | |||
| 18 | |||
| 19 | __here__ = Path(__file__).absolute().parent |
||
| 20 | |||
| 21 | |||
| 22 | version_file_path = __here__ / "verboselib" / "version.py" |
||
| 23 | exec(compile(version_file_path.read_text(), version_file_path, "exec")) |
||
| 24 | |||
| 25 | |||
| 26 | def maybe_get_shell_output(command: str) -> str: |
||
| 27 | try: |
||
| 28 | args = shlex.split(command) |
||
| 29 | with open(os.devnull, "w") as devnull: |
||
| 30 | return check_output(args, stderr=devnull).strip().decode() |
||
| 31 | except Exception: |
||
| 32 | pass |
||
| 33 | |||
| 34 | |||
| 35 | def maybe_get_current_branch_name() -> Optional[str]: |
||
| 36 | return maybe_get_shell_output("git rev-parse --abbrev-ref HEAD") |
||
| 37 | |||
| 38 | |||
| 39 | def maybe_get_current_commit_hash() -> Optional[str]: |
||
| 40 | return maybe_get_shell_output("git rev-parse --short HEAD") |
||
| 41 | |||
| 42 | |||
| 43 | def parse_requirements(file_path: Path) -> Tuple[List[str], List[str]]: |
||
| 44 | requirements, dependencies = list(), list() |
||
| 45 | |||
| 46 | if not file_path.exists(): |
||
| 47 | return requirements, dependencies |
||
| 48 | |||
| 49 | with file_path.open("rt") as f: |
||
| 50 | for line in f: |
||
| 51 | line = line.strip() |
||
| 52 | |||
| 53 | # check if is comment or empty |
||
| 54 | if not line or line.startswith("#"): |
||
| 55 | continue |
||
| 56 | |||
| 57 | # check if is URL |
||
| 58 | if "://" in line: |
||
| 59 | dependencies.append(line) |
||
| 60 | |||
| 61 | egg = line.split("#egg=", 1)[1] |
||
| 62 | |||
| 63 | # check if version is specified |
||
| 64 | if "-" in egg: |
||
| 65 | egg = egg.rsplit("-", 1)[0] |
||
| 66 | |||
| 67 | requirements.append(egg) |
||
| 68 | |||
| 69 | # check if is inclusion of other requirements file |
||
| 70 | elif line.startswith("-r"): |
||
| 71 | name = Path(line.split(" ", 1)[1]) |
||
| 72 | path = file_path.parent / name |
||
| 73 | subrequirements, subdependencies = parse_requirements(path) |
||
| 74 | requirements.extend(subrequirements) |
||
| 75 | dependencies.extend(subdependencies) |
||
| 76 | |||
| 77 | # assume is a standard requirement |
||
| 78 | else: |
||
| 79 | requirements.append(line) |
||
| 80 | |||
| 81 | return requirements, dependencies |
||
| 82 | |||
| 83 | |||
| 84 | README = (__here__ / "README.rst").read_text() |
||
| 85 | |||
| 86 | STABLE_BRANCH_NAME = "master" |
||
| 87 | CURRENT_COMMIT_HASH = maybe_get_current_commit_hash() |
||
| 88 | CURRENT_BRANCH_NAME = maybe_get_current_branch_name() |
||
| 89 | IS_CURRENT_BRANCH_STABLE = (CURRENT_BRANCH_NAME == STABLE_BRANCH_NAME) |
||
| 90 | BUILD_TAG = ( |
||
| 91 | f".{CURRENT_BRANCH_NAME}.{CURRENT_COMMIT_HASH}" |
||
| 92 | if not IS_CURRENT_BRANCH_STABLE and CURRENT_COMMIT_HASH |
||
| 93 | else "" |
||
| 94 | ) |
||
| 95 | |||
| 96 | REQUIREMENTS_DIR_PATH = __here__ / "requirements" |
||
| 97 | |||
| 98 | INSTALL_REQUIREMENTS, INSTALL_DEPENDENCIES = parse_requirements( |
||
| 99 | file_path=(REQUIREMENTS_DIR_PATH / "dist.txt"), |
||
| 100 | ) |
||
| 101 | SETUP_REQUIREMENTS, SETUP_DEPENDENCIES = parse_requirements( |
||
| 102 | file_path=(REQUIREMENTS_DIR_PATH / "setup.txt"), |
||
| 103 | ) |
||
| 104 | TEST_REQUIREMENTS, TEST_DEPENDENCIES = parse_requirements( |
||
| 105 | file_path=(REQUIREMENTS_DIR_PATH / "test.txt"), |
||
| 106 | ) |
||
| 107 | |||
| 108 | setup( |
||
| 109 | name="verboselib", |
||
| 110 | version=VERSION, |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 111 | description="A little I18N framework for libraries and applications", |
||
| 112 | long_description=README, |
||
| 113 | long_description_content_type="text/x-rst", |
||
| 114 | keywords=[ |
||
| 115 | "library", "l18n", "localization", "lazy", "string", "framework", "gettext", |
||
| 116 | ], |
||
| 117 | license="MIT", |
||
| 118 | url=f"https://github.com/oblalex/verboselib/tree/v{VERSION}", |
||
| 119 | |||
| 120 | author="Oleksandr Oblovatnyi", |
||
| 121 | author_email="[email protected]", |
||
| 122 | |||
| 123 | packages=[ |
||
| 124 | "verboselib", |
||
| 125 | "verboselib.cli", |
||
| 126 | ], |
||
| 127 | entry_points={ |
||
| 128 | "console_scripts": [ |
||
| 129 | "verboselib = verboselib.cli.main:main", |
||
| 130 | ], |
||
| 131 | }, |
||
| 132 | |||
| 133 | python_requires=">=3.7", |
||
| 134 | dependency_links=list(set(itertools.chain( |
||
| 135 | INSTALL_DEPENDENCIES, |
||
| 136 | SETUP_DEPENDENCIES, |
||
| 137 | TEST_DEPENDENCIES, |
||
| 138 | ))), |
||
| 139 | install_requires=INSTALL_REQUIREMENTS, |
||
| 140 | setup_requires=SETUP_REQUIREMENTS, |
||
| 141 | tests_require=TEST_REQUIREMENTS, |
||
| 142 | test_suite="tests", |
||
| 143 | |||
| 144 | classifiers=[ |
||
| 145 | "Development Status :: 5 - Production/Stable", |
||
| 146 | "Intended Audience :: Developers", |
||
| 147 | "License :: OSI Approved :: MIT License", |
||
| 148 | "Natural Language :: English", |
||
| 149 | "Operating System :: MacOS :: MacOS X", |
||
| 150 | "Operating System :: Microsoft :: Windows", |
||
| 151 | "Operating System :: POSIX", |
||
| 152 | "Programming Language :: Python :: 3", |
||
| 153 | "Topic :: Software Development :: Libraries", |
||
| 154 | ], |
||
| 155 | |||
| 156 | options={ |
||
| 157 | 'egg_info': { |
||
| 158 | 'tag_build': BUILD_TAG, |
||
| 159 | 'tag_date': False, |
||
| 160 | }, |
||
| 161 | }, |
||
| 162 | |||
| 163 | zip_safe=True, |
||
| 164 | ) |
||
| 165 |