Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linting with flake8 #109

Merged
merged 4 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions cydoctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import doctest
import inspect


def _from_module(module, object):
"""
Return true if the given object is defined in the given module.
Expand All @@ -33,20 +34,22 @@ def _from_module(module, object):
elif hasattr(object, '__module__'):
return module.__name__ == object.__module__
elif isinstance(object, property):
return True # [XX] no way not be sure.
return True # [XX] no way not be sure.
else:
raise ValueError("object must be a class or function")


def fix_module_doctest(module):
"""
Extract docstrings from cython functions, that would be skipped by doctest
otherwise.
"""
module.__test__ = {}
for name in dir(module):
value = getattr(module, name)
if inspect.isbuiltin(value) and isinstance(value.__doc__, str) and _from_module(module, value):
module.__test__[name] = value.__doc__
value = getattr(module, name)
if inspect.isbuiltin(value) and isinstance(value.__doc__, str) and _from_module(module, value):
module.__test__[name] = value.__doc__


def testmod(m=None, *args, **kwargs):
"""
Expand All @@ -62,4 +65,4 @@ def testmod(m=None, *args, **kwargs):

if __name__ == "__main__":
import pyroaring
testmod(pyroaring)
testmod(pyroaring)
9 changes: 4 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode']
'sphinx.ext.viewcode',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down Expand Up @@ -156,6 +158,3 @@
author, 'pyroaring', 'One line description of project.',
'Miscellaneous'),
]



7 changes: 3 additions & 4 deletions download_amalgamation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

"""
import os
from urllib.request import urlretrieve
import sys
from urllib.request import urlretrieve

version = sys.argv[1]

Expand All @@ -19,8 +19,7 @@
files = ["roaring.c", "roaring.h"]

for file in files:
r = urlretrieve(release + file, os.path.join("pyroaring", file))
r = urlretrieve(release + file, os.path.join("pyroaring", file))

with open(os.path.join("pyroaring", "croaring_version.pxi"), "w") as f:
f.write(f"__croaring_version__ = \"{version}\"")

f.write(f"__croaring_version__ = \"{version}\"")
18 changes: 10 additions & 8 deletions quick_bench.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#! /usr/bin/env python3

import sys
import timeit
from pandas import DataFrame, Series
import random
import timeit

from pandas import Series, DataFrame

try:
import tabulate
has_tabulate = True
Expand All @@ -17,7 +19,7 @@
nb_exp = 30
size = int(1e6)
density = 0.125
universe_size = int(size/density)
universe_size = int(size / density)

try:
from roaringbitmap import RoaringBitmap
Expand All @@ -41,20 +43,20 @@
sys.stderr.write(' see https://github.com/sunzhaoping/python-croaring\n')

import_str = 'import array, pickle; from __main__ import %s' % (','.join(
['get_list', 'get_range', 'random', 'size', 'universe_size'] +
[cls.__name__ for cls in classes.values() if cls is not set]))
['get_list', 'get_range', 'random', 'size', 'universe_size']
+ [cls.__name__ for cls in classes.values() if cls is not set]))


def run_exp(stmt, setup, number):
setup = '%s ; %s' % (import_str, setup)
try:
return timeit.timeit(stmt=stmt, setup=setup, number=number)/number
except Exception as e:
return timeit.timeit(stmt=stmt, setup=setup, number=number) / number
except Exception:
return float('nan')


def get_range():
r = (0, universe_size, int(1/density))
r = (0, universe_size, int(1 / density))
try:
return xrange(*r)
except NameError:
Expand Down
30 changes: 30 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[flake8]
exclude =
.eggs
.git
.pybuild
.tox
__pycache__
build
dist
ignore =
# W503 and W504 conflict; ignore the one that disagrees with recent PEP8.
W503

# try to keep it reasonable, but this allows us to push it a bit when needed.
max_line_length = 150

noqa-require-code = true


[isort]
atomic = True
balanced_wrapping = True
combine_as_imports = True
include_trailing_comma = True
length_sort = True
multi_line_output = 3
order_by_type = False

default_section = THIRDPARTY
sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
20 changes: 9 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#! /usr/bin/env python3

from setuptools import setup
from setuptools.extension import Extension
from distutils.sysconfig import get_config_vars
import os
import sys
import subprocess
import platform
from distutils.sysconfig import get_config_vars

from setuptools import setup
from setuptools.extension import Extension

PKG_DIR = 'pyroaring'

Expand All @@ -17,15 +15,15 @@
# Read version file from the src
with open("pyroaring/version.pxi") as fp:
exec(fp.read())
VERSION = __version__
VERSION = __version__ # noqa: F821


# Remove -Wstrict-prototypes option
# See http://stackoverflow.com/a/29634231/4110059
if not PLATFORM_WINDOWS:
cfg_vars = get_config_vars()
for key, value in cfg_vars.items():
if type(value) == str:
if type(value) is str:
cfg_vars[key] = value.replace("-Wstrict-prototypes", "")

try:
Expand All @@ -40,7 +38,7 @@
pyroaring_module = Extension(
'pyroaring',
sources=[os.path.join(PKG_DIR, 'pyroaring.pyx'), os.path.join(PKG_DIR, 'roaring.c')],
language='c++'
language='c++',
)
libraries = None
else:
Expand All @@ -59,14 +57,14 @@
# also creates troubles under macOS with pip installs and requires ugly workarounds.
# The best way to handle people who want to use -march=native is to ask them
# to pass ARCHI=native to their build process.
#else:
# else:
# compile_args.append('-march=native')

pyroaring_module = Extension(
'pyroaring',
sources=[os.path.join(PKG_DIR, 'pyroaring.pyx')],
extra_compile_args=compile_args + ["-std=c++11"],
language='c++'
language='c++',
)

# Because we compile croaring with a c compiler with sometimes incompatible arguments,
Expand All @@ -76,7 +74,7 @@
'croaring',
{
'sources': [os.path.join(PKG_DIR, 'roaring.c')],
"extra_compile_args": compile_args + ["-std=c11"]
"extra_compile_args": compile_args + ["-std=c11"],
},
)
libraries = [croaring]
Expand Down
Loading
Loading