Package: reprit
repritIn what followspythonis an alias forpython3.7orpypy3.7or any later version (python3.8,pypy3.8and so on).InstallationInstall the latestpip&setuptoolspackages versionspython-mpipinstall--upgradepipsetuptoolsUserDownload and install the latest stable version fromPyPIrepositorypython-mpipinstall--upgraderepritDeveloperDownload the latest version fromGitHubrepositorygitclonehttps://github.com/lycantropos/reprit.gitcdrepritInstallpythonsetup.pyinstallUsageLet's suppose we are defining a class and we want to have__repr__, that:Includes parameters involved in instance creation.
For simple cases it should be possible
to copy string & paste in some place (e.g. REPL session)
and have similar object definition with as less work as possible.
This helps a lot during debugging, logging,
in failed test cases with randomly generated data, etc.In case of signature change
method should handle this automatically for simple cases
like renaming/removing/changing order of parameters.This can be done like>>>fromreprit.baseimportgenerate_repr>>>classDummyContainer:...def__init__(self,positional,*variadic_positional,keyword_only,**variadic_keyword):...self.positional=positional...self.variadic_positional=variadic_positional...self.keyword_only=keyword_only...self.variadic_keyword=variadic_keyword......__repr__=generate_repr(__init__)after that>>>DummyContainer(range(10),2,3,keyword_only='some',a={'sample':42})DummyContainer(range(0,10),2,3,keyword_only='some',a={'sample':42})or for a class with avoidance of built-in names clash
& private'ish attributes
& both>>>fromrepritimportseekers>>>fromreprit.baseimportgenerate_repr>>>classState:...def__init__(self,id_,name,zip_):...self.id=id_...self._name=name...self._zip=zip_......__repr__=generate_repr(__init__,...field_seeker=seekers.complex_)after that>>>State(1,'Alabama',36016)State(1,'Alabama',36016)We can also tell to skip unspecified optional parameters>>>fromreprit.baseimportgenerate_repr>>>classEmployee:...def__init__(self,name,email=None,manager=None):...self.name=name...self.email=email...self.manager=manager......__repr__=generate_repr(__init__,...skip_defaults=True)After that>>>Employee('John Doe')Employee('John Doe')>>>Employee('John Doe',...manager=Employee('Jane Doe'))Employee('John Doe',manager=Employee('Jane Doe'))>>>Employee('John Doe','johndoe@company.com',Employee('Jane Doe'))Employee('John Doe','johndoe@company.com',Employee('Jane Doe'))Note: this method doesn't automatically handle changes during runtime
(e.g. if someone deletes instance field
or replaces__init__/__new__method implementation),
in this case user should update__repr__method as well.DevelopmentBumping versionPreparationInstallbump2version.Pre-releaseChoose which version number category to bump followingsemver
specification.Test bumping versionbump2version--dry-run--verbose$CATEGORYwhere$CATEGORYis the target version number category name, possible
values arepatch/minor/major.Bump versionbump2version--verbose$CATEGORYThis will set version tomajor.minor.patch-alpha.ReleaseTest bumping versionbump2version--dry-run--verbosereleaseBump versionbump2version--verbosereleaseThis will set version tomajor.minor.patch.Running testsInstall dependenciespython-mpipinstall-rrequirements-tests.txtPlainpytestInsideDockercontainer:withCPythondocker-compose--filedocker-compose.cpython.ymlupwithPyPydocker-compose--filedocker-compose.pypy.ymlupBashscript:withCPython./run-tests.shor./run-tests.shcpythonwithPyPy./run-tests.shpypyPowerShellscript:withCPython.\run-tests.ps1or.\run-tests.ps1cpythonwithPyPy.\run-tests.ps1pypy