Editor

Build a Release Manager

Advanced · Write the code · from How to Package and Publish Your Python Code to PyPI

From the lesson: How to Package and Publish Your Python Code to PyPI

Imagine you've written a fantastic recipe. Right now it only lives in your kitchen notebook. To share it with the world, you'd need to format it nicely, package it into a cookbook, and get it onto bookstore shelves.

Read the lesson

Create a class called ReleaseManager that manages package releases:

  • __init__(self, name, version): Store the package name and version (a string like '1.0.0'). Initialize an empty list called releases.
  • bump(self, part): Bump the version by part ('major', 'minor', or 'patch'). When bumping major, reset minor and patch to 0. When bumping minor, reset patch to 0. Store the new version as self.version.
  • release(self): Append a dictionary {'version': self.version, 'files': [sdist, wheel]} to self.releases, where sdist is 'name-version.tar.gz' and wheel is 'name-version-py3-none-any.whl' (replace hyphens with underscores in the name for filenames). Print Released name version.
  • history(self): Print each release on its own line in the format v{version}: {file1}, {file2}.
  • class ReleaseManager:
    # Build your release manager
    pass

    What Check runs

    Your code runs first, then each of these lines. The output must match exactly.

    RunsExpected output
    rm = ReleaseManager('my-tool', '1.0.0') rm.release() rm.bump('patch') rm.release() rm.history()Released my-tool 1.0.0 Released my-tool 1.0.1 v1.0.0: my_tool-1.0.0.tar.gz, my_tool-1.0.0-py3-none-any.whl v1.0.1: my_tool-1.0.1.tar.gz, my_tool-1.0.1-py3-none-any.whl
    rm = ReleaseManager('data-utils', '0.1.0') rm.bump('minor') rm.bump('major') rm.release() rm.history()Released data-utils 1.0.0 v1.0.0: data_utils-1.0.0.tar.gz, data_utils-1.0.0-py3-none-any.whl

    More PyPI Packaging exercises

    All Python exercises · 50 practice problems · Modules & Packaging quiz