This is a template for a Python project. It includes several template modules that can form the basis for any Python project.
These steps are based on Github account dcpetty with private e-mail address dcpetty@users.noreply.github.com and with this repository pythontemplate being copied into repository newpython. Change these to match your account and repository.
pythontemplate to repository newpython.main branch from Settings.git clone the repository into the parent directory of the newpython local branch.
git clone git@github.com:dcpetty/pythontemplate.git from the SSH tab of the <> Code button directly. Orβ¦git clone https://github.com/dcpetty/newpython.git from the HTTPS tab of the <> Code button and:
.git/config url of the newpython local branch as per https://gist.github.com/jexchan/2351996 as follows:
url = https://github.com/dcpetty/newpython.giturl = git@github.com:dcpetty/newpython.git~/.ssh/ contains the files (for example) id_rsa_dcp and id_rsa_dcp.pub and that ~/.ssh/config then contains the following:Host *
AddKeysToAgent yes
UseKeychain yes
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_dcp
ssh-agent. Use ssh-add -l to see which keys have been added. When generating an SSH key, I do not use a passphrase.
ssh-add -K ~/.ssh/id_rsa_dcp (for example) to add it to the Apple keychain one time. You can add ssh-add -A 2>/dev/null to your Z-Shell resource file ~/.zshrc on Mac OS to initialize ssh-agent in each Z-Shell without needing the passphrase..git/config to associate commits with the correct account name:[user]
name = dcpetty
email = dcpetty@users.noreply.github.com
git) in ./src/.It is also possible to manage the .git/config url of the newpython local branch with a personal access token (PAT) in lieu of using SSH. This document describes the Github command-line interface in detail.
For this example, with a PAT of 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, the .git/config HTTPS url of the newpython local branch should be changed as follows:
url = https://github.com/dcpetty/newpython.giturl = https://dcpetty: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@github.com/dcpetty/newpython.gitNotes about PATs:
url that includes a PAT can be used to access any repo with you as the user without logging in. Keep them secure and do not give general access to .git/config files that include them.argparseargtemplate.py parses example command-line arguments with argparse. argparse allows for command-line argument types of required, optional, flagged, and flagged multiple. Any required and optional command-line arguments must be grouped together either before or after flagged, and flagged multiple command-line arguments which themselves must be grouped together.
Executing argtemplate.py -? from the command line shows:
usage: argtemplate.py [-?] [--version] [-a ARG] [-m MULT] [-v]
REQUIRED [OPTIONAL ...]
This is a template that includes argparse.ArgumentParser-style arguments in
all their various forms.
positional arguments:
REQUIRED required argument
OPTIONAL optional arguments (default: None)
optional arguments:
-?, --help show this help message and exit
--version show program's version number and exit
-a ARG, --arg ARG argument β multiples supersede (default: None)
-m MULT, --mult MULT multi-argument β multiples accumulate (default: None)
-v, --verbose echo status information (default: False)
log.pylog.py is a Logging module that logs to the console and a temporary log file.
classtemplate.pyclasstemplate.py is a template that demonstrates class and object properties and class and object methods.
.gitignoreThe following basic .gitignore prefix is a useful starting point (and includes .git/info/exclude). Add files generated by https://gitignore.io/ to that prefix β in this case those for c,c++,jekyll,java,python,r,git,latex,macos,intellij+all,pycharm+all,visualstudiocode.
######################################################################
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
*.[oa]
*~
# IDE files #
#############
*.bluej
*.drjava
*.gpj
*.eml
*.userlibraries
.project
.classpath
# IDE directories #
###################
.settings/
bin/
# User directories #
####################
.git/
.m2/
.gradle/
# Target build directories #
############################
target/
build/
out/
# Compiled source #
###################
*.com
# Packages #
############
*.7z
*.dmg
*.gz
*.iso
*.bz2
# Databases #
#############
*.sql
*.sqlite
π permalink and π© repository for this page.