Skip to content
Snippets Groups Projects
Unverified Commit c036f237 authored by Laurent Modolo's avatar Laurent Modolo
Browse files

add dependecies section

parent d44b3a74
Branches
No related tags found
No related merge requests found
......@@ -2,9 +2,15 @@
title: Packaging with Python
---
## Python `pip`
# Packaging with Python
##
![cc](https://creativecommons.org/images/deed/cc_icon_white_x2.png)![by](https://creativecommons.org/images/deed/attribution_icon_white_x2.png)![sa](https://creativecommons.org/images/deed/sa_white_x2.png)
[![cc_by_sa](./img/cc_by_sa.png)](http://creativecommons.org/licenses/by-sa/4.0/)
## Python `pip`
![pipy](https://pypi.org/static/images/logo-large.72ad8bf1.svg)
......@@ -138,5 +144,111 @@ dist/
The `tar.gz` file is a Source Archive whereas the `.whl` file is a Built Distribution. Newer pip versions preferentially install built distributions, but will fall back to source archives if needed.
**You should always upload a source archive and provide built archives for the platforms your project is compatible with.**
What can you do with those two file ?
### Install them:
You can use the `.whl` or the `.tar.gz` file to install your package
```bash
pip3 install dist/example_pkg_YOUR_USERNAME_HERE-0.0.1.tar.gz --user
```
### Upload them
You can upload your package to [pypi](https://pypi.org), but first you can run test on [https://test.pypi.org/](https://test.pypi.org/). As https://pypi.org is an archive, if you upload broken packages, they will stay there.
You first need to create an account https://test.pypi.org/account/register/
Then we use the `twine` tools that we installed before
```bash
twine upload --skip-existing --repository testpypi dist/*
```
The output should look like that:
```bash
Uploading distributions to https://test.pypi.org/legacy/
Enter your username: [your username]
Enter your password:
Uploading example_pkg_YOUR_USERNAME_HERE-0.0.1-py3-none-any.whl
100%|█████████████████████| 4.65k/4.65k [00:01<00:00, 2.88kB/s]
Uploading example_pkg_YOUR_USERNAME_HERE-0.0.1.tar.gz
100%|█████████████████████| 4.25k/4.25k [00:01<00:00, 3.05kB/s]
```
To install your package from https://test.pypi.org you can use the following `pip` options:
```bash
pip install --index-url https://test.pypi.org/simple/ --no-deps example-pkg-YOUR-USERNAME-HERE --user
```
You should be able to open a python console anywhere and run:
```python
>>> import example_pkg
```
When everything is OK, you can create an account on https://pypi.org and use the `twine`command without the `--repository testpypi` option.
## Creating executable software
You can also use `pip` to distribute executable software. To do that, you have to specify the `__main__` function to execute when calling your software in the `setup.py` file.
```python
setuptools.setup(
...
entry_points={
'console_scripts': ['example_pkg=example_pkg.__main__:main'],
},
...
)
```
You can have different executable in this list with the format `EXECUTABLE_NAME=LIBRARY.FILE:FUNCTION`
After the installation, calling `example_pkg`will run your software if your `$PATH` is correctly configured.
## Adding dependencies to your package
As your project will grow more complex, you will split it into different file for code clarity.
Your `__init__.py` file will need to contain a list of all the `.py` files in the `example_pkg` repository:
```python
#!/usr/bin/env python3
# -*-coding:Utf-8 -*
"""
idr library
"""
name = "midr"
__all__ = ["__main__",
"idr", "samic", "archimedean", "archimedean_plots",
"log", "narrowpeak", "raw_matrix", "auxiliary"]
```
As you don't want to reinvente the wheel, you may also import other python library (which could be installed with `pip`). You can specify a list of these library in the `setup.py`file:
```python
setuptools.setup(
...
install_requires=[
'cmake>=3.18'
'scipy>=1.3',
'numpy>=1.16',
'pynverse>=0.1',
'pandas>=0.25.0',
'mpmath>=1.1.0',
'matplotlib>=3.0.0'
],
...
)
```
**Don't forget to specify the version of each dependency to ensure that the function you use are present in the installed library.**
If, some package are required for the installation of your package (for example here `cmake`), you should also add them to the `install_requires`list.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment