Skip to content

Latest commit

 

History

History
219 lines (161 loc) · 3.94 KB

PythonPackaging.md

File metadata and controls

219 lines (161 loc) · 3.94 KB

Python Packaging

PyPI

Installation

Get pip:

python get-pip.py

Get wheel, twine:

pip install wheel
pip install twine

PyPI : Create an Account

~/.pypirc

[distutils]
index-servers =
  pypi
  testpypi

[pypi]
#repository=https://pypi.python/pypi
repository:https://upload.pypi.org/legacy/
username=<username>
password=<password>


[testpypi]
#repository=https://testpypi.python/pypi
repository:https://test.pypi.org/legacy/
username=<username>
password=<password>

PyPI : Create a Package

Create setup.py:

cd ~/git/pydemia
vim setup.py
import os
from setuptools import setup, find_packages
import datetime as dt
from pip._internal.req import parse_requirements
from pip._internal.network.session import PipSession


package_nm = 'kubernetes-client'
__version__ = "0.1.0"

req_file = os.path.join(
    os.path.dirname(__file__),
    "requirements.txt",
)
if os.path.exists(req_file):
    install_requires_gen = parse_requirements(
        req_file,
        session=PipSession(),
    )
    install_requires = [str(i.requirement) for i in install_requires_gen]
else:
    install_requires = []


with open(f'{package_nm}/__version__.py', 'w') as f:
    version_py_module = f'''#-*- coding: utf-8 -*-
# This file is automatically generated by 'setup.py'
"""
Modified on {dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
"""
__all__ = ['__version__']

__version__ = '{__version__}'
'''
    f.write(version_py_module)

long_desc = ""

setup(
    name=package_nm,
    version=__version__,
    author_email='[email protected]',
    url='',
    description='High-level functional API for Kubernetes Resources and 3rd party CRDs, based on the official kubernetes-client, and more.',
    long_description=long_desc,
    python_requires='>=3.8',
    packages=find_packages(
        exclude=['contrib', 'docs', 'tests'],
    ),
    install_requires=install_requires,
)

Create Package Folder:

mkdir pydemia
vim pydemia/__init__.py

PyPI : Build a Package

python3 -m pip install --upgrade build
python3 -m build
#python setup.py sdist bdist_wheel

PyPI : Register a new Package (only at the First time)

#python setup.py register -r https://testpypi.python.org/pypi
#python setup.py register -r https://pypi.python.org/pypi
python3 -m twine upload --repository pypi dist/* \
    -u <username> \
    -p <password>

PyPI : Distributte a Package

Note : The name and version of a package is not be overrided.

python3 -m pip install --upgrade twine
twine upload dist/<package>.tar.gz <package>.whl

Conda

Installation

conda install conda-build anaconda-client

Then, Create an Account on Anaconda.org

Build a conda Package from PyPI

Note : Not all of PyPI Packages are in conda repository, Your build can be failed with package dependencies.

conda skeleton pypi <package_name>
conda build <--python 3.5> <package_name>

Check it:

<your-path-to-anaconda>/conda-bld

You can see linux-64, osx-64, win-64, etc.

Convert it to other platform: Linux & OS X:

conda convert -f --platform all <your-path-to-anaconda>/conda-bld/<your-os>/<your-package-file> -o <outputdir>/

Windows:

conda convert -f --platform all <your-path-to-anaconda>/conda-bld/<your-os>/<your-package-file> -o <outputdir>\

Log-in

anaconda login

Using Anaconda API: https://api.anaconda.org
Username: pydemia
pydemia's Password: 
login successful

Upload to Anaconda.org

anaconda upload <your-package-name>

(Optional) If you want to upload the package at the same time when your build is finished:

conda config --set anaconda_upload yes

Log-out

anaconda logout

Using Anaconda API: https://api.anaconda.org
logout successful

Install your Package

conda install -c <id> <package_name>

Done.