Skip to main content

This package does amazing things.

Project description

Learn how to develop your own Python Package 📦 - Hi! PARIS Summer School 2023

In this practical research tips session hosted by the Hi! PARIS Engineering Team, you will learn how to build, test and publish Python packages.

This repository contains the code of the python package that was built during the session, as well as the terminal commands used during demos.

This package uses scripts from the LowRankDensity python package developed by the Hi! PARIS Engineering Team.
You can find the LowRankDensity package here: https://github.com/hi-paris/Lowrankdensity


Demo 1: Build your package locally 💻

1. Create a virtual environment with venv

Virtual environments allow you to create isolated environments for different projects, ensuring that each project has its own set of dependencies/libraries.

python -m venv <venv-name>

This command will create a virtual environment folder in the directory you are currently in.

2. Activate the virtual environment

Now that you have created the virtual environment, you need to activate it using the following command.

path\to\venv\<venv-name>\Scripts\activate

3. Install the build library

Build is a Python packaging build frontend library. It will generate the distribution packages of our package.

pip install build

4. Build your project

Run the following command in your terminal to build the distribution packages. This command will generate a dist folder with .whl and .gz files.

pyproject-build

5. Install your package locally

Use pip install to install the package on your computer from the .whl file.

pip install ./dist/<whl-file>

Additional ressources:


Demo 2: Test your package with pytest 🧪

1. Install test and code coverage packages

pip install pytest, pytest-cov

These packages should be installed in your virtual environment. You can check which packages are already installed using pip list.

2. Run tests on your package with pytest

pytest

Pytest will directly identify your package’s test files if they follow pytest’s naming convention.

3. Run code coverage with pytest-cov

pytest --cov

Additional ressources:


Demo 3: Git commands and Github ⌨️

1. Create a public repository on github

https://github.com/

2. Clone the github repository to a folder

Git clone: Download the existing source code from a remote repository

git clone <HTTPS-key>

3. Push modifications to your repository with git commands

Github workflow:

  1. Git status: Check the status of your modifications. With this git command, you can track which file/folder you’ve modified in the repository.
git status
  1. Git add: Add changes to the staging area.
git add . # add all modifications to the stagging area
git add <file-directory> # chose a file/folder to add the stagging area
  1. Git commit: Commit the modifications from a staging area to your local repository. Add a message with git commit to inform other contributors what has been modified on the repository.
git commit -m "message"
  1. Git push: Push the commited modifications to the remote repository. This will update the github repository with the modifications you’ve made on your local repository.
git push

If there are many contributors on your projects, you can also create branches to facilitate collaborative development. Branches create seperate versions of the main repository. Each contributor can create their own branch, work on their specific task, and later merge their changes back into the main branch.

git branch <name_branch> # create a branch
git merge main # merge modifications from remote branch to the main repository

Additional ressources:


Demo 4: Github actions + Package publishing ♻️

Github actions can be triggered by many types of git commands. We used git push in the demo. Everytime a contributor pushes new code onto the remote repository, github actions will build and test the package on different operating systems.

1. Create an account on PyPi

PyPi is a repository of software for the Python programming language.

https://pypi.org/

2. Install twine

Twine allows you to publish Python packages to PyPI and other repositories.

pip install twine

3. Publish your package to PyPi with twine

twine upload dist/*

The package’s will be published using the information in the setup.cfg file under [metadata]. In this demo, we published a package named lowrankdensity_demo in it’s 0.0.2 version.

Additional ressources:

git-demo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lowrankdensity_demo_bis-0.0.3.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lowrankdensity_demo_bis-0.0.3-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file lowrankdensity_demo_bis-0.0.3.tar.gz.

File metadata

  • Download URL: lowrankdensity_demo_bis-0.0.3.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for lowrankdensity_demo_bis-0.0.3.tar.gz
Algorithm Hash digest
SHA256 5c5c25f3ae1f0c8569d2e09727ae502562df3526ee4b894c5ef974391457090f
MD5 dac987c720196aceb5823481dff8f2cf
BLAKE2b-256 b78f7eabcbb1aefced8b556380514fd895bac0d7a35cc073e1f44221f4ade054

See more details on using hashes here.

File details

Details for the file lowrankdensity_demo_bis-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for lowrankdensity_demo_bis-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f41de153a23589a33a9152b4be02f2b043ef6869f2d61cfe9302c6c57cbfbff1
MD5 d407efdc3f319fbe5ea0b7a6a843a873
BLAKE2b-256 25cf67a60865625c41f0eff3fcda4bc2cfd675dcbc0c4d08ed7919615ee0a62a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page