The ultimate guide to python packaging
I’ll just give you a few links as the knowledge source of this post
https://github.com/yingshaoxo/auto_everything/blob/master/setup.py
https://packaging.python.org/tutorials/packaging-projects/
https://www.tutorialsteacher.com/python/python-package
https://yingshaoxo.blogspot.com/2021/01/ways-of-importing-python-module.html
Then here are few tips for you
- every module under your package should have an
__init__.py
- the
name
insetup.py
not necessarily the package name that you could use. setuptools.find_packages()
does nothing but return a list of strings. And each string is a folder name. And it only returns folders that have__init__.py
inside.
Tree
.
├── your_real_package_name
│ ├── __init__.py
│ ├── logger
│ │ ├── __init__.py
│ │ ├── my_logging.py
│ └── utils
├── README.md
└── setup.py
Importing
from your_real_package_name.logger import my_logging
or
from your_real_package_name.logger.my_logging import *
Setup.py
from setuptools import setup, find_packages
from os.path import dirname, join, abspath
version = '0.1'
file_path = join(abspath(dirname(__file__)), "README.md")
with open(file_path) as f:
long_description = f.read()
setup(name='whatever', # you think this name is the package name, but it's not, it can be whatever you like. In the end, if you want to import this package, you use `your_real_package_name`, because `your_real_package_name` folder contains a file called `__init__.py`
version=version,
description="This is a system, yet it is also a package.",
long_description=long_description,
long_description_content_type='text/markdown',
classifiers=[
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3',
'Topic :: System',
],
url='http://github.com/yingshaoxo/whatever',
author='yingshaoxo',
author_email='yingshaoxo@gmail.com',
license='GPLv3',
install_requires=[
"setuptools",
],
include_package_data=False,
packages=[
"your_real_package_name"
], # a folder name
)