Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > Kindle Formats

Notices

Reply
 
Thread Tools Search this Thread
Old 10-15-2014, 02:12 PM   #1051
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,788
Karma: 6000000
Join Date: Nov 2009
Device: many
Hi,

Thanks for the help, but I would need to do that for each of the 60 commits so I might as well just erase the whole thing and start again since setting the author for each commit is needed, right? It would be safer I think anyway.

Also, can you assign more than 1 author for a single commit?

Thanks,

KevinH


Quote:
EDIT: Never mind, in my test it seems as though amending a commit makes it more fussy.
fatal: Malformed ident string: 'Adam Selene <> 1268438400 +0000'

EDIT #2: use this to "amend" a commit by undoing the commit, recommitting using the saved EDITMSG, then continuing rebase:

Code:
git undo-commit && git commit --author="Adam Selene <>" -m "$(cat .git/COMMIT_EDITMSG)" && git rebase --continue
...
...
Assumes you have created the following alias (should be git builtin):
Code:
# revert "git commit", leaving you with staged changes.
git config --global alias.undo-commit 'reset --soft HEAD^'
KevinH is online now   Reply With Quote
Old 10-15-2014, 02:22 PM   #1052
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Quote:
Originally Posted by KevinH View Post
Hi,

Thanks for the help, but I would need to do that for each of the 60 commits so I might as well just erase the whole thing and start again since setting the author for each commit is needed, right? It would be safer I think anyway.

Also, can you assign more than 1 author for a single commit?

Thanks,

KevinH
One commit per author.

Sure you can start over. But currently you have the actual contents of the commits the way you want them, correct?

rebase allows you to keep the content and just edit the metadata of the commits. (It does other things too, of course. )

It's really easy to edit the author each time, just hit the up arrow in your terminal, right-arrow a few times and edit the --author flag. Compare that to cp'ing in the right files, git add -A, then changing the author and email config or overriding via the exact same method I described..., then rewriting the whole commitmsg from scratch rather than editing the current one... (my method preserves the commitmsg generated by rebase)...

Oh yes. If you want to preserve the commitmsg but remove the extraneous authorinfo, you should use --edit -m instead, but once again setting a blank email seems to break. You should probably just use
Code:
git commit --amend --author="Adam Selene <none>" && git rebase --continue
which does absolutely everything right in the first place except for leaving a weirdly fake email address. I am not sure it is worth finding a workaround.

I just love the inconsistency. Really.

EDIT (again): I like the answer below.

You might want to use
Code:
--msg-filter 'sed -e "/Authors[^,]*$/d"'
to remove the authors info if there is only one author listed.

Last edited by eschwartz; 10-15-2014 at 03:06 PM.
eschwartz is offline   Reply With Quote
Advert
Old 10-15-2014, 02:38 PM   #1053
eureka
but forgot what it's like
eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.
 
Posts: 741
Karma: 2345678
Join Date: Dec 2011
Location: north (by northwest)
Device: Kindle Touch
Hope this will help.

Here is a Python 3 script for printing author name basing on your commit message format:
Spoiler:
Code:
#!/usr/bin/env python3

import fileinput
from itertools import chain
import re

# Author names are delimited with comma and spaces after it.
AUTHOR = re.compile('(?:,\s*)?(?P<author>[^,]+)')

def get_authors(commit_log_line):
    leading_spaces, note, authors = commit_log_line.rpartition(' Authors: ')
    # Check for split being done and if prefix really consisting of spaces
    # only (prefix check is a sanity/paranoid check).
    if authors != commit_log_line and not leading_spaces.strip():
        return AUTHOR.findall(authors.strip())

# `chain.from_iterable` flattens list of lists, then `set` removes duplicates.
authors = list(set(chain.from_iterable(
    # Transform stdin line into list of authors or None (if authors were not
    # found in that line) and then filter out None's.
    filter(None, map(get_authors, fileinput.input()))
)))

if len(authors) == 0:
    print("Kevin Hendricks")
elif len(authors) == 1:
    author = authors[0]
    if author == "KevinH":
        print("Kevin Hendricks")
    else:
        print(author)
else:
    print('Various authors')

It could be tested with:
Code:
$ git log -n1 <commit_id> | python3 authors.py
For example:
Code:
$ git log -n1 af0740a3 | python3 authors.py
Kevin Hendricks
$ git log -n1 80150331 | python3 authors.py
Kevin Hendricks
$ git log -n1 7b32b687 | python3 authors.py
tkeo
$ git log -n1 91d3e282 | python3 authors.py
Various authors
And this script could be used with the following --env-filter parameter for git filter-branch:
Code:
--env-filter 'export GIT_AUTHOR_NAME="$(git log -n1 ${GIT_COMMIT} | python3 /full/path/to/authors.py)"; if [ "x${GIT_AUTHOR_NAME}" != "xKevin Hendricks" ]; then export GIT_AUTHOR_EMAIL=""; fi'
This is the result:
Spoiler:
Code:
$ git log|grep '^\(Author\|Date\):'
Code:
Author: Kevin Hendricks <kevinhendricks@users.noreply.github.com>
Date:   Tue Oct 14 18:21:13 2014 -0400
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Fri Oct 10 00:00:00 2014 +0000
Author: Various authors <>
Date:   Sat Sep 13 00:00:00 2014 +0000
Author: Various authors <>
Date:   Tue Jul 15 00:00:00 2014 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Thu Jul 10 00:00:00 2014 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Thu Jul 10 00:00:00 2014 +0000
Author: Various authors <>
Date:   Thu Jul 10 00:00:00 2014 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Thu Jul 10 00:00:00 2014 +0000
Author: Various authors <>
Date:   Tue Jul 8 00:00:00 2014 +0000
Author: Various authors <>
Date:   Thu Jun 26 00:00:00 2014 +0000
Author: Various authors <>
Date:   Wed Jun 25 00:00:00 2014 +0000
Author: tkeo <>
Date:   Sun Jun 22 00:00:00 2014 +0000
Author: Various authors <>
Date:   Wed Jun 18 00:00:00 2014 +0000
Author: Various authors <>
Date:   Tue Jun 17 00:00:00 2014 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Sat Jun 14 00:00:00 2014 +0000
Author: Various authors <>
Date:   Tue Jun 10 00:00:00 2014 +0000
Author: Various authors <>
Date:   Sun May 18 00:00:00 2014 +0000
Author: Various authors <>
Date:   Sat Apr 26 00:00:00 2014 +0000
Author: Various authors <>
Date:   Sun Feb 23 00:00:00 2014 +0000
Author: tkeo <>
Date:   Sun Feb 16 00:00:00 2014 +0000
Author: tkeo <>
Date:   Sun Feb 9 00:00:00 2014 +0000
Author: Various authors <>
Date:   Mon Apr 22 00:00:00 2013 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Fri Jan 17 00:00:00 2003 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Fri Jan 17 00:00:00 2003 +0000
Author: Various authors <>
Date:   Mon Dec 10 00:00:00 2012 +0000
Author: Various authors <>
Date:   Sat Oct 27 00:00:00 2012 +0000
Author: Various authors <>
Date:   Fri Oct 26 00:00:00 2012 +0000
Author: DiapDealer <>
Date:   Thu Sep 13 00:00:00 2012 +0000
Author: Various authors <>
Date:   Wed Jul 25 00:00:00 2012 +0000
Author: Various authors <>
Date:   Thu Apr 26 00:00:00 2012 +0000
Author: Various authors <>
Date:   Fri Mar 23 00:00:00 2012 +0000
Author: Various authors <>
Date:   Thu Mar 8 00:00:00 2012 +0000
Author: Various authors <>
Date:   Sun Feb 12 00:00:00 2012 +0000
Author: Various authors <>
Date:   Fri Jan 27 00:00:00 2012 +0000
Author: nickredding <>
Date:   Fri Jan 27 00:00:00 2012 +0000
Author: Various authors <>
Date:   Wed Jan 18 00:00:00 2012 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Fri Dec 23 00:00:00 2011 +0000
Author: Various authors <>
Date:   Thu Oct 27 00:00:00 2011 +0000
Author: pdurrant <>
Date:   Thu Sep 1 00:00:00 2011 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Fri Aug 5 00:00:00 2011 +0000
Author: siebert <>
Date:   Sat Jul 23 00:00:00 2011 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Tue Jul 19 00:00:00 2011 +0000
Author: siebert <>
Date:   Mon Jul 18 00:00:00 2011 +0000
Author: Various authors <>
Date:   Mon Jun 27 00:00:00 2011 +0000
Author: pdurrant <>
Date:   Wed May 18 00:00:00 2011 +0000
Author: pdurrant <>
Date:   Sun Aug 29 00:00:00 2010 +0000
Author: pdurrant <>
Date:   Mon Apr 12 00:00:00 2010 +0000
Author: pdurrant <>
Date:   Sat Mar 13 00:00:00 2010 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Thu Feb 18 00:00:00 2010 +0000
Author: pdurrant <>
Date:   Thu Feb 18 00:00:00 2010 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Thu Feb 18 00:00:00 2010 +0000
Author: pdurrant <>
Date:   Wed Feb 17 00:00:00 2010 +0000
Author: pdurrant <>
Date:   Thu Feb 11 00:00:00 2010 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Mon Feb 8 00:00:00 2010 +0000
Author: Various authors <>
Date:   Sun Feb 7 00:00:00 2010 +0000
Author: pdurrant <>
Date:   Fri Feb 5 00:00:00 2010 +0000
Author: Kevin Hendricks <kevin.b.hendricks@noreply-github.com>
Date:   Thu Nov 12 00:00:00 2009 +0000

I guess, author of the very first commit should be fixed manually.

I think, Git allows only for one author in commit field, so historical information about authors shouldn't be removed from commit messages.

Last edited by eureka; 10-15-2014 at 02:47 PM. Reason: put current original commit ids into authors.py example
eureka is offline   Reply With Quote
Old 10-15-2014, 03:08 PM   #1054
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Quote:
Originally Posted by eureka View Post
I think, Git allows only for one author in commit field, so historical information about authors shouldn't be removed from commit messages.
Code:
--msg-filter 'sed -e "/Authors[^,]*$/d"'
to remove the authors info if there is only one author listed.
eschwartz is offline   Reply With Quote
Old 10-15-2014, 03:27 PM   #1055
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,788
Karma: 6000000
Join Date: Nov 2009
Device: many
Hi eschwartz,

Thank you!

That is worth trying on my local tree but since we have no real e-mail addresses anyway, I will try creating a combined "author" field when more than one author is listed. I saw where some companies are doing this for their "pairs" approach to programming. I also saw there is a long-running bug report in git to allow multiple authors for a single commit.

So changing

Author: Various authors <>

To something along the lines of:

Author: "DiapDealer, tkeo"<>

or

Author: "DiapDealer & tkeo"<>


If that works, then I will definitely give this a try.

Thanks,

KevinH
KevinH is online now   Reply With Quote
Advert
Old 10-15-2014, 03:51 PM   #1056
eureka
but forgot what it's like
eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.
 
Posts: 741
Karma: 2345678
Join Date: Dec 2011
Location: north (by northwest)
Device: Kindle Touch
Quote:
Originally Posted by KevinH View Post
So changing

Author: Various authors <>

To something along the lines of:

Author: "DiapDealer, tkeo"<>
Here is a changed script for printing authors separated by comma:
Spoiler:
Code:
#!/usr/bin/env python3

from collections import OrderedDict
import fileinput
from itertools import chain, repeat
import re

DEFAULT_AUTHOR_NAME = "Kevin Hendricks"
AUTHOR_REAL_NAME = {
    "KevinH": DEFAULT_AUTHOR_NAME,
    "kovidgoyal": "Kovid Goyal",
}

AUTHORS_PREFIX = "Authors: "
# Author names are delimited with comma and spaces after it.
AUTHOR_RE = re.compile('(?:,\s*)?(?P<author>[^,]+)')

def get_authors(commit_obj_line):
    if commit_obj_line.startswith(AUTHORS_PREFIX):
        _, authors = commit_obj_line.split(AUTHORS_PREFIX, maxsplit=1)
        return AUTHOR_RE.findall(authors.strip())

# Remove duplicates with preserving order.
def uniq(iterable):
    uniq_container = OrderedDict(zip(iterable, repeat(None)))
    return uniq_container.keys()

# `chain.from_iterable` flattens list of lists.
authors = uniq(chain.from_iterable(
    # Transform stdin line into list of authors or None (if authors were not
    # found in that line) and then filter out None's.
    filter(None, map(get_authors, fileinput.input()))
)) or [DEFAULT_AUTHOR_NAME]

print(", ".join(AUTHOR_REAL_NAME.get(name, name) for name in authors))

It recognizes a bit different input line, as provided by:
Code:
--env-filter 'export GIT_AUTHOR_NAME="$(git cat-file -p ${GIT_COMMIT} | python3 /full/path/to/authors.py)"; if [ "x${GIT_AUTHOR_NAME}" != "xKevin Hendricks" ]; then export GIT_AUTHOR_EMAIL=""; fi'
You can look at script's output for all commits with
Code:
for commit_id in `git log --format='format:%H'`; do git cat-file -p $commit_id | python3 authors.py; done
UPD: still, first commit author should be manually changed to "Adam Selene" after applying git filter-branch with this script.

UPD2: as eschwartz demonstrated, --author option of git commit doesn't accept empty email without commit message also being set with command-line option. Maybe some other Git-related commands/tools have similar small idiosyncrasies?... It might be better/safer to set invalid email instead of empty email.

Last edited by eureka; 10-15-2014 at 06:55 PM. Reason: mild script change
eureka is offline   Reply With Quote
Old 10-15-2014, 09:28 PM   #1057
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,788
Karma: 6000000
Join Date: Nov 2009
Device: many
github now with author information

Hi All,

A very special thanks to both eschwartz and eureka for their invaluable help figuring out how to edit the commit metadata and for developing authors.py.

I have now used these tools on my own tree. I decided to keep the Authors information in the commit messages since some commits are actually multiple releases and this way people will know who committed what.

I still violate the 50 char rule (argh!) and the initial capitalization rule but since these are historic commits imported from outside of GitHub, I am hoping no one will mind too much.

I will try to use both the 50 char limit and first word capitalized rules for all new commits to the tree.

Hope everyone is now happy with the result.

https://github.com/kevinhendricks/KindleUnpack

Thanks,

KevinH
KevinH is online now   Reply With Quote
Old 10-15-2014, 10:57 PM   #1058
eureka
but forgot what it's like
eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.
 
Posts: 741
Karma: 2345678
Join Date: Dec 2011
Location: north (by northwest)
Device: Kindle Touch
Out of curiosity I've tried to run flake8 on KindleUnpack codebase:
Spoiler:
Code:
$ flake8 -qq -statistics KindleUnpack
1st column: number of similar PEP8 errors (EXXX)/PEP8 warnings (WXXX)/failed pyflakes source checks (FXXX)
2nd column: error code
3rd column: error description

Description of FXXX could contain variable/module/something name in single quotes '...', but it's only a name from the first failed check with this code (other similarly failed checks could be related to other name(s) which is (are) just "masked").
Code:
1       E101 indentation contains mixed spaces and tabs
2       E111 indentation is not a multiple of four
1       E122 continuation line missing indentation or outdented
1       E124 closing bracket does not match visual indentation
24      E126 continuation line over-indented for hanging indent
5       E127 continuation line over-indented for visual indent
12      E128 continuation line under-indented for visual indent
12      E131 continuation line unaligned for hanging indent
2       E202 whitespace before ')'
953     E203 whitespace before ':'
1       E211 whitespace before '('
8       E221 multiple spaces before operator
12      E222 multiple spaces after operator
63      E225 missing whitespace around operator
16      E227 missing whitespace around bitwise or shift operator
7       E228 missing whitespace around modulo operator
468     E231 missing whitespace after ','
10      E251 unexpected spaces around keyword / parameter equals
103     E261 at least two spaces before inline comment
4       E262 inline comment should start with '# '
46      E265 block comment should start with '# '
6       E271 multiple spaces after keyword
3       E272 multiple spaces before keyword
4       E301 expected 1 blank line, found 0
56      E302 expected 2 blank lines, found 1
69      E303 too many blank lines (3)
25      E401 multiple imports on one line
614     E501 line too long (84 > 79 characters)
4       E502 the backslash is redundant between brackets
21      E701 multiple statements on one line (colon)
2       E703 statement ends with a semicolon
1       E711 comparison to None should be 'if cond is not None:'
77      F401 'cdll' imported but unused
3       F811 redefinition of unused 'uuid' from line 154
1       F821 undefined name 'value'
11      F841 local variable 'boundary' is assigned to but never used
1       W191 indentation contains tabs
35      W291 trailing whitespace
1       W292 no newline at end of file
19      W293 blank line contains whitespace
8       W391 blank line at end of file

I did this not for blaming purposes. I understand that KindleUnpack is working code useful for many people in current state, so it's a practically good code. But this list possibly contains some low-hanging fruits.
eureka is offline   Reply With Quote
Old 10-16-2014, 01:04 AM   #1059
AcidWeb
KCC Co-Author
AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.
 
AcidWeb's Avatar
 
Posts: 845
Karma: 765434
Join Date: Mar 2013
Location: Poland
Device: Kindle Oasis 2
eureka beat me to it. I also was planning to bring up this topic.

Today I will make Pull Request to Python3 branch with cleaned/PEP8 compliant code.
At the same time KevinH will have chance to look how GitHub support code contributions.

Edit:
I presume that Python3 branch is not yet ready? Because I see multiple places where sytax not supported by Python 3.4 is used.

Edit 2:
2188 Python 2.x PEP8 style violations. *Cough*. That pull request might not be ready today :-P

Last edited by AcidWeb; 10-16-2014 at 03:12 AM.
AcidWeb is offline   Reply With Quote
Old 10-16-2014, 07:02 AM   #1060
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,788
Karma: 6000000
Join Date: Nov 2009
Device: many
Hi,
The code to allow KindleUnpack to work on *BOTH* Python 2.7 and Python 3.4 is incomplete, but runnable from the command line. It is in the python2and3 branch.

And yes 2to3 will scream at it but that is expected and does actually run on both.

I will run reindent.py on the master to clean up most of the spacing issues. It was run but only the python2and3 branch.

That was done so all serious whitespace issues should be taken care of.

As for flake8 - it is simply a style enforcer. And McCabe's complexity analysis is for the birds as well. You can tell if code is maintainable by simply reading it.

For example numerous "errors" in mobi_header.py are:

Code:
    id_map_strings = {
        1 : 'Drm Server Id (1)',
        2 : 'Drm Commerce Id (2)',
        3 : 'Drm Ebookbase Book Id(3)',
        100 : 'Creator_(100)',
        101 : 'Publisher_(101)',
        102 : 'Imprint_(102)',
        103 : 'Description_(103)',
        104 : 'ISBN_(104)',
        105 : 'Subject_(105)',
        106 : 'Published_(106)',
simply the space before or after the ":' in the dictionary initializer.

Sorry but that's not gonna change!

The change itself would be meaningless (no impact on pyc execution) and the spacing helps to make things look cleaner.

I *will* look at the unused variables and more serious cdll issues and other issues that flake8 picks up but style only changes in whitespace or "line too long" changes will be ignored.

So please don't bother to offer pull requests for line length issues or whitespace issues that are not related to indentation issues. Only changes that actually or potentially impact functionality will considered.

That should bring that 2188 down to a more reasonable level!

Thanks,

KevinH

Quote:
Originally Posted by AcidWeb View Post
eureka beat me to it. I also was planning to bring up this topic.

Today I will make Pull Request to Python3 branch with cleaned/PEP8 compliant code.
At the same time KevinH will have chance to look how GitHub support code contributions.

Edit:
I presume that Python3 branch is not yet ready? Because I see multiple places where sytax not supported by Python 3.4 is used.

Edit 2:
2188 Python 2.x PEP8 style violations. *Cough*. That pull request might not be ready today :-P

Last edited by KevinH; 10-16-2014 at 08:08 AM.
KevinH is online now   Reply With Quote
Old 10-16-2014, 10:31 AM   #1061
eureka
but forgot what it's like
eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.
 
Posts: 741
Karma: 2345678
Join Date: Dec 2011
Location: north (by northwest)
Device: Kindle Touch
Quote:
Originally Posted by KevinH View Post
So please don't bother to offer pull requests for line length issues or whitespace issues that are not related to indentation issues. Only changes that actually or potentially impact functionality will considered.

That should bring that 2188 down to a more reasonable level!
I do agree with ignoring of some errors which aren't errors but just artifacts of custom developed style.

There is also another point wrt flake8. Given openness for contribution, is it a reasonable goal to have automated style check for keeping (enforcing) style consistency? If so, flake8 can help with it.

flake8 is just a wrapper for pep8, pyflakes and McCabe tools (with McCabe deactivated by default). flake8 (pep8) tool policy could be changed to the limit (flake8 configuration) with per-project settings file (which could be commited to repository). For example, maximum line length (checked by pep8 tool) could be increased to 119 characters (as in Django coding style, to align with width of GitHub code review) or any other arbitrary but fixed value. pep8 errors reporting could be disabled either globally (with settings file, by whitelisting or blacklisting several errors) or locally (with special comment after line where error reporting should be disabled, but only for some selected errors). flake8 will also not check files with # flake8: noqa comment.

Providing different flake8 settings for checking Python2/Python3 code could be automated with tox. tox is useful anyway for making things run against different Python versions in testing purposes.

I'm not trying to set any priority for using flake8. It was just a small tour into its configurability.
eureka is offline   Reply With Quote
Old 10-16-2014, 11:15 AM   #1062
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,373
Karma: 27230406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
@KevinH: Just FYI, here is my configuration for pep8 that eliminates all the coding style warnings that I find silly/counterproductive,
https://github.com/kovidgoyal/calibr...ster/setup.cfg
kovidgoyal is offline   Reply With Quote
Old 10-16-2014, 11:41 AM   #1063
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,788
Karma: 6000000
Join Date: Nov 2009
Device: many
Hi Kovid,

Thanks! By my rough estimate based on the stats run posted earlier, using your config will remove over 2100 of the "errors" from the 2188 listed. Running reindent.py should also account for the some of the others. That will leave me with a manageable 50 or so to take a closer look at.

That is doable. I will commit your setup.cfg to KindleUnpack just to help us focus in on what might be real problems. Thanks also to eureka for explaining that many of these can be turned off.

Take care,

KevinH



Quote:
Originally Posted by kovidgoyal View Post
@KevinH: Just FYI, here is my configuration for pep8 that eliminates all the coding style warnings that I find silly/counterproductive,
https://github.com/kovidgoyal/calibr...ster/setup.cfg
KevinH is online now   Reply With Quote
Old 10-16-2014, 11:46 AM   #1064
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,373
Karma: 27230406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You might find the autopep8 tool useful to easily take care of the rest. Here is a script that I use to integrate it with vim. It is used to automatically fix pep8 warnings in the current file being edited. It reads setup.cfg and tells autopep8 to ignore those classes of warnings.

Code:
#!/usr/bin/env python2
# vim:fileencoding=utf-8
from __future__ import (unicode_literals, division, absolute_import,
                        print_function)

__license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal'

import sys
import os
import subprocess
from ConfigParser import SafeConfigParser

arg = sys.argv[-1]

args = []
# Look for setup.cfg

parent = arg
while parent and os.path.dirname(parent) != parent:
    parent = os.path.dirname(parent)
    cfg = os.path.join(parent, 'setup.cfg')
    if os.path.exists(cfg):
        c = SafeConfigParser()
        c.read(cfg)
        if c.has_section('flake8'):
            if c.has_option('flake8', 'select'):
                args.append('--select=' + c.get('flake8', 'select'))
            if c.has_option('flake8', 'ignore'):
                args.append('--ignore=' + c.get('flake8', 'ignore'))
            if c.has_option('flake8', 'max-line-length'):
                args.append('--max-line-length=' +
                            c.get('flake8', 'max-line-length'))
        break

cmd = ['autopep8'] + args
if '--as-filter' in sys.argv:
    raw = sys.stdin.read()
    p = subprocess.Popen(
        cmd + ['-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    stdout = p.communicate(raw)[0]
    rc = p.wait()
    if rc != 0:
        stdout = raw
    sys.stdout.write(stdout)
    raise SystemExit(rc)
cmd += [arg]
print (' '.join(cmd))
raise SystemExit(subprocess.Popen(cmd).wait())

Last edited by kovidgoyal; 10-16-2014 at 11:49 AM.
kovidgoyal is offline   Reply With Quote
Old 10-16-2014, 12:54 PM   #1065
AcidWeb
KCC Co-Author
AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.AcidWeb ought to be getting tired of karma fortunes by now.
 
AcidWeb's Avatar
 
Posts: 845
Karma: 765434
Join Date: Mar 2013
Location: Poland
Device: Kindle Oasis 2
Well... I consider many coding standards used here as messy but this is not my project so I will just shut up and and focus on making this code work on both Python versions.

Edit:
Not bad. CLI version look good. I presume that not converted prints was caused by fact that you not touched GUI part yet. I hate Tk so no help from me there. Sorry.
One small trap: unescape function used in mobi_opf.py will be removed in Python 3.5.

Last edited by AcidWeb; 10-16-2014 at 01:44 PM.
AcidWeb is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can i rotate text and insert images in Mobi and EPUB? JanGLi Kindle Formats 5 02-02-2013 04:16 PM
PDF to Mobi with text and images pocketsprocket Kindle Formats 7 05-21-2012 07:06 AM
Mobi files - images DWC Introduce Yourself 5 07-06-2011 01:43 AM
pdf to mobi... creating images rather than text Dumhed Calibre 5 11-06-2010 12:08 PM
Transfer of images on text files anirudh215 PDF 2 06-22-2009 09:28 AM


All times are GMT -4. The time now is 02:48 PM.


MobileRead.com is a privately owned, operated and funded community.