diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index cc97ba4..0000000 --- a/.coveragerc +++ /dev/null @@ -1,15 +0,0 @@ -[paths] -source = src - -[run] -branch = true -source = - src - tests -parallel = true -omit = src/memwiper/utils/_coretest.py - -[report] -show_missing = true -precision = 2 -omit = *migrations* diff --git a/.readthedocs.yml b/.readthedocs.yml deleted file mode 100644 index 13d27cc..0000000 --- a/.readthedocs.yml +++ /dev/null @@ -1,4 +0,0 @@ -requirements_file: docs/requirements.txt -python: - version: 3.5 - diff --git a/MANIFEST.in b/MANIFEST.in index 237feb0..bca1421 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,28 +3,26 @@ graft src graft ci graft tests +include AUTHORS.rst include .bumpversion.cfg -include .coveragerc +include CHANGELOG.rst +include codecov.yml +include CONTRIBUTING.rst include .cookiecutterrc include .editorconfig -include .isort.cfg -include .readthedocs.yml include .flake8 -include bandit.yml -include pyproject.toml -include codecov.yml - - -include AUTHORS.rst -include CHANGELOG.rst -include CONTRIBUTING.rst +include flake8.ini include LICENSE +include pytest.ini +include pyproject.toml include README.rst -include TODO.rst +include readthedocs.yml include requirements.txt include requirements-dev.txt +include TODO.rst +include tox.ini +include .travis.yml -include tox.ini .travis.yml prune __pycache__ prune .ropeproject diff --git a/bandit.yml b/bandit.yml deleted file mode 100644 index 67e95e5..0000000 --- a/bandit.yml +++ /dev/null @@ -1,399 +0,0 @@ - -### Bandit config file generated from: -# '/home/qlixed/srced/python-memwiper/bin/bandit-config-generator -o bandit.yml' - -### This config may optionally select a subset of tests to run or skip by -### filling out the 'tests' and 'skips' lists given below. If no tests are -### specified for inclusion then it is assumed all tests are desired. The skips -### set will remove specific tests from the include set. This can be controlled -### using the -t/-s CLI options. Note that the same test ID should not appear -### in both 'tests' and 'skips', this would be nonsensical and is detected by -### Bandit at runtime. - -# Available tests: -# B101 : assert_used -# B102 : exec_used -# B103 : set_bad_file_permissions -# B104 : hardcoded_bind_all_interfaces -# B105 : hardcoded_password_string -# B106 : hardcoded_password_funcarg -# B107 : hardcoded_password_default -# B108 : hardcoded_tmp_directory -# B110 : try_except_pass -# B112 : try_except_continue -# B201 : flask_debug_true -# B301 : pickle -# B302 : marshal -# B303 : md5 -# B304 : ciphers -# B305 : cipher_modes -# B306 : mktemp_q -# B307 : eval -# B308 : mark_safe -# B309 : httpsconnection -# B310 : urllib_urlopen -# B311 : random -# B312 : telnetlib -# B313 : xml_bad_cElementTree -# B314 : xml_bad_ElementTree -# B315 : xml_bad_expatreader -# B316 : xml_bad_expatbuilder -# B317 : xml_bad_sax -# B318 : xml_bad_minidom -# B319 : xml_bad_pulldom -# B320 : xml_bad_etree -# B321 : ftplib -# B322 : input -# B323 : unverified_context -# B324 : hashlib_new_insecure_functions -# B325 : tempnam -# B401 : import_telnetlib -# B402 : import_ftplib -# B403 : import_pickle -# B404 : import_subprocess -# B405 : import_xml_etree -# B406 : import_xml_sax -# B407 : import_xml_expat -# B408 : import_xml_minidom -# B409 : import_xml_pulldom -# B410 : import_lxml -# B411 : import_xmlrpclib -# B412 : import_httpoxy -# B413 : import_pycrypto -# B501 : request_with_no_cert_validation -# B502 : ssl_with_bad_version -# B503 : ssl_with_bad_defaults -# B504 : ssl_with_no_version -# B505 : weak_cryptographic_key -# B506 : yaml_load -# B507 : ssh_no_host_key_verification -# B601 : paramiko_calls -# B602 : subprocess_popen_with_shell_equals_true -# B603 : subprocess_without_shell_equals_true -# B604 : any_other_function_with_shell_equals_true -# B605 : start_process_with_a_shell -# B606 : start_process_with_no_shell -# B607 : start_process_with_partial_path -# B608 : hardcoded_sql_expressions -# B609 : linux_commands_wildcard_injection -# B610 : django_extra_used -# B611 : django_rawsql_used -# B701 : jinja2_autoescape_false -# B702 : use_of_mako_templates -# B703 : django_mark_safe - -# (optional) list included test IDs here, eg '[B101, B406]': -tests: - -# (optional) list skipped test IDs here, eg '[B101, B406]': -# B404:blacklist - subprocess -# B603:subprocess_without_shell_equals_true -skips: ['B404', 'B603'] - -### (optional) plugin settings - some test plugins require configuration data -### that may be given here, per-plugin. All bandit test plugins have a built in -### set of sensible defaults and these will be used if no configuration is -### provided. It is not necessary to provide settings for every (or any) plugin -### if the defaults are acceptable. - -any_other_function_with_shell_equals_true: - no_shell: - - os.execl - - os.execle - - os.execlp - - os.execlpe - - os.execv - - os.execve - - os.execvp - - os.execvpe - - os.spawnl - - os.spawnle - - os.spawnlp - - os.spawnlpe - - os.spawnv - - os.spawnve - - os.spawnvp - - os.spawnvpe - - os.startfile - shell: - - os.system - - os.popen - - os.popen2 - - os.popen3 - - os.popen4 - - popen2.popen2 - - popen2.popen3 - - popen2.popen4 - - popen2.Popen3 - - popen2.Popen4 - - commands.getoutput - - commands.getstatusoutput - subprocess: - - subprocess.Popen - - subprocess.call - - subprocess.check_call - - subprocess.check_output - - subprocess.run -hardcoded_tmp_directory: - tmp_dirs: - - /tmp - - /var/tmp - - /dev/shm -linux_commands_wildcard_injection: - no_shell: - - os.execl - - os.execle - - os.execlp - - os.execlpe - - os.execv - - os.execve - - os.execvp - - os.execvpe - - os.spawnl - - os.spawnle - - os.spawnlp - - os.spawnlpe - - os.spawnv - - os.spawnve - - os.spawnvp - - os.spawnvpe - - os.startfile - shell: - - os.system - - os.popen - - os.popen2 - - os.popen3 - - os.popen4 - - popen2.popen2 - - popen2.popen3 - - popen2.popen4 - - popen2.Popen3 - - popen2.Popen4 - - commands.getoutput - - commands.getstatusoutput - subprocess: - - subprocess.Popen - - subprocess.call - - subprocess.check_call - - subprocess.check_output - - subprocess.run -ssl_with_bad_defaults: - bad_protocol_versions: - - PROTOCOL_SSLv2 - - SSLv2_METHOD - - SSLv23_METHOD - - PROTOCOL_SSLv3 - - PROTOCOL_TLSv1 - - SSLv3_METHOD - - TLSv1_METHOD -ssl_with_bad_version: - bad_protocol_versions: - - PROTOCOL_SSLv2 - - SSLv2_METHOD - - SSLv23_METHOD - - PROTOCOL_SSLv3 - - PROTOCOL_TLSv1 - - SSLv3_METHOD - - TLSv1_METHOD -start_process_with_a_shell: - no_shell: - - os.execl - - os.execle - - os.execlp - - os.execlpe - - os.execv - - os.execve - - os.execvp - - os.execvpe - - os.spawnl - - os.spawnle - - os.spawnlp - - os.spawnlpe - - os.spawnv - - os.spawnve - - os.spawnvp - - os.spawnvpe - - os.startfile - shell: - - os.system - - os.popen - - os.popen2 - - os.popen3 - - os.popen4 - - popen2.popen2 - - popen2.popen3 - - popen2.popen4 - - popen2.Popen3 - - popen2.Popen4 - - commands.getoutput - - commands.getstatusoutput - subprocess: - - subprocess.Popen - - subprocess.call - - subprocess.check_call - - subprocess.check_output - - subprocess.run -start_process_with_no_shell: - no_shell: - - os.execl - - os.execle - - os.execlp - - os.execlpe - - os.execv - - os.execve - - os.execvp - - os.execvpe - - os.spawnl - - os.spawnle - - os.spawnlp - - os.spawnlpe - - os.spawnv - - os.spawnve - - os.spawnvp - - os.spawnvpe - - os.startfile - shell: - - os.system - - os.popen - - os.popen2 - - os.popen3 - - os.popen4 - - popen2.popen2 - - popen2.popen3 - - popen2.popen4 - - popen2.Popen3 - - popen2.Popen4 - - commands.getoutput - - commands.getstatusoutput - subprocess: - - subprocess.Popen - - subprocess.call - - subprocess.check_call - - subprocess.check_output - - subprocess.run -start_process_with_partial_path: - no_shell: - - os.execl - - os.execle - - os.execlp - - os.execlpe - - os.execv - - os.execve - - os.execvp - - os.execvpe - - os.spawnl - - os.spawnle - - os.spawnlp - - os.spawnlpe - - os.spawnv - - os.spawnve - - os.spawnvp - - os.spawnvpe - - os.startfile - shell: - - os.system - - os.popen - - os.popen2 - - os.popen3 - - os.popen4 - - popen2.popen2 - - popen2.popen3 - - popen2.popen4 - - popen2.Popen3 - - popen2.Popen4 - - commands.getoutput - - commands.getstatusoutput - subprocess: - - subprocess.Popen - - subprocess.call - - subprocess.check_call - - subprocess.check_output - - subprocess.run -subprocess_popen_with_shell_equals_true: - no_shell: - - os.execl - - os.execle - - os.execlp - - os.execlpe - - os.execv - - os.execve - - os.execvp - - os.execvpe - - os.spawnl - - os.spawnle - - os.spawnlp - - os.spawnlpe - - os.spawnv - - os.spawnve - - os.spawnvp - - os.spawnvpe - - os.startfile - shell: - - os.system - - os.popen - - os.popen2 - - os.popen3 - - os.popen4 - - popen2.popen2 - - popen2.popen3 - - popen2.popen4 - - popen2.Popen3 - - popen2.Popen4 - - commands.getoutput - - commands.getstatusoutput - subprocess: - - subprocess.Popen - - subprocess.call - - subprocess.check_call - - subprocess.check_output - - subprocess.run -subprocess_without_shell_equals_true: - no_shell: - - os.execl - - os.execle - - os.execlp - - os.execlpe - - os.execv - - os.execve - - os.execvp - - os.execvpe - - os.spawnl - - os.spawnle - - os.spawnlp - - os.spawnlpe - - os.spawnv - - os.spawnve - - os.spawnvp - - os.spawnvpe - - os.startfile - shell: - - os.system - - os.popen - - os.popen2 - - os.popen3 - - os.popen4 - - popen2.popen2 - - popen2.popen3 - - popen2.popen4 - - popen2.Popen3 - - popen2.Popen4 - - commands.getoutput - - commands.getstatusoutput - subprocess: - - subprocess.Popen - - subprocess.call - - subprocess.check_call - - subprocess.check_output - - subprocess.run -try_except_continue: - check_typed_exception: false -try_except_pass: - check_typed_exception: false -weak_cryptographic_key: - weak_key_size_dsa_high: 1024 - weak_key_size_dsa_medium: 2048 - weak_key_size_ec_high: 160 - weak_key_size_ec_medium: 224 - weak_key_size_rsa_high: 1024 - weak_key_size_rsa_medium: 2048 - diff --git a/ci/appveyor-bootstrap.py b/ci/appveyor-bootstrap.py index d4d09dc..a82e7df 100644 --- a/ci/appveyor-bootstrap.py +++ b/ci/appveyor-bootstrap.py @@ -5,6 +5,7 @@ with various fixes and improvements that just weren't feasible to implement in PowerShell. """ from __future__ import print_function + from os import environ from os.path import exists from subprocess import check_call diff --git a/ci/appveyor-download.py b/ci/appveyor-download.py index c67ba4e..484674b 100755 --- a/ci/appveyor-download.py +++ b/ci/appveyor-download.py @@ -8,9 +8,9 @@ """ from __future__ import unicode_literals -import argparse import os import zipfile +import argparse import requests diff --git a/ci/bootstrap.py b/ci/bootstrap.py index 2d14d54..a2075c9 100755 --- a/ci/bootstrap.py +++ b/ci/bootstrap.py @@ -1,15 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals +from __future__ import print_function, absolute_import, unicode_literals import os import sys -from os.path import abspath -from os.path import dirname -from os.path import exists -from os.path import join +from os.path import join, exists, abspath, dirname base_path = dirname(dirname(abspath(__file__))) @@ -90,4 +85,3 @@ def main(): else: print("Unexpected arguments {0}".format(args), file=sys.stderr) sys.exit(1) - diff --git a/ci/templates/tox.ini b/ci/templates/tox.ini index 5d0bb3c..4804b12 100644 --- a/ci/templates/tox.ini +++ b/ci/templates/tox.ini @@ -8,9 +8,6 @@ envlist = {% endfor %} report -[pytest] -testpaths = tests - [testenv] basepython = docs: {env:TOXPYTHON:python3} @@ -23,6 +20,7 @@ passenv = deps = pytest pytest-travis-fold + coverage[toml] commands = python setup.py clean --all build_ext --force --inplace {posargs:pytest -vv --ignore=src} @@ -50,9 +48,9 @@ commands = python setup.py check --strict --metadata --restructuredtext check-manifest {toxinidir} black src tests setup.py - flake8 src tests setup.py + flake8 --config flake8.ini src tests setup.py isort --verbose --check-only --diff --recursive src tests setup.py - bandit -c bandit.yml -r src + bandit -r src [testenv:docs] usedevelop = true diff --git a/.flake8 b/flake8.ini similarity index 100% rename from .flake8 rename to flake8.ini diff --git a/pyproject.toml b/pyproject.toml index 9ec322b..d6bd3fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,8 +42,17 @@ classifiers = [ [build-system] requires = ["setuptools", "wheel"] # PEP 508 specifications. + +# Tools: +# Enabled so far: +# - Black +# - coverage +# - isort +# + [tool.black] -line-length = 79 +line-length = 90 +target-version= ['py36', 'py37', 'py38', ] include = '\.pyi?$' exclude = ''' /( @@ -58,3 +67,26 @@ exclude = ''' | dist )/ ''' + +[tool.coverage] + [[tool.coverage.paths]] + source = ['src'] + + [[tool.coverage.run]] + branch = true + source = ['src', 'tests'] + parallel = true + omit = ['src/memwiper/utils/_coretest.py'] + + [[tool.coverage.report]] + show_missing = true + precision = 2 + omit = ['*migrations*'] + +[tool.isort] +line_length = 120 +indent = ' ' +multi_line_output = 6 +length_sort = true +balanced_wrapping = true +known_first_party = ['memwiper'] diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..b31688c --- /dev/null +++ b/pytest.ini @@ -0,0 +1,26 @@ +[pytest] +norecursedirs = + .git + .tox + .env + .ropeproject + dist + build + migrations +python_files = + test_*.py + *_test.py + tests.py +addopts = + -ra + --strict + --ignore=docs/conf.py + --ignore=setup.py + --ignore=ci + --ignore=.eggs + --doctest-modules + --doctest-glob=\*.rst + --tb=short +testpaths = + tests + diff --git a/readthedocs.yml b/readthedocs.yml new file mode 100644 index 0000000..27794c0 --- /dev/null +++ b/readthedocs.yml @@ -0,0 +1,5 @@ +version: 2 +formats: all +python: + install: + - requirements: docs/requirements.txt diff --git a/requirements-dev.txt b/requirements-dev.txt index 4077b2e..9561eb0 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,11 +1,13 @@ +bandit +black bumpversion +codacy-coverage +coveralls +codecov pytest +pytest-bandit +pytest-black pytest-cov pytest-faulthandler -tox requires.io -jedi -black -codacy-coverage -coveralls -codecov +tox diff --git a/setup.cfg b/setup.cfg index 8e9b528..e1bdfea 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,3 @@ -[flake8] -max-line-length = 140 -exclude = */migrations/* - [options] # tests_require is a list of dependencies that are *absolutely required* # to run the tests. tests_require is used when running tests from your @@ -27,46 +23,6 @@ tests_require = pytest # Alias `setup.py test` to `setup.py pytest` test = pytest -[tool:pytest] -# If a pytest section is found in one of the possible config files -# (pytest.ini, tox.ini or setup.cfg), then pytest will not look for any others, -# so if you add a pytest config section elsewhere, -# you will need to delete this section from setup.cfg. -norecursedirs = - .git - .tox - .env - .ropeproject - dist - build - migrations - -python_files = - test_*.py - *_test.py - tests.py -addopts = - -ra - --strict - --ignore=docs/conf.py - --ignore=setup.py - --ignore=ci - --ignore=.eggs - --doctest-modules - --doctest-glob=\*.rst - --tb=short -testpaths = - tests - -[tool:isort] -force_single_line = True -line_length = 120 -known_first_party = memwiper -default_section = THIRDPARTY -forced_separate = test_memwiper -not_skip = __init__.py -skip = migrations - [matrix] # This is the configuration for the `./bootstrap.py` script. # It generates `.travis.yml`, `tox.ini` and `.appveyor.yml`. diff --git a/setup.py b/setup.py index eb218ce..7c82d3d 100644 --- a/setup.py +++ b/setup.py @@ -1,27 +1,19 @@ #!/usr/bin/env python # -*- encoding: utf-8 -*- -from __future__ import absolute_import -from __future__ import print_function +from __future__ import print_function, absolute_import import io import os import re from glob import glob -from os.path import basename -from os.path import dirname -from os.path import join -from os.path import relpath -from os.path import splitext +from os.path import join, dirname, relpath, basename, splitext -from setuptools import Extension -from setuptools import find_packages -from setuptools import setup +from setuptools import Extension, setup, find_packages def read(*names, **kwargs): with io.open( - join(dirname(__file__), *names), - encoding=kwargs.get("encoding", "utf8"), + join(dirname(__file__), *names), encoding=kwargs.get("encoding", "utf8"), ) as fh: return fh.read() @@ -33,9 +25,7 @@ def read(*names, **kwargs): os.environ["CFLAGS"] = os.environ["SETUPPY_CFLAGS"] if "CFLAGS" in os.environ: - os.environ["CFLAGS"] = " ".join( - (os.environ["CFLAGS"], "-DMEMWIPER_DEBUG=1") - ) + os.environ["CFLAGS"] = " ".join((os.environ["CFLAGS"], "-DMEMWIPER_DEBUG=1")) else: os.environ["CFLAGS"] = "-DMEMWIPER_DEBUG=1" diff --git a/src/memwiper/utils/__init__.py b/src/memwiper/utils/__init__.py index 3963dbd..f8618fa 100644 --- a/src/memwiper/utils/__init__.py +++ b/src/memwiper/utils/__init__.py @@ -1,6 +1,4 @@ -from memwiper.c_src.memwiper_utils import codepoints -from memwiper.c_src.memwiper_utils import kind -from memwiper.c_src.memwiper_utils import size +from memwiper.c_src.memwiper_utils import kind, size, codepoints __all__ = [ "kind", diff --git a/src/memwiper/utils/_coretest.py b/src/memwiper/utils/_coretest.py index 84f9090..21ae1d5 100644 --- a/src/memwiper/utils/_coretest.py +++ b/src/memwiper/utils/_coretest.py @@ -1,11 +1,11 @@ -import codecs -import getpass -import multiprocessing import os -import platform import shlex +import codecs import shutil +import getpass +import platform import subprocess +import multiprocessing from sys import exit as sysexit import memwiper @@ -67,9 +67,7 @@ def main(): # "Decoding" the file: s1 = codecs.encode(sfromfile, "rot_13") # Generating pre-core - print( - "Generating {f}.{pid}:".format(f=corefn.format(when="pre"), pid=mypid) - ) + print("Generating {f}.{pid}:".format(f=corefn.format(when="pre"), pid=mypid)) cmd = gdb_cmds corename = corefn.format(when="pre") print(cmd.format(filename=corename, pid=mypid)) @@ -77,9 +75,7 @@ def main(): print("Now we're going to overwrite the memory,") memwiper.wipeit(s1) # Generating pos-core - print( - "Generating {f}.{pid}:".format(f=corefn.format(when="pos"), pid=mypid) - ) + print("Generating {f}.{pid}:".format(f=corefn.format(when="pos"), pid=mypid)) corename = corefn.format(when="pos") print(cmd.format(filename=corename, pid=mypid)) subprocess.run(shlex.split(cmd.format(filename=corename, pid=mypid))) diff --git a/tests/test_memwiper.py b/tests/test_memwiper.py index b8567bd..9d9ee9d 100644 --- a/tests/test_memwiper.py +++ b/tests/test_memwiper.py @@ -1,5 +1,4 @@ -import pytest # noqa: F401 - +import pytest import memwiper diff --git a/tests/test_memwiper_utils.py b/tests/test_memwiper_utils.py index 900814d..b7eda8c 100644 --- a/tests/test_memwiper_utils.py +++ b/tests/test_memwiper_utils.py @@ -1,9 +1,7 @@ -import pytest # noqa: F401 - +import pytest import memwiper.utils as mwutils UNICODE_KIND = ["Wide Char", "1 Byte", "2 Byte", "4 Byte"] - UNICODE_WIDTH = {"1 Byte": 1, "2 Byte": 2, "4 Byte": 4} # AFAIK the Wide Char is only used as representation on diff --git a/tox.ini b/tox.ini index 3d03b8e..8768d98 100644 --- a/tox.ini +++ b/tox.ini @@ -13,9 +13,6 @@ envlist = py38-nocov, report -[pytest] -testpaths = tests - [testenv] basepython = docs: {env:TOXPYTHON:python3} @@ -28,6 +25,7 @@ passenv = deps = pytest pytest-travis-fold + coverage[toml] commands = python setup.py clean --all build_ext --force --inplace {posargs:pytest -vv --ignore=src} @@ -55,9 +53,9 @@ commands = python setup.py check --strict --metadata --restructuredtext check-manifest {toxinidir} black src tests setup.py - flake8 src tests setup.py + flake8 --config flake8.ini src tests setup.py isort --verbose --check-only --diff --recursive src tests setup.py - bandit -c bandit.yml -r src + bandit -r src [testenv:docs] usedevelop = true