Skip to content

Commit

Permalink
Reformat using black
Browse files Browse the repository at this point in the history
  • Loading branch information
chocobn69 committed Jul 13, 2021
1 parent 7c92f79 commit 80f5470
Show file tree
Hide file tree
Showing 22 changed files with 740 additions and 363 deletions.
197 changes: 98 additions & 99 deletions doc/conf.py

Large diffs are not rendered by default.

159 changes: 89 additions & 70 deletions scripts/bumpversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,39 @@
from argparse import RawTextHelpFormatter, ArgumentParser, FileType


if (sys.version_info[0] == 3):
if sys.version_info[0] == 3:
bytes = bytes
str = type(u"")
str = type("")
basestring = (str, bytes)

def is_bytes(x):
return isinstance(x, (bytes, memoryview, bytearray))


else:
bytes = str
str = type(u"")
str = type("")
basestring = basestring

def is_bytes(x):
return isinstance(x, (buffer, bytearray))


def to_unicode(obj, encoding='utf-8'):
""" Convert ``obj`` to unicode"""
def to_unicode(obj, encoding="utf-8"):
"""Convert ``obj`` to unicode"""
# unicode support
if isinstance(obj, str):
return obj

# bytes support
if is_bytes(obj):
if hasattr(obj, 'tobytes'):
if hasattr(obj, "tobytes"):
return str(obj.tobytes(), encoding)
return str(obj, encoding)

# string support
if isinstance(obj, basestring):
if hasattr(obj, 'decode'):
if hasattr(obj, "decode"):
return obj.decode(encoding)
else:
return str(obj, encoding)
Expand All @@ -68,29 +69,32 @@ def get_release_date():
def bump_release_version(args):
"""Automated software release workflow
* Bumps the release version number (with .bumpversion.cfg)
* Preloads the correct changelog template for editing
* Builds a source distribution
* Sets release date
* Tags the release
* Bumps the release version number (with .bumpversion.cfg)
* Preloads the correct changelog template for editing
* Builds a source distribution
* Sets release date
* Tags the release
You can run it like::
You can run it like::
$ python bumpversion.py
$ python bumpversion.py
which will create a 'release' version (Eg. 0.7.2-dev => 0.7.2).
which will create a 'release' version (Eg. 0.7.2-dev => 0.7.2).
"""
# Dry run 'bumpversion' to find out what the new version number
# would be. Useful side effect: exits if the working directory is not
# clean.
changelog = args.changelog.name
bumpver = to_unicode(subprocess.check_output(
['bumpversion', 'release', '--dry-run', '--verbose'],
stderr=subprocess.STDOUT))
m = re.search(r'Parsing version \'(\d+\.\d+\.\d+)\.dev0\'', bumpver)
bumpver = to_unicode(
subprocess.check_output(
["bumpversion", "release", "--dry-run", "--verbose"],
stderr=subprocess.STDOUT,
)
)
m = re.search(r"Parsing version \'(\d+\.\d+\.\d+)\.dev0\'", bumpver)
current_version = m.groups(0)[0] + ".dev0"
m = re.search(r'New version will be \'(\d+\.\d+\.\d+)\'', bumpver)
m = re.search(r"New version will be \'(\d+\.\d+\.\d+)\'", bumpver)
release_version = m.groups(0)[0]

date = get_release_date()
Expand All @@ -101,60 +105,64 @@ def bump_release_version(args):
with open(changelog) as fd:
changes += fd.read()

changes = changes.replace(current_version_title, release_version_title)\
.replace("**unreleased**", "Released on %s" % date)
changes = changes.replace(current_version_title, release_version_title).replace(
"**unreleased**", "Released on %s" % date
)

with open(changelog, "w") as fd:
fd.write(changes)
fd.write(changes)

# Tries to load the EDITOR environment variable, else falls back to vim
editor = os.environ.get('EDITOR', 'vim')
editor = os.environ.get("EDITOR", "vim")
os.system("{} {}".format(editor, changelog))

subprocess.check_output(['python', 'setup.py', 'sdist'])
subprocess.check_output(["python", "setup.py", "sdist"])

# Have to add it so it will be part of the commit
subprocess.check_output(['git', 'add', changelog])
subprocess.check_output(["git", "add", changelog])
subprocess.check_output(
['git', 'commit', '-m', 'Changelog for {}'.format(release_version)])
["git", "commit", "-m", "Changelog for {}".format(release_version)]
)

# Really run bumpver to set the new release and tag
bv_args = ['bumpversion', 'release']
bv_args = ["bumpversion", "release"]

bv_args += ['--new-version', release_version]
bv_args += ["--new-version", release_version]

subprocess.check_output(bv_args)


def bump_new_version(args):
"""Increment the version number to the next development version
* Bumps the development version number (with .bumpversion.cfg)
* Preloads the correct changelog template for editing
* Bumps the development version number (with .bumpversion.cfg)
* Preloads the correct changelog template for editing
You can run it like::
You can run it like::
$ python bumpversion.py newversion
$ python bumpversion.py newversion
which, by default, will create a 'patch' dev version (0.0.1 => 0.0.2-dev).
which, by default, will create a 'patch' dev version (0.0.1 => 0.0.2-dev).
You can also specify a patch level (patch, minor, major) to change to::
You can also specify a patch level (patch, minor, major) to change to::
$ python bumpversion.py newversion major
$ python bumpversion.py newversion major
which will create a 'major' release (0.0.2 => 1.0.0-dev)."""
which will create a 'major' release (0.0.2 => 1.0.0-dev)."""
pass
# Dry run 'bumpversion' to find out what the new version number
# would be. Useful side effect: exits if the working directory is not
# clean.
changelog = args.changelog.name
part = args.part
bumpver = to_unicode(subprocess.check_output(
['bumpversion', part, '--dry-run', '--verbose'],
stderr=subprocess.STDOUT))
m = re.search(r'Parsing version \'(\d+\.\d+\.\d+)\'', bumpver)
bumpver = to_unicode(
subprocess.check_output(
["bumpversion", part, "--dry-run", "--verbose"], stderr=subprocess.STDOUT
)
)
m = re.search(r"Parsing version \'(\d+\.\d+\.\d+)\'", bumpver)
current_version = m.groups(0)[0]
m = re.search(r'New version will be \'(\d+\.\d+\.\d+)\.dev0\'', bumpver)
m = re.search(r"New version will be \'(\d+\.\d+\.\d+)\.dev0\'", bumpver)
next_version = m.groups(0)[0] + ".dev0"

current_version_title = generate_changelog_title(current_version)
Expand All @@ -166,61 +174,72 @@ def bump_new_version(args):
with open(changelog) as fd:
changes += fd.read()

changes = changes.replace(current_version_title,
next_release_template + current_version_title)
changes = changes.replace(
current_version_title, next_release_template + current_version_title
)

with open(changelog, "w") as fd:
fd.write(changes)
fd.write(changes)

# Tries to load the EDITOR environment variable, else falls back to vim
editor = os.environ.get('EDITOR', 'vim')
editor = os.environ.get("EDITOR", "vim")
os.system("{} {}".format(editor, changelog))

subprocess.check_output(['python', 'setup.py', 'sdist'])
subprocess.check_output(["python", "setup.py", "sdist"])

# Have to add it so it will be part of the commit
subprocess.check_output(['git', 'add', changelog])
subprocess.check_output(["git", "add", changelog])
subprocess.check_output(
['git', 'commit', '-m', 'Changelog for {}'.format(next_version)])
["git", "commit", "-m", "Changelog for {}".format(next_version)]
)

# Really run bumpver to set the new release and tag
bv_args = ['bumpversion', part, '--no-tag', '--new-version', next_version]
bv_args = ["bumpversion", part, "--no-tag", "--new-version", next_version]

subprocess.check_output(bv_args)


def main():
'''Parse command-line arguments and execute bumpversion command.'''
"""Parse command-line arguments and execute bumpversion command."""

parser = ArgumentParser(prog='bumpversion',
description='Bumpversion wrapper')
parser = ArgumentParser(prog="bumpversion", description="Bumpversion wrapper")

default_changelog = os.path.join(os.getcwd(), 'CHANGES.rst')
default_changelog = os.path.join(os.getcwd(), "CHANGES.rst")

subparsers = parser.add_subparsers(title='bumpversion wrapper commands')
subparsers = parser.add_subparsers(title="bumpversion wrapper commands")
# release command
release_doc = bump_release_version.__doc__
subparser = subparsers.add_parser("release",
description=release_doc,
formatter_class=RawTextHelpFormatter)
subparser.add_argument('--changelog', help='Project changelog',
type=FileType(),
default=default_changelog)
subparser = subparsers.add_parser(
"release", description=release_doc, formatter_class=RawTextHelpFormatter
)
subparser.add_argument(
"--changelog",
help="Project changelog",
type=FileType(),
default=default_changelog,
)
subparser.set_defaults(func=bump_release_version)
# newversion command
newversion_doc = bump_new_version.__doc__
subparser = subparsers.add_parser("newversion",
description=newversion_doc,
formatter_class=RawTextHelpFormatter)
subparser.add_argument('--changelog', help='Project changelog',
type=FileType(),
default=default_changelog)
subparser.add_argument('part', help='Part of the version to be bumped',
choices=['patch', 'minor', 'major'])
subparser = subparsers.add_parser(
"newversion", description=newversion_doc, formatter_class=RawTextHelpFormatter
)
subparser.add_argument(
"--changelog",
help="Project changelog",
type=FileType(),
default=default_changelog,
)
subparser.add_argument(
"part",
help="Part of the version to be bumped",
choices=["patch", "minor", "major"],
)
subparser.set_defaults(func=bump_new_version)
# Parse argv arguments
args = parser.parse_args()
args.func(args)

if __name__ == '__main__':

if __name__ == "__main__":
main()
39 changes: 20 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@


def read(fname):
''' Return the file content. '''
"""Return the file content."""
here = op.abspath(op.dirname(__file__))
with open(op.join(here, fname), 'r', 'utf-8') as fd:
with open(op.join(here, fname), "r", "utf-8") as fd:
return fd.read()


readme = read('README.rst')
changelog = read('CHANGES.rst').replace('.. :changelog:', '')
readme = read("README.rst")
changelog = read("CHANGES.rst").replace(".. :changelog:", "")

requirements = [
"requests",
Expand All @@ -26,34 +26,35 @@ def read(fname):
"ftfy",
]

version = ''
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
read(op.join('shiba', '__init__.py')),
re.MULTILINE).group(1)
version = ""
version = re.search(
r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
read(op.join("shiba", "__init__.py")),
re.MULTILINE,
).group(1)

if not version:
raise RuntimeError('Cannot find version information')
raise RuntimeError("Cannot find version information")


setup(
name='Shiba',
name="Shiba",
author="Maxime Boguta",
author_email="[email protected]",
version=version,
url='https://github.com/ShibaAPI/shiba',
url="https://github.com/ShibaAPI/shiba",
packages=["shiba"],
install_requires=requirements,
zip_safe=True,
description="A Python API for PriceMinister WebServices",
long_description=readme + '\n\n' + changelog,
long_description=readme + "\n\n" + changelog,
keywords=["api", "priceminister", "python", "webservices"],
license='GPLv3',
license="GPLv3",
classifiers=[
'Development Status :: 4 - Beta',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Intended Audience :: Developers',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Software Development :: Libraries :: Python Modules',
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Software Development :: Libraries :: Python Modules",
],
)
2 changes: 1 addition & 1 deletion shiba/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '1.1.12'
__version__ = "1.1.12"
VERSION = __version__
17 changes: 12 additions & 5 deletions shiba/accountingmanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@


class AccountingManagement(object):
""" Accounting Management class, showing global financial operations on your account, or specific financial details
about an operation
"""Accounting Management class, showing global financial operations on your account, or specific financial details
about an operation
"""

def __init__(self, connection):
if not isinstance(connection, ShibaConnection):
raise ValueError("expecting a ShibaConnection instance, got '%s'" % type(connection))
raise ValueError(
"expecting a ShibaConnection instance, got '%s'" % type(connection)
)
self.connection = connection

def get_operations(self, lastoperationdate=""):
Expand All @@ -27,8 +29,13 @@ def get_operations(self, lastoperationdate=""):
"""
operationcause = "salestransfer"

if not isinstance(lastoperationdate, date) and not isinstance(lastoperationdate, basestring):
raise ValueError("expected string or date for 'lastoperationdate', got '%s'" % type(lastoperationdate))
if not isinstance(lastoperationdate, date) and not isinstance(
lastoperationdate, basestring
):
raise ValueError(
"expected string or date for 'lastoperationdate', got '%s'"
% type(lastoperationdate)
)

if isinstance(lastoperationdate, date):
lastoperationdate = lastoperationdate.strftime("%d/%m/%y-%H:%M:%S")
Expand Down
Loading

0 comments on commit 80f5470

Please sign in to comment.