Completed
Push — master ( d31ad1...a3685b )
by Kyle
01:32
created

_Mock.def_extern()   A

Complexity

Conditions 2

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 3
rs 10
1
"""This module handles loading of the libtcod cffi API.
2
"""
3
from __future__ import absolute_import as _
4
5
import sys as _sys
6
import os as _os
7
8
import platform as _platform
9
10
11
from tcod import __path__
12
13
# add Windows dll's to PATH
14
if _sys.platform == 'win32':
15
    _bits, _linkage = _platform.architecture()
16
    _os.environ['PATH'] += (';' +
17
        _os.path.join(__path__[0], 'x86/' if _bits == '32bit' else 'x64'))
18
19
20
def _import_library_functions(lib):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Comprehensibility Bug introduced by
lib is re-defining a name which is already available in the outer-scope (previously defined on line 82).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
21
    # imports libtcod namespace into thie module
22
    # does not override existing names
23
    g = globals()
24
    for name in dir(lib):
25
        if name[:5] == 'TCOD_':
26
            if name.isupper():
27
                g[name[5:]] = getattr(lib, name) # const names
28
        elif name.startswith('FOV'):
29
            g[name] = getattr(lib, name) # fov const names
30
        elif name[:6] == 'TCODK_': # key name
31
            g['KEY_' + name[6:]] = getattr(lib, name)
32
33
NOISE_DEFAULT_HURST = 0.5
34
NOISE_DEFAULT_LACUNARITY = 2.0
35
36
def FOV_PERMISSIVE(p) :
0 ignored issues
show
Coding Style introduced by
No space allowed before :
def FOV_PERMISSIVE(p) :
^
Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
37
    return FOV_PERMISSIVE_0+p
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'FOV_PERMISSIVE_0'
Loading history...
38
39
def BKGND_ALPHA(a):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
40
    return BKGND_ALPH | (int(a * 255) << 8)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'BKGND_ALPH'
Loading history...
41
42
def BKGND_ADDALPHA(a):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
43
    return BKGND_ADDA | (int(a * 255) << 8)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'BKGND_ADDA'
Loading history...
44
45
class _Mock(object):
46
    """Mock object needed for ReadTheDocs."""
47
48
    TCOD_RENDERER_SDL = 2
49
    TCOD_FONT_LAYOUT_ASCII_INCOL = 1
50
    TCOD_BKGND_SET = 1
51
    TCOD_BKGND_DEFAULT = 13
52
    TCOD_KEY_RELEASED = 2
53
    TCOD_NOISE_DEFAULT = 0
54
    TCOD_NOISE_SIMPLEX = 2
55
    FOV_RESTRICTIVE = 12
56
57
    TCOD_RNG_MT = 0
58
    TCOD_RNG_CMWC = 1
59
60
    CData = () # This gets passed to an isinstance call.
61
62
    def def_extern(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
63
        """Pass def_extern call silently."""
64
        return lambda func:func
0 ignored issues
show
Coding Style introduced by
Exactly one space required after :
return lambda func:func
^
Loading history...
65
66
    def __getattr__(self, attr):
67
        """This object pretends to have everything."""
68
        return self
69
70
    def __call__(self, *args, **kargs):
71
        """Suppress any other calls"""
72
        return self
73
74
    def __str__(self):
75
        """Just have ? in case anything leaks as a parameter default."""
76
        return '?'
77
78
79
if _os.environ.get('READTHEDOCS'):
80
    # Mock the lib and ffi objects needed to compile docs for readthedocs.io
81
    # Allows an import without building the cffi module first.
82
    lib = ffi = _Mock()
83
else:
84
    from tcod._libtcod import lib, ffi
0 ignored issues
show
Bug introduced by
The name _libtcod does not seem to exist in module tcod.
Loading history...
Configuration introduced by
The import tcod._libtcod could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
Unused Code introduced by
Unused ffi imported from tcod._libtcod
Loading history...
85
86
_import_library_functions(lib)
87