Registering with PyPI from modern Python library self-made

I want to register my library on PyPI

... but Python has something like Ruby's bundler No (I don't think it's unified even if it fits) A free directory structure for each product ...

At least I wanted to unify my products Directory structure when creating a Python library Write notes about environment construction. I'll forget ...

I am aware that the version of Python used is 3.3 or later. Prior to that (3.2, 3.1 ... 2.x) is not considered. I don't think it's a problem ...

Library created for testing purposes

スクリーンショット 2013-10-16 8.08.53.png

I made a library called ** fizzbuzz **. It's a library or command line tool. I will write notes based on the structure of this library.

Library directory / file structure

The directory and file structure is as follows.

fizzbuzz
└lib #Library body
  └bin #Execution script body
  └fizzbuzz #Library name directory
      └ __init__.py #Initialization settings when importing the library are here
  └test #Test file
requirements.txt # travis-ci and setup.Use with py. pip--Can be made with freeze.
info.py #A file that contains package author information, etc.
version.py #File containing version information
setup.py #File to be the key

I think it's okay because of this.

Build the pyvenv environment under the library directory

Starting with Python 3.3, virtualenv is included. To test the operation of the library, use the following command Create a local Python runtime environment.

> pyvenv .venv

I've been using it since virtualenv, so it's under .venv I try to create an environment for pyvenv, but I think it's optional (such as .pvenv).

Since I built a local Python execution environment, activateThe shellsourceImport with a command. By doing this, you will be able to use the Python environment under `` `.venv```. (like python command)

> source .venv/bin/activate

Installation of setuptools

Up to a certain version of virtualenv The system library was imported by virtualenv, It cannot be imported as a new version of virtualenv and pyvenv. Running pyvenv builds a pure environment.

Therefore, the environment is created without easy_install. Run the following command to set up setuptools.

Quoted from the PyPI page of setuptools.

> wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python

Now run the easy_install command and it's on your PyPI You will be able to install the package. But rather than installing the PyPI package with easy_install

It's easier to use with pip. Let's put pip...



## pip installation

 If you have easy_install installed, you can easily install pip.

easy_install pip


 Now you are ready.

# Make a list of required libraries

 If your library uses another library
 In the hash passed to the setuptools.setup function
 You have to specify install_requires.
 You can easily create a list of required libraries using pip.

pip freeze > requirements.txt


 Travis CI also uses requirements.txt

 In setup.py, specify install_requires using ``` requirement.txt```.

```py
setup({
  install_requires: open('requirements.txt').read().splitlines(),
})

This will install the external libraries required by the library.

Where to keep the package information

Package creator information

Which file should have the library creator information displayed on PyPI I was at a loss, but I put it as info.py directly under package root.

info.py


# package information.
INFO = dict(
  name        = "PyFizzBuzz",
  description = "FizzBuzz cli tool",
  author      = "Keiji Matsuzaki",
  author_email = "[email protected]",
  license     = "MIT License",
  url         = "https://github.com/futoase/fizzbuzz",
  classifiers = [
    "Programming Language :: Python :: 3.2",
    "Programming Language :: Python :: 3.3",
    "License :: OSI Approved :: MIT License"
  ]
)

classifiers have their own library from List here Select and set the genre that seems to match.

Package version

version.Specify VERSION in py.




#### **`version.py`**
```py

VERSION = "0.0.3"

Creating a MANIFEST.in file

** 20131017 postscript **

package_info in dir.py, version.py, requirements.Because you didn't specify a txt file


 I have to write a MANIFEST.in file.
 I didn't check it when I wrote this article, so I couldn't find any issues that weren't included.
 So add it.


#### **`MANIFEST.in`**
```py

include info.py
include version.py
include requirements.txt

Package testing

Test the package using the pip command

> pip install .

By specifying yourself in your own directory and doing a pip install, pyvenvYou can use your own library in your environment.

> pip list
konira (0.3.2)
pip (1.4.1)
PyFizzBuzz (0.0.3)
setuptools (1.1.5)

If you find a bug in your library after pip install Execute the following command under the environment of pyvenv.

> pip uninstall PyFizzBuzz

It's like specifying gemspec in the Gemfile ... I think you should execute the command with feelings ...

Operation check

This time, fizzbuzz is executed as a command, so

.venv/bin/The command is located in fizzbuzz.



(.venv) > fizzbuzz 10 | head -3
1 2 Fizz


 I was able to check the operation.

# Register with PyPI

 If you have not registered to PyPI, execute the following command to register.


#### **`~/.If you have not generated a piprc file, you will be prompted to register your user name and password.(Should be)...`**
> python setup.py register

Upload the package to PyPI.

> python setup.py sdist upload

OK if a library page is created on PyPI

It may be different for C extension libraries. (I don't consider uploading egg files ...)

After uploading to PyPI

The number of downloads per day, a list of files of versions uploaded in the past, etc. You can see it from the PyPI page. (Login required)

It's pretty fun.

Digression

Since setuptools is integrated with distribute, only setuptools is imported, but Before the integration, the packages to be imported were separated by setup.py in the following form.

setup.py


try:
    import setuptools
except ImportError:
    from distribute_setup import use_setuptools
    use_setuptools()
from setuptools import setup, find_packages

Distribute_setup.py was dropped from here (I can't access it right now), and it was included in the package.

I'm glad it was unified with setuptools. (This article may be possible because it doesn't consider backward compatibility ...)

Recommended Posts

Registering with PyPI from modern Python library self-made
x86 compiler self-made with python
With skype, notify with skype from python!
I tried using the Python library from Ruby with PyCall
Package python runtime and pypi library with chef / omnibus and Docker
Using Rstan from Python with PypeR
Setup modern Python environment with Homebrew
Install Python from source with Ansible
Create folders from '01' to '12' with python
Run Aprili from Python with Orange
[Hyperledger Iroha] Query with Python library
Read fbx from python with cinema4d
Logistic regression analysis Self-made with python
Collecting information from Twitter with Python (Twitter API)
Receive textual data from mysql with python
Get html from element with Python selenium
[Note] Get data from PostgreSQL with Python
Play audio files from Python with interrupts
Create wordcloud from your tweet with python3
Tweet from python with Twitter Developer + Tweepy
Business efficiency starting from scratch with Python
Decrypt files encrypted with openssl from python with openssl
[Python] Register your own library on PyPI
Use cryptography library cryptography with Docker Python image
Working with Azure CosmosDB from Python Part.2
Image acquisition from camera with Python + OpenCV
Getting started with Dynamo from Python boto
Try HTML scraping with a Python library
Publish your own Python library with Homebrew
Use C ++ functions from python with pybind11
[Python] Get Python package information with PyPI API
Build a modern Python environment with Neovim
Make the library created by Eigen in C ++ available from Python with Boost.Numpy.
I registered PyQCheck, a library that can perform QuickCheck with Python, in PyPI.
Collecting information from Twitter with Python (Environment construction)
[Personal memo] julia --Using Python library with julia using PyCall
Csv output from Google search with [Python]! 【Easy】
Library comparison summary to generate PDF with Python
Extract text from PowerPoint with Python! (Compatible with tables)
Try operating Studio Library from Python. [Anim Save]
Wrap C with Cython for use from Python
~ Tips for Python beginners from Pythonista with love ① ~
Make OpenCV3 available from python3 installed with pyenv
Image processing from scratch with python (4) Contour extraction
Generate an insert statement from CSV with Python.
Manage AWS nicely with the Python library Boto
Call Python library for text normalization from MATLAB
Create a decision tree from 0 with Python (1. Overview)
Install vim7.3 (+ python2.4) from source (compatible with Gundo.vim)
Wrap C ++ with Cython for use from Python
Read line by line from a file with Python
Make JSON into CSV with Python from Splunk
From Python environment construction to virtual environment construction with anaconda
Extract data from a web page with Python
FizzBuzz with Python3
Scraping with Python
Python ast library
Statistics with python
Scraping with Python
Python with Go
Integrate with Python