I registered the package on PyPI for the first time, so I will summarize what I did.
The directory structure is as simple as it gets.
.
├── LICENSE.txt
├── README.md
├── nbupload
│ ├── FileUploaderView.js
│ ├── FileUploaderWidget.py
│ └── __init__.py
└── setup.py
Since it manages git, .gitignore for Python is also included.
Write a minimal setup.py. packages = ['nbupload']
is a way to write a directory name as a package. For details, refer to Documentation.
from setuptools import setup
setup(
name = "nbupload",
version = "0.0.1",
packages=['nbupload'],
)
with this,
python setup.py develop
If you type, it will be installed for develop and you can import it normally. As an entity, there was a file called nbupload.egg-link in the python site-packages directory, in which the path to the package directory was written.
Uninstall
python setup.py develop -u
It's fine.
setup.py is lonely above, so add more.
If you don't have a pypi account, get one. There is also a testpypi for the package registration test, so register an account there as well. Please note that the password to be registered must be placed in the home directory in plain text (although it can be deleted immediately).
I feel that the password must be 16 characters or more and there are no uppercase or lowercase letters. Google's OpenID can't be used because Google no longer supports new registrations.
Create .pypirc in your home directory. (If you only register on pypi, you don't have to put this (?), But if you have testpypi, you have to put this)
I referred to here.
[distutils]
index-servers =
pypi
pypitest
[pypi]
repository: https://pypi.python.org/pypi
username: {{your_username}}
password: {{your_password}}
[pypitest]
repository: https://testpypi.python.org/pypi
username: {{your_username}}
password: {{your_password}}
Register with testpypi.
python setup.py register -r https://testpypi.python.org/pypi
Now you have an item on your pypi, and you can also find it on pip search --index https://testpypi.python.org/pypi nb upload
.
However, as it is, there is no actual package anywhere yet, so I have to upload gzip. You can also write download_url in setup.py and specify the gzip of the github tag, but by default pip install
ignores URLs other than pypi (you can pass it with --allow-external
). Good to upload to pypi itself. The next command does that.
python setup.py sdist upload -r https://testpypi.python.org/pypi
You can now install it with pip install --index-url https://testpypi.python.org/simple/ nbupload
.
If you can do so far, all you have to do is register for the production pypi.
python setup.py register
python setup.py sdist upload
It ends with.
This time I had to include JS in the package and distribute it, so I had to write this in setup.py.
package_data = {
'nbupload': ['FileUploaderView.js'],
},
If you don't do this, by default packaging with python setup.py sdist upload
will not include any non-python files.
Recommended Posts