Package: challenges
Library to assist programming, testing and execution of solutions for coding challenges like those on stepik.org or
rosalind.info.Find the full documentation atReadthedocs.State:betaLicense:MITAuthor:Elmar HinzRepository:https://github.com/elmar-hinz/Python.ChallengesDocumentation:http://challenges.readthedocs.ioInstallation:https://pypi.org/project/challenges/Hello worldfromchallengesimportChallengeclassAddChallenge(Challenge):sample='''
        5, 6
    '''expect='''
        11
    '''defbuild(self):self.model=self.line_to_integers(0)defcalc(self):self.result=self.model[0]+self.model[1]defformat(self):self.output=str(self.result)The class to write lets you focus on the core algorithms of the challenge while keeping stuff like opening, reading and
writing of files out of the way. You inherit several methods to set up the model or to format your result for writing.While the class attributesamplejust holds a minimal example of the input, the actual input is later injected by
theChallenge Runnervia the command line. In Bioinformatics this is often a large file of DNA.HintSee a more verbose example of HelloWorld and other examples.HelloWorldChallengeHelloWorldTestHelloFastaChallengeHelloFastaTestHelloGraphChallengeHelloGraphTestFeatureslisting available challengesscaffolding a new challenge directory with a challenge class and a unit test classexecuting thesamplefrom the sample class attributereading input files from the command lineoutput formatted result on the command linewritingsample.txtand matchingresult.txtinto the challenges directoryrunning the unit test case of a challengereading lines with integersreading lines with floatsreading lines with wordsreading fasta inputDirectory layoutLets call the base directory of your challenges projectmyChallenges/. Name it however you like.myChallenges/Challenge1/__init__.pyChallenge1/challenge.pyChallenge1/test.pyChallenge2/__init__.pyChallenge2/challenge.pyChallenge2/test.py...morechallenges...The namesChallenge1andChallenge2are just placeholders for the names you choose during scaffolding.HintThe files__init__.pyare empty. They help unittest tools likenosetestto locate the files.Challenge runnerImportantAlways move into the base directory to use theChallenge Runner.List the available challengesprompt>challenge--list*Challenge1*Challenge2*...Scaffolding a new challengeprompt>challenge--scaffoldChallenge3You now find the files:myChallenges/Challenge3/__init__.pyChallenge3/challenge.pyChallenge3/test.pyCheck it’s working by running the unit test case.prompt>challenge--unittestChallenge3.sss.----------------------------------------------------------------------Ran5testsin0.006sOK(skipped=3)Run <sample> from the class fileThis is the small sample directly coded into the challenge class.prompt>challenge--klassChallenge1[theresultoutputgoeshere]HintYou will automatically find the latest output in two files, independent from the input method you choose.myChallenges/Challenge1/latest.txtmyChallenges/latest.txtThese files are just for convenience and are overwritten by the next run.Read sample from an input fileprompt>challengeChallenge1--file~/Downloads/data.txt[theresultoutputgoeshere]Storing data and resultsDid you pass the challenge? Was the online grader content with the upload oflatest.txt? Then you should store data
and result.prompt>challengeChallenge1--file~/Downloads/data.txt--writeYou will find the files:myChallenges/Challenge1/sample.txtmyChallenges/Challenge1/result.txtThis files are stored until the next run with the–writeflag.HelpTo quickly see all available options.challenge--helpTipFor every double dashed option there is a single dashed one letter shortcut. Help lists them all.prompt> challenge Challenge1 –scaffold
prompt> challenge Challenge1 -sTipYou can palce the dashed options behind the name of the challenge. This makes it easy to exchange them.
Practical usage may look like this.prompt>challengeExampleProblem-sprompt>challengeExampleProblem-uprompt>challengeExampleProblem-kprompt>challengeExampleProblem-f~/Downloads/data.txtprompt>challengeExampleProblem-f~/Downloads/data.txt-wNaming conventionsThe naming conventions follow the standards as defined byPEP 8Style Guide for Python CodeThere are two deliberate exceptions:Challenge module names areCamelCase:In contradiction to the style guide directories of the challenges are not all lowercase. Especially the
first character must be uppercase. This is used to find and list the challenge directories between other modules.
If the name of your challenge isExampleProblemthen this are the required names:directory:ExampleProblem/challenge file:ExampleProblem/challenge.pyunittest file:ExampleProblem/test.pyfull qualified challenge class:ExampleProblem.challenge.ExampleProblemChallengefull qualified test class:ExampleProblem.test.ExampleProblemTestThis is automatically wired up during scaffolding.Abbreviations or codes like onRosalindmay be all uppercase  or camelcase,RSUBorRsub.Inherited class attributes and methods don’t have a leading underscore:The inherited functions and methods of the challenge are not a public API and the style guides recommends leading
underscores. As inheritance is a core concept of the challenge class, this would lead to a hell of leading
underscores. For this reason we don’t follow the style guide in this recommendation.TipOne useful advantage of naming the directory just like your challenge is, that you can use the path expansion
mechanism of the shell. Write the first characters of the directory name and hit <TAB>. Now you can use the
directory name as name of the challenge. A trailing slash is discarded. The following two inputs are equivalent.prompt>challenge-kExampleProblemprompt>challenge-kExampleProblem/InstallationImportantThis software requires Python 3.Clone from GithubYou can clone (or download) the Challenges project directly from Github. In this case the scripts and paths are not
configured globally. Either you configure it globally or you place your challenges immediately into the projects folder
so that the paths are detected relatively.Put your challenges immediately into the projects folderThis is the most simple setup to get started. After downloading change into the download folder an try to run theHelloWorldunit test. In this case the command is in thebindirectory, you call it asbin/challenge.prompt>bin/challenge--unittestHelloWorld...----------------------------------------------------------------------Ran3testsin0.001sOKNow you are ready to create your challenge side-by-side with theHelloWorldchallenge.prompt>bin/challenge--scaffoldMyChallengeUse <pip> to install <challenges>If you have a fully configured python 3 environment up and running you can install <challenges> with pip3.prompt>pip3searchchallengesprompt>pip3installchallengesThe library will be included into the python class path. The runner will be globally available aschallenge,
alternatively asstepikorrosalind.prompt>challenge--versionchallenge0.8.0prompt>stepik--versionstepik0.8.0prompt>rosalind--versionrosalind0.8.0