Completed
Push — master ( 37f12b...701e77 )
by Christophe
21s
created

_post()   C

Complexity

Conditions 7

Size

Total Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 7
dl 0
loc 60
rs 6.3863
c 2
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
"""A setuptools based setup module.
2
3
See:
4
https://packaging.python.org/en/latest/distributing.html
5
https://github.com/chdemko/pandoc-latex-tip
6
"""
7
8
# Always prefer setuptools over distutils
9
from setuptools import setup, find_packages
10
11
# To use a consistent encoding
12
from codecs import open
13
from os import path, makedirs
14
15
here = path.abspath(path.dirname(__file__))
16
17
# Get the long description from the README file
18
try:
19
    import pypandoc
20
    long_description = pypandoc.convert('README.md', 'rst')
21
except (IOError, ImportError):
22
    with open(path.join(here, 'README.md'), encoding='utf-8') as f:
23
        long_description = f.read()
24
25
from distutils.command.build_py import build_py as _build_py
26
from distutils.command.build_ext import build_ext as _build_ext
27
28
def _post():
29
    import icon_font_to_png
30
    from pkg_resources import get_distribution
31
    from appdirs import AppDirs
32
    import os
33
34
    # fontawesome 4.7
35
    dirs = AppDirs(
36
        os.path.join(
37
            'pandoc_latex_tip',
38
            get_distribution('pandoc_latex_tip').version,
39
            '4.7'
40
        )
41
    )
42
    directory = dirs.user_data_dir
43
    if not path.exists(directory):
44
        makedirs(directory)
45
        downloader = icon_font_to_png.FontAwesomeDownloader(directory)
46
        downloader.css_url = 'https://cdn.rawgit.com/FortAwesome/Font-Awesome/v4.7.0/css/font-awesome.css'
47
        downloader.ttf_url = 'https://cdn.rawgit.com/FortAwesome/Font-Awesome/v4.7.0/fonts/fontawesome-webfont.ttf'
48
        downloader.download_files()
49
50
    # fontawesome 5.0
51
    dirs = AppDirs(
52
        os.path.join(
53
            'pandoc_latex_tip',
54
            get_distribution('pandoc_latex_tip').version,
55
            '5.0'
56
        )
57
    )
58
    directory = dirs.user_data_dir
59
    if not path.exists(directory):
60
        makedirs(directory)
61
62
        import requests
63
        import re
64
        from distutils.version import StrictVersion
65
        try:
66
            versions = requests.get('https://api.github.com/repos/FortAwesome/Font-Awesome/tags').json()
67
        except ValueError:
68
            import sys
69
            sys.stderr.write('Unable to get the last version number of the Font-Awesome package on github\n')
70
            sys.exit(1)
71
72
        latest = '5.0'
73
        for version in versions:
74
            if re.match('^5.0', version['name']) and StrictVersion(version['name']) > StrictVersion(latest):
75
                latest = version['name']
76
77
        downloader = icon_font_to_png.FontAwesomeDownloader(directory)
78
        downloader.css_url = 'https://cdn.rawgit.com/FortAwesome/Font-Awesome/' + latest + '/web-fonts-with-css/css/fontawesome.css'
79
        # brands
80
        downloader.ttf_url = 'https://cdn.rawgit.com/FortAwesome/Font-Awesome/' + latest + '/web-fonts-with-css/webfonts/fa-brands-400.ttf'
81
        downloader.download_files()
82
        # regular
83
        downloader.ttf_url = 'https://cdn.rawgit.com/FortAwesome/Font-Awesome/' + latest + '/web-fonts-with-css/webfonts/fa-regular-400.ttf'
84
        downloader.download_files()
85
        # solid
86
        downloader.ttf_url = 'https://cdn.rawgit.com/FortAwesome/Font-Awesome/' + latest + '/web-fonts-with-css/webfonts/fa-solid-900.ttf'
87
        downloader.download_files()
88
89
90
class build_py(_build_py):
91
    def run(self):
92
        _build_py.run(self)
93
        self.execute(_post, (), msg="Running post build task")
94
95
class build_ext(_build_ext):
96
    def run(self):
97
        _build_ext.run(self)
98
        self.execute(_post, (), msg="Running post build task")
99
100
setup(
101
    cmdclass={'build_py': build_py, 'build_ext': build_ext},
102
    name='pandoc-latex-tip',
103
104
    # Versions should comply with PEP440.  For a discussion on single-sourcing
105
    # the version across setup.py and the project code, see
106
    # https://packaging.python.org/en/latest/single_source_version.html
107
    version='1.4.0',
108
109
    # The project's description
110
    description='A pandoc filter for adding tip in LaTeX',
111
    long_description=long_description,
112
113
    # The project's main homepage.
114
    url='https://github.com/chdemko/pandoc-latex-tip',
115
116
    # The project's download page
117
    download_url = 'https://github.com/chdemko/pandoc-latex-tip/archive/master.zip',
118
119
    # Author details
120
    author='Christophe Demko',
121
    author_email='[email protected]',
122
123
    # Maintainer details
124
    maintainer='Christophe Demko',
125
    maintainer_email='[email protected]',
126
127
    # Choose your license
128
    license='BSD-3-Clause',
129
130
    # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
131
    classifiers=[
132
        # How mature is this project? Common values are
133
        #   3 - Alpha
134
        #   4 - Beta
135
        #   5 - Production/Stable
136
        'Development Status :: 5 - Production/Stable',
137
138
        # Specify the OS
139
        'Operating System :: OS Independent',
140
141
        # Indicate who your project is intended for
142
        'Environment :: Console',
143
        'Intended Audience :: End Users/Desktop',
144
        'Intended Audience :: Developers',
145
        'Topic :: Software Development :: Build Tools',
146
        'Topic :: Software Development :: Documentation',
147
        'Topic :: Text Processing :: Filters',
148
149
        # Specify the Python versions you support here. In particular, ensure
150
        # that you indicate whether you support Python 2, Python 3 or both.
151
        'Programming Language :: Python :: 2.7',
152
        'Programming Language :: Python :: 3.4',
153
        'Programming Language :: Python :: 3.5',
154
    ],
155
156
    # What does your project relate to?
157
    keywords='pandoc filters latex tip Font-Awesome icon',
158
159
    # Alternatively, if you want to distribute just a my_module.py, uncomment
160
    # this:
161
    py_modules=["pandoc_latex_tip"],
162
163
    # To provide executable scripts, use entry points in preference to the
164
    # "scripts" keyword. Entry points provide cross-platform support and allow
165
    # pip to create the appropriate form of executable for the target platform.
166
    entry_points={
167
        'console_scripts': [
168
            'pandoc-latex-tip = pandoc_latex_tip:main',
169
        ],
170
    },
171
172
    # List run-time dependencies here.  These will be installed by pip when
173
    # your project is installed. For an analysis of "install_requires" vs pip's
174
    # requirements files see:
175
    # https://packaging.python.org/en/latest/requirements.html
176
    install_requires=[
177
        'panflute>=1.10',
178
        'icon_font_to_png>=0.4',
179
        'pillow>=5.1',
180
        'appdirs>=1.4',
181
        'pypandoc>=1.4'
182
    ],
183
184
    # List additional groups of dependencies here (e.g. development
185
    # dependencies). You can install these using the following syntax,
186
    # for example:
187
    # $ pip install -e .[dev,test]
188
    extras_require={
189
        'dev': ['check-manifest'],
190
        'test': ['coverage'],
191
    },
192
193
    # packages=find_packages(),
194
    # include_package_data = True,
195
196
    setup_requires=[
197
        'pytest-runner',
198
        'icon_font_to_png>=0.4',
199
        'appdirs>=1.4'
200
    ],
201
    tests_require=['pytest', 'coverage'],
202
)
203