PyPI hosting on AWS S3
Create a web hosting in the AWS S3
It is a common task to create a web hosting in the S3 bucket. However, you have to change the permission to access the bucket via http protocol. For that you can right click the dist folder and select the Make public
from the drop down menu.
Create Distribution package
Create a directory for distribution package source for example ojservice
. Your folder structure is as follows:
ojsevice+
|
+index.html
|
+error.html
|
+LICENSE.txt
|
+README.txt
|
+setup.py
|
+ojservice+
|
+__init__.py
|
+helloservice.py
In the above structure, index.html and error.html are two files given in the AWS S3 host configuration under the bucket’s Static web hosting
: respectively index and error documents.
Here the helloservice.py:
def hello(name):
return 'Hello {}'.format(name)
In addition to that you have to install the package pip2pi
pip install pip2pi
Create setup.py file for the distribution:
from distutils.core import setup
setup(
name='ojservice',
version='0.1',
packages=['ojservice',],
license='Coreative Commons Attribution-Noncommercial-Share Alike license',
long_description=open('README.txt').read(),
)
Create Distribution package which target is dist
folder under the parent directory
python setup.py sdist
run the following command to create the package hierarchy:
dir2pi dist
Sync the folder to the s3 bucket for example: ojpy
aws s3 sync dist/simple s3://ojpy
Install the package using pip
Setup the client application to import and test the pip distribution package. Virtual environment is the best.
mkdir ojtest
cd ojtest
#setup virtual env
virtualenv ~/.virtualenvs/ojtest
#activate the enviroment
source ~/.virtualenvs/ojtest/bin/activate
Here the command
pip install --index-url=http://<s3 host>/ojservice ojservice==0.1 --trusted-host <s3 host>
Here the example
pip install --index-url=http://ojpy.s3-website-ap-southeast-2.amazonaws.com/ojservice/ ojservice==0.1 --trusted-host ojpy.s3-website-ap-southeast-2.amazonaws.com
Here the code snippet to import from the distributed package
from ojservice import helloservice
print(helloservice.hello('OJ'))
Comments
Post a Comment
commented your blog