Makefiles และ classifiers

การพัฒนา Python Packages

James Fulton

Climate informatics researcher

Classifiers

  • Metadata ของแพ็กเกจ
  • ช่วยให้ผู้ใช้ค้นหาแพ็กเกจบน PyPI
  • ควรระบุ
    • สถานะของแพ็กเกจ
    • กลุ่มผู้ใช้เป้าหมาย
    • ประเภทสัญญาอนุญาต
    • ภาษา
    • เวอร์ชัน Python ที่รองรับ
  • มี classifiers อื่น ๆ อีกมาก https://pypi.org/classifiers

ภายใน setup.py ของ mysklearn

setup(
    ...
    classifiers=[
        'Development Status :: 2 - Pre-Alpha',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: MIT License',
        'Natural Language :: English',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3.8',
    ],
    ...
)
การพัฒนา Python Packages

Makefile ใช้ทำอะไร?

  • ใช้สำหรับทำให้กระบวนการสร้างแพ็กเกจเป็นอัตโนมัติ
mysklearn/
...
|-- README.md
|-- setup.py
|-- Makefile  <---
...
การพัฒนา Python Packages

Makefile มีอะไรบ้าง?

ภายใน Makefile

...

dist: ## builds source and wheel package
    python3 setup.py sdist bdist_wheel

clean-build: ## remove build artifacts rm -fr build/ rm -fr dist/ rm -fr .eggs/
test: ## run tests quickly with the default Python pytest
release: dist ## package and upload a release twine upload dist/*
การพัฒนา Python Packages

ใช้งาน Makefile อย่างไร?

make <function-name>
mysklearn/ <--- navigate to here
...
|-- README.md
|-- setup.py
|-- Makefile  
...
การพัฒนา Python Packages

ใช้งาน Makefile อย่างไร?

หากต้องการใช้ฟังก์ชัน dist ให้พิมพ์คำสั่งนี้ใน terminal

make dist

ภายใน Makefile

...

dist: ## builds source and wheel package
    python3 setup.py sdist bdist_wheel

clean-build: ## remove build artifacts
    rm -fr build/
    rm -fr dist/
    rm -fr .eggs/

test: ## run tests quickly with the default Python
    pytest

release: dist ## package and upload a release
    twine upload dist/*
การพัฒนา Python Packages

สรุป Makefile

make help
clean                remove all build, test, coverage and Python artifacts
clean-build          remove build artifacts
clean-pyc            remove Python file artifacts
clean-test           remove test and coverage artifacts
lint                 check style with flake8
test                 run tests quickly with the default Python
test-all             run tests on every Python version with tox
release              package and upload a release
dist                 builds source and wheel package
install              install the package to the active Python's site-packages
การพัฒนา Python Packages

มาฝึกกันเถอะ!

การพัฒนา Python Packages

Preparing Video For Download...