Skip to content

ptrstn/python-starter

Repository files navigation

Python Package codecov Code style: black

python-starter

My personal python starter template. Intended for copy and paste use.

This project is released into the public domain, so feel free to modify and use it as you wish.

tl;dr

If you don't want to walk through the Usage chapter manually, just run this code block:

read -p "Enter the package name: " NEW_PACKAGE_NAME
read -p "Enter the project name [default: $NEW_PACKAGE_NAME]: " NEW_PROJECT_NAME
NEW_PROJECT_NAME=${NEW_PROJECT_NAME:-$NEW_PACKAGE_NAME}
read -p "Enter your GitHub username [default: ptrstn]: " YOUR_GH_USERNAME
YOUR_GH_USERNAME=${YOUR_GH_USERNAME:-ptrstn}
echo -e "\033[0;34mPackage name: $NEW_PACKAGE_NAME\033[0m"
echo -e "\033[0;34mProject name: $NEW_PROJECT_NAME\033[0m"
echo -e "\033[0;34mGitHub username: $YOUR_GH_USERNAME\033[0m"
echo -e "\033[0;34mCloning https://github.com/ptrstn/python-starter.git...\033[0m"
git clone https://github.com/ptrstn/python-starter.git tmp
rm -rf tmp/.git
cp -r tmp/.coveragerc tmp/.flake8 tmp/.gitignore tmp/* .
cp -r tmp/.github .github
rm -rf tmp
mv src/packagename src/$NEW_PACKAGE_NAME
sed -i "s/packagename/$NEW_PACKAGE_NAME/g" pyproject.toml .coveragerc README.md "src/${NEW_PACKAGE_NAME}/__main__.py" tests/test_core.py
sed -i "s/python-starter/$NEW_PROJECT_NAME/g" README.md pyproject.toml
sed -i "s/ptrstn/$YOUR_GH_USERNAME/g" pyproject.toml README.md
sed -i '6,/^## Installation/d' README.md
echo -e '\033[0;32mDone!\033[0m'
echo -e 'Note: Don'"'"'t forget to update your preferred \033[0;34mLICENSE\033[0m'

Usage

Copy files into your new project

Copy all files from this repository into your personal project.

git clone https://github.com/ptrstn/python-starter.git tmp
rm -rf tmp/.git
cp -r tmp/.coveragerc tmp/.flake8 tmp/.gitignore tmp/* .
cp -r tmp/.github .github
rm -rf tmp

Note: If your project is not empty, it might overwrite your files.

Adjust package name

Replace all occurrences of packagename and python-starter with your package name.

You can do this for instance by first declaring a variable NEW_PROJECT_NAME and replacing <YOUR_PACKAGE_NAME> with your desired package/project name.

NEW_PACKAGE_NAME=<YOUR_PACKAGE_NAME>
NEW_PROJECT_NAME=<YOUR_PACKAGE_NAME>

You can then use this variable to rename all occurrences in the template with your desired package/project name.

mv src/packagename src/$NEW_PACKAGE_NAME
sed -i "s/packagename/$NEW_PACKAGE_NAME/g" pyproject.toml .coveragerc README.md "src/${NEW_PACKAGE_NAME}/__main__.py" tests/test_core.py
sed -i "s/python-starter/$NEW_PROJECT_NAME/g" README.md pyproject.toml

Adjust GitHub Username

If your username is not ptrstn then you can first setup a new variable:

YOUR_GH_USERNAME=<YOUR_GITHUB_USERNAME>

Then you can replace it with the following command:

sed -i "s/ptrstn/$YOUR_GH_USERNAME/g" pyproject.toml README.md

Adjust license

Replace the LICENSE file to whatever you want to use. I would suggest the MIT license.

Adjust author

Also replace the author name in pyproject.toml with your name.

Adjust README.md

Adapt README.md, especially the installation instructions, according to your project.

In particular, delete all the text up until ## Installationc

sed -i '6,/^## Installation/d' README.md

Installation

pip install --user git+https://github.com/ptrstn/python-starter

Usage

packagename

Development

git clone https://github.com/ptrstn/python-starter
cd python-starter
python -m venv .venv
. .venv/bin/activate
pip install -e .[test]

Testing

pytest

About

My personal python starter template

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages