Python Packaging: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
No edit summary
Line 39: Line 39:


* [https://stackoverflow.com/questions/4830856/is-it-possible-to-use-pip-to-install-a-package-from-a-private-github-repository Is is possible to use pip to install a package from a private GitHub repository] - StackOverflow
* [https://stackoverflow.com/questions/4830856/is-it-possible-to-use-pip-to-install-a-package-from-a-private-github-repository Is is possible to use pip to install a package from a private GitHub repository] - StackOverflow
* [https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/ Generating a new SSH key and adding it to the ssh-agent] - GitHub Help
* [https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/ Adding a new SSH key to your GitHub account] - GitHub Help


=== Overview of process ===


* It's necessary to store a SSH key locally
=== Prerequisites ===
* Then install the key on GitHub
 
* Install the package hosted on GitHub with `pip install git+ssh://git@github.com/username/my-repo.git`
Create and store a local SSH key. (One each for all computers where development is happening.) See [https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/ Generating a new SSH key and adding it to the ssh-agent] - GitHub Help
 
Register the key on the GitHub account. See [https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/ Adding a new SSH key to your GitHub account] - GitHub Help
 
One key pair will suffice for all ssh requests, i.e. for a computer with the key installed, the key can be used for all repositories in the GitHub account.
 
=== Installing a package ===
 
To install a package from a private GitHub repository:
 
<syntaxhighlight lang="bash">
$ pip install git+ssh://git@github.com/username/my-repo.git
</syntaxhighlight>
 
The packages dependencies will be installed along with it as long as they are listed in the package's `requirements.txt`.
 
=== Updating a package ===
 
After changes have been committed to a repository, they can be retrieved with:
 
<syntaxhighlight lang="bash">
$ pip install git+ssh://git@github.com/username/my-repo.git --upgrade
  (or)
$ pip install git+ssh://git@github.com/username/my-repo.git -U
</syntaxhighlight>


== See also ==
== See also ==
<references />
<references />

Revision as of 16:46, 30 March 2018

Overview

Create python packages that can be distributed with pip from GitHub (and not PyPi).

Configuration

A setup config file, setup.py, in the repo root directory should contain a single call to setuptools.setup(), like so: [1]

from setuptools import setup

setup(name='my_package',
      version='0.1',
      description='My package description',
      url='http://github.com/dbarchowsky/my-package',
      author='Damien Barchowsky',
      author_email='dbarchowsky@gmail.com',
      license='MIT',
      packages=['my_package'],
      zip_safe=False)

After which the package can be installed locally with

$ pip install .

And once installed the package can be used like this:

>>> import my_package
>>> my_package.some_routine()

Installation from GitHub

Links


Prerequisites

Create and store a local SSH key. (One each for all computers where development is happening.) See Generating a new SSH key and adding it to the ssh-agent - GitHub Help

Register the key on the GitHub account. See Adding a new SSH key to your GitHub account - GitHub Help

One key pair will suffice for all ssh requests, i.e. for a computer with the key installed, the key can be used for all repositories in the GitHub account.

Installing a package

To install a package from a private GitHub repository:

$ pip install git+ssh://git@github.com/username/my-repo.git

The packages dependencies will be installed along with it as long as they are listed in the package's requirements.txt.

Updating a package

After changes have been committed to a repository, they can be retrieved with:

$ pip install git+ssh://git@github.com/username/my-repo.git --upgrade
  (or) 
$ pip install git+ssh://git@github.com/username/my-repo.git -U

See also

  1. How To Package Your Python Code - Python Packaging Tutorial