File: setup.py

package info (click to toggle)
pylint-gitlab 2.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 200 kB
  • sloc: python: 302; makefile: 8
file content (102 lines) | stat: -rw-r--r-- 3,052 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#
# Copyright 2020 Stephan Mueller
#
# Licensed under the GPLv3 license

"""Setup for pylint_gitlab module."""

import json
import logging
import os
import subprocess

import setuptools

logger = logging.getLogger(__name__)


def get_install_requirements() -> list:
    """Retrieves list of packages from Pipfile.lock required for installation.

    Returns: List of packages
    """
    with open("Pipfile.lock", encoding="UTF-8") as file:
        pipfile = file.read()

    packages = []
    for name, _ in json.loads(pipfile)["default"].items():
        packages.append(name)
    return packages


def long_description() -> str:
    """Reads README.md

    Returns: Content of ``README.md``
    """
    with open("README.md", "r", encoding="UTF-8") as file:
        return file.read()


def version() -> str:
    """Tries to detect version based on selected strategy.

    Returns: Project version
    """

    version_strategy = os.getenv("VERSION_STRATEGY", "GIT_REF_NAME")

    if version_strategy == "GIT_COMMIT_SHA":

        if os.getenv("CI_COMMIT_SHA", "") != "":
            return os.getenv("CI_COMMIT_SHA")

        process = subprocess.run(["git", "rev-parse", "--quiet", "HEAD"], capture_output=True, check=True)
        commit_sha = process.stdout.decode().strip()
        if commit_sha is not None and commit_sha != "":
            return "0.0.0+commit" + commit_sha

    elif version_strategy == "GIT_REF_NAME":

        if os.getenv("CI_COMMIT_TAG", "") != "":
            return os.getenv("CI_COMMIT_TAG")

        if os.getenv("CI_COMMIT_REF_NAME", "") != "":
            branch = os.getenv("CI_COMMIT_REF_NAME")
        else:
            process = subprocess.run(["git", "symbolic-ref", "--quiet", "HEAD"], capture_output=True, check=True)
            branch = process.stdout.decode().strip().replace("refs/heads/", "", 1)

        if branch is not None and branch != "":
            return "0.0.0+" + branch.replace("/", "-")

    raise ValueError("Version could not be detected.")


setuptools.setup(
    name="pylint-gitlab",
    version=os.getenv("UPSTREAM_VERSION"),
    author="Stephan Müller",
    author_email="mail@stephanmueller.eu",
    license='GPLv3',
    description="This project provides pylint formatters for a nice integration with GitLab CI.",
    long_description=long_description(),
    long_description_content_type="text/markdown",
    url="https://gitlab.com/smueller18/pylint-gitlab",
    packages=setuptools.find_packages(),
    install_requires=get_install_requirements(),
    package_data={
        "": ["templates/report.html.j2"]
    },
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
        "Operating System :: OS Independent",
    ],
    python_requires='>=3.7',
    project_urls={
        'Documentation': 'https://gitlab.com/smueller18/pylint-gitlab',
        'Source': 'https://gitlab.com/smueller18/pylint-gitlab',
        'Tracker': 'https://gitlab.com/smueller18/pylint-gitlab/issues',
    },
)