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

Port twisted.names.authority.BindAuthority to Py3 #579

Merged
merged 8 commits into from
Jan 21, 2017
Merged

Port twisted.names.authority.BindAuthority to Py3 #579

merged 8 commits into from
Jan 21, 2017

Conversation

hynek
Copy link
Member

@hynek hynek commented Oct 31, 2016

Underway I had to fix a few bugs/annoyances. Most notably:

  • Remove a (debug!?) print statement when adding records.
  • Reflect explicit $ORIGIN in instance.
  • Add discouraging docstrings to public helper methods that should be private.
    These should be deprecated ASAP.
  • Remove a bunch of commented out debug print statements.

I wrote a bunch of tests (the class was completely untested so far), but want to see Travis/coverage before writing more.

@codecov-io
Copy link

codecov-io commented Oct 31, 2016

Current coverage is 90.74% (diff: 94.89%)

Merging #579 into trunk will increase coverage by 0.05%

@@              trunk       #579   diff @@
==========================================
  Files           815        815          
  Lines        145980     146021    +41   
  Methods           0          0          
  Messages          0          0          
  Branches      12875      12882     +7   
==========================================
+ Hits         132389     132505   +116   
+ Misses        11322      11245    -77   
- Partials       2269       2271     +2   

Powered by Codecov. Last update c00f00e...d05819d

@glyph
Copy link
Member

glyph commented Nov 19, 2016

There are a couple of twistedchecker failures - can you fix those? Thanks!

Underway I had to fix a few bugs/annoyances.  Most notably:

- Fix a major bug in addRecord that didn't remove the final dot if an
  owner/origin is added.
- Remove a (debug!?) print statement when adding records.
- Reflect explicit $ORIGIN in instance.
- Add discouraging docstrings to public helper methods that should be
  private.  These should be deprecated ASAP.
- Remove a bunch of commented out debug print statements.
@hynek
Copy link
Member Author

hynek commented Nov 19, 2016

Look at all those green build jobs!

@adiroiban
Copy link
Member

Thanks for the patch. The release notes only talks about porting to python3.

Since in this branch you have also fixed a few bugs, shouldn't we advertise this in the release notes?

def getSerial(filename = '/tmp/twisted-names.serial'):
"""Return a monotonically increasing (across program runs) integer.

def getSerial(filename='/tmp/twisted-names.serial'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is targeting python3, is filename a native string, bytes or unicode?

with the move to python3 I think that it would help to be explicit if something is text or data.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ISTM that for paths a filename is OK to be a native string. Are there any precedences?

I’d also like to point out, that I just touched this function to make twistedchecker shut up. Starting to fix it up seems out of scope? NB I’m not asking because I’m lazy, I’m asking because I’m not sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing it is definitely out of scope. And we should probably figure out how to make twistedchecker not complain about stuff that is merely adjacent to your diff rather than part of it...

# self._cache[(name, cls, type)] = r
# return r
serial = serial + ('%02d' % (ID,))
serialFile.write('%s %d' % (serial, id))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use FIlePath here? I think that it should take care of handling the path encoding issues.

@@ -161,25 +156,32 @@ def _lookup(self, name, cls, type, timeout = None):
else:
ttl = default_ttl

if record.TYPE == dns.NS and name.lower() != self.soa[0].lower():
if record.TYPE == dns.NS and \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you should use parenthesis to break long lines .... but twistechecker should have complain about this

@hynek
Copy link
Member Author

hynek commented Nov 19, 2016

I thought about the release notes thing but wasn’t sure how to phrase it (especially because the bugs are rather subtle).

Copy link
Member

@glyph glyph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this, @hynek . This is generally a great branch and I like most of the cleanups. However, if you could address the few nitpicks it would be great.

If you can push these changes to a branch on Twisted itself, then the all the buildbots should run and I think the coverage issues will be addressed. If not, please pacify codecov by adding tests for any uncovered lines.

@@ -34,28 +44,14 @@ def getSerial(filename = '/tmp/twisted-names.serial'):
os.umask(o)

with open(filename, 'r') as serialFile:
lastSerial, ID = serialFile.readline().split()
lastSerial, id = serialFile.readline().split()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id is a builtin, which is why this was previously capitalized :).

Perhaps zoneID?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

twistedchecker complained about ID

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically (naming-standard-wise) it is correct to complain; it should just also be complaining about id. zoneID ought to be OK with it though.

serial = serial + ('%02d' % (ID,))
serialFile.write('%s %d' % (serial, id))

serial = serial + ('%02d' % (id,))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: .format instead of % because it's ~fancier~?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it’s slower? :)

@type filename: L{bytes}
"""
fp = FilePath(filename)
# XXX - not the best way to set an origin. It can be set using $ORIGIN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per policy, XXX and FIXME comments should be links to tickets.

return [
a.find(';') == -1 and a or a[:a.find(';')] for a in [
"""
This is a private API; do not use in application code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this method private and then add a deprecated public alias? Deprecation should be communicated structurally in a way that automated tooling can deal with, not with ad-hoc doc comments.



def collapseContinuations(self, lines):
L = []
"""
This is a private API; do not use in application code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above comment.

TTL = 60 * 60 * 3
ORIGIN = self.origin
"""
This is a private API; do not use in application code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above about private APIs.

if not domain.endswith('.'):
domain = domain + '.' + owner
"""
This is a private API; do not use in application code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK hang on a second. Are these APIs really private? It feels like maybe somebody is using them. Maybe we can just delete the deprecations in this branch and do that separately?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How am I supposed to document them to make twistedchecker shut up?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems like an unrelated question, but... txchecker-travis is passing :).

You already have a docstring here, so if you just delete the line This is a private API; do not use in application code. it should still be fine with it.

Am I misunderstanding the question?


def test_aaaaRecords(self):
"""
AAAA records are loaded correctly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per https://jml.io/pages/test-docstrings.html, "correctly" is a non-word :).


def test_mxRecords(self):
"""
MX records are loaded correctly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def test_invalidRecordClass(self):
"""
Raises NotImplementedError on invalid records.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence should have a subject.

@param rdata: record data
@type rdata: L{list} of L{bytes}

@return: nothing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: there's no return statement in the body of the function, so twistedchecker and pydoctor ought not to complain if you just omit @return entirely. And anywhere twistedchecker lets us omit stuff we probably should :). (If I'm wrong about this please correct me).

@wsanchez
Copy link
Member

Coverage is failing.

At least one case is directly relevant to your changes: https://codecov.io/gh/twisted/twisted/compare/f520d35bfd552f0da91b248171d25789170110ae...1dd9c449504b07652af650382fc46b566fcd8546#7372632F747769737465642F6E616D65732F617574686F726974792E7079-86

Others are not new but triggering due to reformatting of code:
https://codecov.io/gh/twisted/twisted/compare/f520d35bfd552f0da91b248171d25789170110ae...1dd9c449504b07652af650382fc46b566fcd8546#7372632F747769737465642F6E616D65732F617574686F726974792E7079-86

Since recently policy says no overriding of these is allowed, you probably need to un-reformat that code or test it.

@wsanchez
Copy link
Member

Actually I mis-read the "directly relevant" example; you removed an adjacent line, so again, cleanup is causing coverage to complain.

@glyph
Copy link
Member

glyph commented Jan 21, 2017

It looks like @hynek did in fact address all the review feedback, and the coverage issue is just a re-formatted NotImplementedError line. Formally speaking this is something that should be "in a different PR" but given that absolute coverage increased, I'm not going to be a pain in the butt about it :).

Since this has been a while I'm going to update the branch and push it to a twisted branch for full CI, but assuming CI is reasonably happy after that, I'll merge.

@glyph glyph merged commit d34091c into twisted:trunk Jan 21, 2017
@glyph
Copy link
Member

glyph commented Jan 21, 2017

Thanks to https://www.traviscistatus.com/incidents/3pfp91tltsbr I really didn't want to wait the additional 2 hours for another trunk merge, so: merged.

@glyph
Copy link
Member

glyph commented Jan 21, 2017

(Happily the status just passed though, so no exception necessary!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants