Lab10 Packaging and Releasing SSG
Published: 2021-11-27 20:36:37

Lab10 will focus on packaging and releasing my own SSG project and getting our code into the hands of users. I use the [PyPI ](https://packaging.python.org/tutorials/packaging-projects/)to do it. 
### How to set up
I followed the [instruction](https://packaging.python.org/tutorials/packaging-projects/) 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/emccygb0dlm3iy2qtqio.png)
 
__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"
```
__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
```
__Fifth__, Now run this command from the same directory where pyproject.toml is located. Then register an account using this [register page](https://test.pypi.org/account/register/)
```
py -m pip install --upgrade build
py -m build
```
```
py -m pip install --upgrade twine
py -m twine upload --repository testpypi dist/*
```
__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/*
```
The [magic-ssg 1.0.0](https://test.pypi.org/project/magic-ssg/)  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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d1cmjx6r8xrvcxlvhk5y.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tc1ihi51tcs0o1gg0ttw.png)
 
### 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.