DEV Community

Cover image for Lab10 Packaging and Releasing SSG
Jason
Jason

Posted on

Lab10 Packaging and Releasing SSG

Lab10 will focus on packaging and releasing my own SSG project and getting our code into the hands of users. I use the PyPI to do it.

How to set up

I followed the instruction to finish all the steps.
First, I need to change the directory structure before I package SSG. I create a new directory named src/. When importing the package, Python searches through the directories on sys.path looking for the package subdirectory. I also need to update import information of all files.
Second, I creat a new file named _init_.py. The _init_.py files is required to import the directory as a package, and should be empty.
Image description

Third, edit the exist pyproject.toml file which tells build tools (like pip and build) what is required to build your project.

[build-system]
requires = [
    "setuptools>=42",
    "wheel"
]
build-backend = "setuptools.build_meta"
Enter fullscreen mode Exit fullscreen mode

Forth, configuring metadata. There are two types of metadata: static and dynamic. I use the static metadata because it is simpler, easier to read, and avoids many common errors. setup.cfg is the configuration file for setuptools. It tells setuptools about your package (such as the name and version) as well as which code files to include. Eventually much of this configuration may be able to move to pyproject.toml.

[metadata]
name = magic-ssg
version = 0.9.1
author = Tengzhen Zhao
author_email = tzhao16@myseneca.com
description = A simple Static Site Generator tool, and it can help you to generate .html from .txt and .md files. 
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/Yoda-Canada/Magic-SSG
project_urls =
    Bug Tracker = https://github.com/Yoda-Canada/Magic-SSG/issues
classifiers =
    Programming Language :: Python :: 3
    License :: OSI Approved :: MIT License
    Operating System :: OS Independent

[options]
package_dir =
    = src
packages = find:
python_requires = >=3.8.5

[options.packages.find]
where = src
Enter fullscreen mode Exit fullscreen mode

Fifth, Now run this command from the same directory where pyproject.toml is located. Then register an account using this register page

py -m pip install --upgrade build
py -m build
Enter fullscreen mode Exit fullscreen mode
py -m pip install --upgrade twine
py -m twine upload --repository testpypi dist/*
Enter fullscreen mode Exit fullscreen mode

Sixth, after registered, I use twine to upload the distribution packages and install Twine. Once installed, run Twine to upload all of the archives under dist.

py -m pip install --upgrade twine
py -m twine upload --repository testpypi dist/*
Enter fullscreen mode Exit fullscreen mode

The magic-ssg 1.0.0 upload to the PyPI successfully.

Testing

Former students of OSD600 helped me to test the installation of this software. The installation went smoothly and there was no problem running.
Image description
Image description

Reflection

I learned how to control the version and how to package and publish the program. I know how the version number is constantly updated, which is helpful for my future to develop a project.

Top comments (0)