It was unexpectedly troublesome to make it as easily as the node package system.
Create an appropriate directory.
mkdir mymodule && cd $_
Use virtualenv or direnv to isolate the system python from the python in the directory.
Virtualenv env
for virtualenv
For direnv, do direnv edit .
and then layout python
in the editor you opened.
If you do pip freeze
and only wsgiref appears, the environment construction is complete.
It is isolated from the system pip, so you are free to pip install the required modules.
.
├── .gitignore
├── LICENSE
├── MANIFEST.in
├── README.md
├── mymodule.py
├── setup.py
└── tests
└── myplugin_test.py
.gitignore
Based on Python's .gitignore, add the env directory if you use virtualenv, add .direnv if you use direnv. gitignore/Python.gitignore
README.md
Actually, restructuredText that is formatted and displayed with PyPI is better than markdown.
setup.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import with_statement
from setuptools import setup
with open("README.md") as f:
long_description = f.read()
setup(
name="mymodule",
version="0.1.0",
description="hogehoge.",
long_description=long_description,
author="yourid",
author_email="youremail",
url="yoururl",
py_modules=["mymodule"],
include_package_data=True,
install_requires=["Flask"],
tests_require=["nose"],
license="MIT",
keywords="",
zip_safe=False,
classifiers=[]
)
py_modules specifies the filename of the module to publish.
install_requires and tests_require write out dependent modules. Depending on the article, pip freeze
may be specified here, but it is better to write without manually specifying the version because it will be specified up to the version and it will be like dependency hell.
Select classifiers from here.
MANIFEST.in
By default, only Python files are included in the module, so this is necessary to include special text files. This time, write ʻinclude README.md` to include README.md. If you prepare requirements.txt, you need to describe it here as well.
mymodule.py
Module body. Write appropriately.
tests/
Module testing. Write appropriately. Write properly.
Use nose. You can enter by doing pip install nose
.
Execution is nosetests
Register with Test PyPI and PyPI. Create a .pypirc file in your home directory and write the registration information.
[distutils]
index-servers =
pypi
pypitest
[pypi]
repository: https://pypi.python.org/pypi
username: {{User name}}
password: {{password}}
[pypitest]
repository: https://testpypi.python.org/pypi
username: {{User name}}
password: {{password}}
Once the module is complete and the tests are complete, python setup.py register -r https://testpypi.python.org/pypi
to register the package and then python setup.py sdist upload -r https: // Register with Test PyPI at testpypi.python.org/pypi
. Since it is a test site, you can register and test more and more.
If it is registered without any problem, you can install it with pip install --index-url https://testpypi.python.org/simple/mymodule
.
After testing whether it can be installed properly with Python on the system, import it and use it, etc., register it in the production PyPI.
Register modules on production PyPI with python setup.py register
You can upload modules to production PyPI with python setup.py sdist upload
.
I made this airtoxin/plugin-loader
Recommended Posts