From 0719ff429f1136cbc40fd358df49310525f53ac3 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sun, 26 Feb 2012 12:44:06 +0000 Subject: [PATCH] Improve documentation generation --- github/GithubObject.UnitTest.py | 7 +++---- github/GithubObject.py | 12 +++++------- github/GithubObjects.py | 4 ++-- github/ObjectCapacities/Basic.py | 13 ++++++++++--- github/ObjectCapacities/List.py | 4 ++-- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/github/GithubObject.UnitTest.py b/github/GithubObject.UnitTest.py index 64c9f419..79ea216b 100644 --- a/github/GithubObject.UnitTest.py +++ b/github/GithubObject.UnitTest.py @@ -430,9 +430,6 @@ class GithubObjectWithMultiCapacityExternalListOfSimpleTypes( TestCaseWithGithub self.expectStatusDelete( "/test/a3s", [ "a", "b", "c" ] ).andReturn( 204 ) a3s = self.o.remove_from_a3s( "a", "b", "c" ) -def myCallable( obj, mock, arg ): - return mock.call( arg ) - class GithubObjectWithExternalSimpleAttribute( TestCaseWithGithubTestObject ): GithubTestObject = GithubObject( "GithubTestObject", @@ -445,12 +442,14 @@ class GithubObjectWithExternalSimpleAttribute( TestCaseWithGithubTestObject ): self.expectDataGet( "/test/a3" ).andReturn( 72 ) self.assertEqual( self.o.get_a3(), 72 ) +def myCallable( obj, mock, arg ): + return mock.call( arg ) class GithubObjectWithMethodFromCallable( TestCaseWithGithubTestObject ): GithubTestObject = GithubObject( "GithubTestObject", BaseUrl( lambda obj: "/test" ), InternalSimpleAttributes( "a1", "a2" ), - MethodFromCallable( "myMethod", myCallable ) + MethodFromCallable( "myMethod", [ "mock", "arg" ], [], myCallable ) ) def testCallMethod( self ): diff --git a/github/GithubObject.py b/github/GithubObject.py index d2057f8f..18dc5a3c 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -1,6 +1,6 @@ import itertools -from ObjectCapacities.ArgumentsChecker import ArgumentsChecker +from ObjectCapacities.ArgumentsChecker import * from ObjectCapacities.Basic import * from ObjectCapacities.List import * from ObjectCapacities.TypePolicies import * @@ -28,19 +28,17 @@ def Identity( identity ): class Editable( MethodFromCallable ): def __init__( self, mandatoryParameters, optionalParameters ): - MethodFromCallable.__init__( self, "edit", self.__execute ) - self.__argumentsChecker = ArgumentsChecker( mandatoryParameters, optionalParameters ) + MethodFromCallable.__init__( self, "edit", mandatoryParameters, optionalParameters, self.__execute ) - def __execute( self, obj, *args, **kwds ): - data = self.__argumentsChecker.check( args, kwds ) + def __execute( self, obj, **data ): attributes = obj._github._dataRequest( "PATCH", obj._baseUrl, None, data ) obj._updateAttributes( attributes ) class Deletable( MethodFromCallable ): def __init__( self ): - MethodFromCallable.__init__( self, "delete", self.__execute ) + MethodFromCallable.__init__( self, "delete", [], [], self.__execute ) - def __execute( self, obj, *args, **kwds ): + def __execute( self, obj ): obj._github._statusRequest( "DELETE", obj._baseUrl, None, None ) def GithubObject( className, *attributePolicies ): diff --git a/github/GithubObjects.py b/github/GithubObjects.py index 6d946948..1501860d 100644 --- a/github/GithubObjects.py +++ b/github/GithubObjects.py @@ -423,11 +423,11 @@ NamedUser._addAttributePolicy( def __createForkForUser( user, repo ): assert isinstance( repo, Repository ) return Repository( user._github, user._github._dataRequest( "POST", repo._baseUrl + "/forks", None, None ), lazy = True ) -AuthenticatedUser._addAttributePolicy( MethodFromCallable( "create_fork", __createForkForUser ) ) +AuthenticatedUser._addAttributePolicy( MethodFromCallable( "create_fork", [ "repo" ], [], __createForkForUser ) ) def __createForkForOrg( org, repo ): assert isinstance( repo, Repository ) return Repository( org._github, org._github._dataRequest( "POST", repo._baseUrl + "/forks", { "org": org.login }, None ), lazy = True ) -Organization._addAttributePolicy( MethodFromCallable( "create_fork", __createForkForOrg ) ) +Organization._addAttributePolicy( MethodFromCallable( "create_fork", [ "repo" ], [], __createForkForOrg ) ) Team = GithubObject( "Team", diff --git a/github/ObjectCapacities/Basic.py b/github/ObjectCapacities/Basic.py index e65d05ea..569deb61 100644 --- a/github/ObjectCapacities/Basic.py +++ b/github/ObjectCapacities/Basic.py @@ -1,3 +1,5 @@ +from ArgumentsChecker import * + class AttributeFromCallable: class AttributeDefinition: def __init__( self, name, callable ): @@ -26,15 +28,20 @@ class AttributeFromCallable: ### @todo include the ArgumentsChecker class MethodFromCallable: - def __init__( self, name, callable ): + def __init__( self, name, mandatoryParameters, optionalParameters, callable ): + self.__argumentsChecker = ArgumentsChecker( mandatoryParameters, optionalParameters ) self.__name = name self.__callable = callable def apply( self, cls ): - cls._addMethod( self.__name, self.__callable ) + cls._addMethod( self.__name, self.__execute ) + + def __execute( self, obj, *args, **kwds ): + data = self.__argumentsChecker.check( args, kwds ) + return self.__callable( obj, **data ) def autoDocument( self ): - return "* `" + self.__name + "( ... )`\n" + return "* `" + self.__name + "(" + self.__argumentsChecker.documentParameters() + ")`\n" class InternalAttribute: class AttributeDefinition: diff --git a/github/ObjectCapacities/List.py b/github/ObjectCapacities/List.py index 1f05c01c..f96821d4 100644 --- a/github/ObjectCapacities/List.py +++ b/github/ObjectCapacities/List.py @@ -110,7 +110,7 @@ class ElementGetable( ListCapacity ): return attributes def autoDocument( self ): - return "* `get_" + self.singularName + "( ... )`: `" + self.typePolicy.documentTypeName() + "`\n" + return "* `get_" + self.singularName + "(" + self.__argumentsChecker.documentParameters() + ")`: `" + self.typePolicy.documentTypeName() + "`\n" class SeveralElementsAddable( ListCapacity ): def apply( self, cls ): @@ -172,7 +172,7 @@ class ListGetable( ListCapacity ): ] def autoDocument( self ): - return "* `get_" + self.safeAttributeName + "()`: list of `" + self.typePolicy.documentTypeName() + "`\n" + return "* `get_" + self.safeAttributeName + "(" + self.__argumentsChecker.documentParameters() + ")`: list of `" + self.typePolicy.documentTypeName() + "`\n" def __modifyAttributes( self, obj, attributes ): for attributeName, attributeModifier in self.__attributeModifiers.iteritems():