Build a private pypi with github

Jackie
2 min readApr 24, 2020

--

recently, I have tried to build a pypi server on top of github.

here are the steps:

  1. create a repo, to host those packages
  2. at the root level, define the setup.py with the findpackages(), like
import setuptoolswith open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="pypi",
version="0.0.1",
author="lwpro2",
author_email="lwpro2",
description="A pypi for python packages",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/lwpro2",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
)

3. at each packages, add the setup.py as well

import setuptoolswith open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="package1",
version="0.0.2",
author="lwpro2",
author_email="lwpro2",
description="A fake library",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/lwpro2",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
)

the folder structure will be like

--pypi
------setup.py
------README.md
------package1
-------------setup.py
-------------README.md
-------------__init__.py
-------------functions.py
------package2
-------------setup.py
-------------README.md
-------------__init__.py
-------------functions.py

4. run this command to generate the binaries

python3 setup.py sdist bdist_wheel

the folder will become

--pypi
------setup.py
------README.md
------package1
-------------setup.py
-------------README.md
-------------__init__.py
-------------functions.py

-------------build/
-------------dist/
--------------------package1-0.0.1.tar.gz
------package2
-------------setup.py
-------------README.md
-------------__init__.py
-------------functions.py

-------------build/
-------------dist/
--------------------package2-0.0.1.tar.gz

5. then create a static pypi server which comply to Pep 503, like

6. then add the new pypi server into Pipfile and pyproject.toml

Pipfile

[source]
name = "privatepypi"
url = "http://private/pypi"
verify_ssl = false
[dev-packages][packages]
package1 = {version = "*", index = "privatepypi"}

pyproject.toml

[[tool.poetry.source]]
name = "privatepypi"
url = "https://private/pypi"
secondary = true
[tool.poetry.dependencies]
package2= "^0.0.1"

7. then can install packages using the commands as normal

pip install

poetry install

--

--

No responses yet