2

Packaging and Releasing (Lab 10)

 2 years ago
source link: https://dev.to/ar/packaging-and-releasing-lab-10-3gcl
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

For this lab, we were tasked with packaging and releasing our SSG project we've been working on all semester. Since I wrote my SSG in Python, I chose PyPI for this.

Setting up

Reading PyPI's docs, I realized that I have to do a bit of restructuring, add a new file, and install setuptools, which does the packaging.

Installing setuptools was simple:
pip install setuptools

I moved the ssg folder containing the main code into a src folder and added a new setup.cfg file, which is used by setuptools.

setup.cfg
[metadata]
name = ssg-a-rokay
version = 1.0.4
author = Ahmad Rokay
author_email = *************
description = Uses python to generate static html files from a single txt or folder of txt files
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/a-rokay/static-site-generator
project_urls =
    Bug Tracker = https://github.com/a-rokay/static-site-generator/issues
classifiers =
    Programming Language :: Python :: 3
    License :: OSI Approved :: MIT License
    Operating System :: OS Independent

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

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

I also had to add some lines to pyproject.toml, which tells pip and build what is required to build my project.

[build-system]
requires = [
    "setuptools>=42",
    "markdown",
    "pygments"
]
build-backend = "setuptools.build_meta"
Enter fullscreen modeExit fullscreen mode

Because I moved the main code into a new folder, I had to update the imports for my tests to reflect the new structure:

Packaging and releasing

Now that everything was setup, I was able to package and release.

py -m build
py -m twine upload dist/*

After creating an account on PyPI and entering my information, the project was successfully released!

To install my project, all that has to be run is:
pip install ssg-a-rokay

Testing

I reached out through Slack to another student and gave them the PyPI link to have them attempt to install my project. They had zero issues and were easily able to implement my code.

Outcomes

I've always thought you had to have your project approved by some big entity to be able to install it through pip. It was very interesting to see how easy it actually is. It felt really good installing my work from PyPI and seeing another student effortlessly do too!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK