Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
November 26, 2021 03:16 pm GMT

Packaging and Releasing (Lab 10)

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-rokayversion = 1.0.4author = Ahmad Rokayauthor_email = *************description = Uses python to generate static html files from a single txt or folder of txt fileslong_description = file: README.mdlong_description_content_type = text/markdownurl = https://github.com/a-rokay/static-site-generatorproject_urls =    Bug Tracker = https://github.com/a-rokay/static-site-generator/issuesclassifiers =    Programming Language :: Python :: 3    License :: OSI Approved :: MIT License    Operating System :: OS Independent[options]package_dir =    = srcpackages = find:python_requires = >=3.6[options.packages.find]where = src

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"

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

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.
Image description

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!


Original Link: https://dev.to/ar/packaging-and-releasing-lab-10-3gcl

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To