GithubHelp home page GithubHelp logo

jeanpimentel / python-lib Goto Github PK

View Code? Open in Web Editor NEW

This project forked from simonw/python-lib

0.0 1.0 0.0 21 KB

Opinionated cookiecutter template for creating a new Python library

License: Apache License 2.0

Python 100.00%

python-lib's Introduction

python-lib cookiecutter template

Opinionated cookiecutter template for creating a new Python library

Installation

You'll need to have cookiecutter installed. I recommend pipx for this:

pipx install cookiecutter

Regular pip will work OK too.

Usage

Run cookiecutter gh:simonw/python-lib and then answer the prompts. Here's an example run:

$ cookiecutter gh:simonw/python-lib
lib_name []: python lib template demo
description []: Demonstrating https://github.com/simonw/python-lib
hyphenated [python-lib-template-demo]: 
underscored [python_lib_template_demo]: 
github_username []: simonw
author_name []: Simon Willison

I strongly recommend accepting the suggested value for "hyphenated" and "underscored" by hitting enter on those prompts.

This will create a directory called python-lib-template-demo - the name you enter is converted to lowercase and uses hyphens instead of spaces.

See https://github.com/simonw/python-lib-template-demo for the output of this example.

Developing your library

Having created the new structure from the template, here's how to start working on the library.

If your library is called my-new-library, you can start working on it like so:

cd my-new-library
# Create and activate a virtual environment:
python3 -mvenv venv
source venv/bin/activate
# Install dependencies so you can edit the project:
pip install -e '.[test]'
# With zsh you have to run this again for some reason:
source venv/bin/activate

You can run the default test for your library like so:

pytest

This will execute the test in tests/test_my_new_library.py.

Creating a Git repository for your library

You can initialize a Git repository for your library like this:

cd my-new-library
git init
git add .
git commit -m "Initial structure from template"
# Rename the 'master' branch to 'main':
git branch -m master main

Publishing your library to GitHub

Use https://github.com/new to create a new GitHub repository sharing the same name as your library, which should be something like my-new-library.

Push your main branch to GitHub like this:

git remote add origin [email protected]:YOURNAME/my-new-library.git
git push -u origin main

The template will have created a GitHub Action which runs your library's test suite against every commit.

Publishing your library as a package to PyPI

The template also includes an Action for publishing packages to PyPI.

To use this action, you need to create a PyPI account and an API token against that account.

Once you have created your account, navigate to https://pypi.org/manage/account/token/ and create an API token. For initial publication of the package you will need to set the scope of the token to "Entire account (all projects)".

Add that token to your repository as a GitHub secret called PYPI_TOKEN. You can find this in the "Settings -> Secrets -> New Secret" area of the repository. The token should begin with the string pypi-.

Now, any time you create a new "Release" on GitHub the Action will build your package and push it to PyPI. The tag for the new release needs to match the VERSION string at the top of your setup.py file.

After the first release has gone out you can create a new PyPI API token that is scoped just to that project and use that to replace the PYPI_TOKEN secret in your GitHub repository settings.

python-lib's People

Contributors

simonw avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.