Skip to content

Cesarbautista10/Pypi_template_docs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ISE_template_Pypip

This repository is focused on building MicroPython projects using Thonny, a free code editor, and implementing new mechanics to cater to a wider audience.

Note

This repository is tailored for Windows operating systems.

Firstly, you need an account on PyPI, an index where you can find multiple libraries and package projects for various Python applications.

Warning

You need to configure a token in your local file named .pypirc located at "C:/Users/YourUserName/.pypirc".

[pypi]
username = __token__
password = <PyPI token>

You can register and upload your projects, focusing on applications utilizing microcontroller technologies and free code, as they are essential for progress. For more information, read here.

Environment

You need to install two libraries:

pip install --upgrade twine

and

pip install wheel

Files

The following files are necessary for building the project.

Create your file using a simple class as an example:

# calculator.py
class Calculator:
    def __init__(self, numbers):
        self.numbers = numbers

    def sum(self):
        return sum(self.numbers)

    def subtract(self):
        result = self.numbers[0]
        for num in self.numbers[1:]:
            result -= num
        return result

    def multiply(self):
        result = self.numbers[0]
        for num in self.numbers[1:]:
            result *= num
        return result

    def divide(self):
        result = self.numbers[0]
        for num in self.numbers[1:]:
            result /= num
        return result

Save your file in an independent directory ./package/calculator.py. In a file __init__.py, import the library before:

# __init__.py

from package.calculator import Calculator

Caution

The filename is calculator.py, and the class used is Calculator.

The directory structure is as follows:

./package/ 
    __init__.py
    calculator.py

[!NOTE] "package" is a placeholder name for the package. You can rename this directory and its files as needed.## MANIFEST.in

The MANIFEST.in file is a resource for saving the structure of the package. It's recommended to use this structure:

include README.md
include LICENSE
recursive-include resource *.py

Finally, the setup.py file saves the configuration metadata necessary for building the project. The recommendation for use is to add the following features:

import pathlib
from setuptools import find_packages, setup

HERE = pathlib.Path(__file__).parent

VERSION = '0.x.x'
PACKAGE_NAME = 'package'
AUTHOR = 'Author name'
AUTHOR_EMAIL = '[email protected]'
LICENSE = 'License'
DESCRIPTION = 'Description about the project.'
# Read the contents of your README file for the long description
with open('README.md', 'r', encoding='utf-8') as f:
    LONG_DESCRIPTION = f.read()

# Add your required packages to INSTALL_REQUIRES list
INSTALL_REQUIRES = []

setup(
    name=PACKAGE_NAME,
    version=VERSION,
    description=DESCRIPTION,
    long_description=LONG_DESCRIPTION,
    long_description_content_type='text/markdown',  # Specify the type of content
    author=AUTHOR,
    author_email=AUTHOR_EMAIL,
    install_requires=INSTALL_REQUIRES,
    license=LICENSE,
    packages=find_packages(),
    include_package_data=True
)

Build

To build, simply run the following command:

python setup.py sdist bdist_wheel

The result will be new directories:

build
dist
package.egg-info

Check the configuration before uploading:

twine check dist/*

The result in the console should be:

    Checking dist/package-0.1-py3-none-any.whl: PASSED
    Checking dist/package-0.1.tar.gz: PASSED

Finally, upload the project:

twine upload dist/*

If everything is good, you can see the project deployed on Windows PyPI.

Mode of use:

Install the version package in Thonny, for example:

Thonny install

About

Template for upload libraries to pypi

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages