Skip to content

Commit

Permalink
Merge branch 'features'
Browse files Browse the repository at this point in the history
* fixes:
  Bump to version 0.43.0
  [FIX] Misc compatibility fixes
  Be explicit with kwarg
  [ENH] Loosen up dev requirements
  [DOC] Show a csv dialect example (closes #22)
  [NEW] Add `whitelist` option to remove_keys
  [ENH] Add prettify command and use it!
  [ENH] Pass kwargs to date parser (closes #16)
  Fix incorrect int parsing during is_numeric checks
  • Loading branch information
reubano committed Dec 24, 2021
2 parents ff1f881 + 68697f8 commit c298144
Show file tree
Hide file tree
Showing 17 changed files with 1,126 additions and 978 deletions.
5 changes: 3 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
wheel>=0.29.0
responses>=0.9.0,<0.10.0
coverage>=4.3.4,<5.0.0
black>=19.3b0,<22.0
flake8>=3.8.3,<4.0.0
flake8-black>=0.1.1,<0.3.0
nose>=1.3.7,<2.0.0
pylint>=2.5.0,<3.0.0
setuptools>=38.7.0,<40.0.0
tox>=3.14.3,<4.0.0
twine>=3.2.0,<4.0.0
virtualenv>=15.1.0,<16.0.0
wheel>=0.29.0,<0.32.0
pkutils>=1.2.1,<=3.0.0
manage.py>=0.2.10,<0.3.0
113 changes: 60 additions & 53 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,106 +9,113 @@

manager = Manager()
BASEDIR = p.dirname(__file__)
DEF_WHERE = ["meza", "tests", "setup.py", "manage.py"]
DEF_WHERE = ["meza", "tests", "examples", "setup.py", "manage.py"]


def upload_():
"""Upload distribution files"""
command = 'twine upload --repository-url https://upload.pypi.org/legacy/ {0}'
check_call(command.format(p.join(BASEDIR, 'dist', '*')).split(' '))
command = "twine upload --repository-url https://upload.pypi.org/legacy/ {0}"
check_call(command.format(p.join(BASEDIR, "dist", "*")).split(" "))


def sdist_():
"""Create a source distribution package"""
check_call(p.join(BASEDIR, 'helpers', 'srcdist'))
check_call(p.join(BASEDIR, "helpers", "srcdist"))


def wheel_():
"""Create a wheel package"""
check_call(p.join(BASEDIR, 'helpers', 'wheel'))
check_call(p.join(BASEDIR, "helpers", "wheel"))


def clean_():
"""Remove Python file and build artifacts"""
check_call(p.join(BASEDIR, 'helpers', 'clean'))
check_call(p.join(BASEDIR, "helpers", "clean"))


@manager.command
def check():
"""Check staged changes for lint errors"""
exit(call(p.join(BASEDIR, 'helpers', 'check-stage')))
exit(call(p.join(BASEDIR, "helpers", "check-stage")))


@manager.arg('where', 'w', help='Modules to check', default='meza')
@manager.arg('strict', 's', help='Check with pylint')
@manager.arg('compatibility', 'c', help='Check with pylint porting checker')
@manager.arg("where", "w", help="Modules to check")
@manager.arg("strict", "s", help="Check with pylint")
@manager.command
def lint(where=None, strict=False, compatibility=False):
def lint(where=None, strict=False):
"""Check style with linters"""
_where = where or ' '.join(DEF_WHERE)
command = f"pylint --rcfile=tests/standard.rc -rn -fparseable {_where}"
extra = where.split(" ") if where else DEF_WHERE
args = ["pylint", "--rcfile=tests/pylintrc", "-rn", "-fparseable"]

try:
check_call(['flake8'] + _where.split(' '))

if strict:
check_call(command, shell=True)
check_call(args + extra)
else:
check_call(["flake8"] + extra)
except CalledProcessError as e:
exit(e.returncode)

if compatibility:
check_call(f"{command} --py3k", shell=True)

@manager.arg("where", "w", help="Modules to check")
@manager.command
def prettify(where=None):
"""Prettify code with black"""
extra = where.split(" ") if where else DEF_WHERE

try:
check_call(["black"] + extra)
except CalledProcessError as e:
exit(e.returncode)


@manager.command
def pipme():
"""Install requirements.txt"""
exit(call('pip install -r requirements.txt'.split(' ')))
exit(call("pip install -r requirements.txt".split(" ")))


@manager.command
def require():
"""Create requirements.txt"""
cmd = 'pip freeze -l | grep -vxFf dev-requirements.txt > requirements.txt'
exit(call(cmd.split(' ')))


@manager.arg('source', 's', help='the tests to run', default=None)
@manager.arg('where', 'w', help='test path', default=None)
@manager.arg(
'stop', 'x', help='Stop after first error', type=bool, default=False)
@manager.arg(
'failed', 'f', help='Run failed tests', type=bool, default=False)
@manager.arg(
'cover', 'c', help='Add coverage report', type=bool, default=False)
@manager.arg('tox', 't', help='Run tox tests', type=bool, default=False)
@manager.arg('detox', 'd', help='Run detox tests', type=bool, default=False)
@manager.arg(
'verbose', 'v', help='Use detailed errors', type=bool, default=False)
@manager.arg(
'parallel', 'p', help='Run tests in parallel in multiple processes',
type=bool, default=False)
cmd = "pip freeze -l | grep -vxFf dev-requirements.txt > requirements.txt"
exit(call(cmd.split(" ")))


@manager.arg("source", "s", help="the tests to run", default=None)
@manager.arg("where", "w", help="test path", default=None)
@manager.arg("stop", "x", help="Stop after first error", type=bool, default=False)
@manager.arg("failed", "f", help="Run failed tests", type=bool, default=False)
@manager.arg("cover", "c", help="Add coverage report", type=bool, default=False)
@manager.arg("tox", "t", help="Run tox tests", type=bool, default=False)
@manager.arg("detox", "d", help="Run detox tests", type=bool, default=False)
@manager.arg("verbose", "v", help="Use detailed errors", type=bool, default=False)
@manager.arg(
'debug', 'D', help='Use nose.loader debugger', type=bool, default=False)
"parallel",
"p",
help="Run tests in parallel in multiple processes",
type=bool,
default=False,
)
@manager.arg("debug", "D", help="Use nose.loader debugger", type=bool, default=False)
@manager.command
def test(source=None, where=None, stop=False, **kwargs):
"""Run nose, tox, and script tests"""
opts = '-xv' if stop else '-v'
opts += ' --with-coverage' if kwargs.get('cover') else ''
opts += ' --failed' if kwargs.get('failed') else ' --with-id'
opts += ' --processes=-1' if kwargs.get('parallel') else ''
opts += ' --detailed-errors' if kwargs.get('verbose') else ''
opts += ' --debug=nose.loader' if kwargs.get('debug') else ''
opts += ' -w {}'.format(where) if where else ''
opts += ' {}'.format(source) if source else ''
opts = "-xv" if stop else "-v"
opts += " --with-coverage" if kwargs.get("cover") else ""
opts += " --failed" if kwargs.get("failed") else " --with-id"
opts += " --processes=-1" if kwargs.get("parallel") else ""
opts += " --detailed-errors" if kwargs.get("verbose") else ""
opts += " --debug=nose.loader" if kwargs.get("debug") else ""
opts += " -w {}".format(where) if where else ""
opts += " {}".format(source) if source else ""

try:
if kwargs.get('tox'):
check_call('tox')
elif kwargs.get('detox'):
check_call('detox')
if kwargs.get("tox"):
check_call("tox")
elif kwargs.get("detox"):
check_call("detox")
else:
check_call(('nosetests {}'.format(opts)).split(' '))
check_call(("nosetests {}".format(opts)).split(" "))
except CalledProcessError as e:
exit(e.returncode)

Expand Down Expand Up @@ -172,5 +179,5 @@ def clean():
exit(e.returncode)


if __name__ == '__main__':
if __name__ == "__main__":
manager.main()
24 changes: 12 additions & 12 deletions meza/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
from datetime import datetime as dt
from os import path as p

__version__ = '0.42.5'
__title__ = 'meza'
__package_name__ = 'meza'
__author__ = 'Reuben Cummings'
__description__ = 'A Python toolkit for processing tabular data'
__email__ = '[email protected]'
__license__ = 'MIT'
__copyright__ = 'Copyright 2015 Reuben Cummings'
__version__ = "0.43.0"
__title__ = "meza"
__package_name__ = "meza"
__author__ = "Reuben Cummings"
__description__ = "A Python toolkit for processing tabular data"
__email__ = "[email protected]"
__license__ = "MIT"
__copyright__ = "Copyright 2015 Reuben Cummings"

CURRENCIES = ('$', '£', '€')
ENCODING = 'utf-8'
CURRENCIES = ("$", "£", "€")
ENCODING = "utf-8"
DEFAULT_DATETIME = dt(9999, 12, 31, 0, 0, 0)
BOM = '\ufeff'
BOM = "\ufeff"
PARENT_DIR = p.abspath(p.dirname(p.dirname(__file__)))
DATA_DIR = p.join(PARENT_DIR, 'data', 'test')
DATA_DIR = p.join(PARENT_DIR, "data", "test")
6 changes: 3 additions & 3 deletions meza/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ def encode(content, encoding=ENCODING):
>>> encode(content.encode('utf-8')) == content.encode('utf-8')
True
"""
if hasattr(content, 'real'):
if hasattr(content, "real"):
try:
length = (content.bit_length() // 8) + 1
except AttributeError:
encoded = content
else:
encoded = content.to_bytes(length, byteorder='big')
elif hasattr(content, 'encode'):
encoded = content.to_bytes(length, byteorder="big")
elif hasattr(content, "encode"):
try:
encoded = ENCODER(encoding).encode(content)
except UnicodeDecodeError:
Expand Down
Loading

0 comments on commit c298144

Please sign in to comment.