Introduction
If you followed my prevous post here, you remember that I had put up the tree structure of our codebase as seen below:
bank_creator/
├── bank_creator/
│ ├── __init__.py
│ ├── bank.py
│ ├── branch.py
│ ├── account.py
│ ├── loan.py
│ ├── utilities.py
│ ├── decorators.py
│ ├── database.py
├── tests/
│ ├── __init__.py
│ ├── test_bank.py
│ ├── test_branch.py
│ ├── test_account.py
│ ├── test_loan.py
│ ├── test_utilities.py
├── README.md
├── LICENSE
├── setup.py
Well, that is exactly the code I have written, and since we are not discussing the contents of the code, I will skip that, and simply focus on getting the code base ready for pushing it to GitHub, and later to the PyPi repositories.
Create a Github repository
First, make sure you have a github account. If you don't, perhaps its time you created one, at github.com. Head over to your account, and look at the top right, find the new link and click it to start creating the repository as seen in the screenshot below, just be sure to use a different name from the one am using for your repository🤦♀️🤦♀️
Follow instruction, and enter the name of the repository. You may make it private or public. I have made mine public because I want to make it open for contribution and improvement by the community, as well as allow people to download it. Here is what you will have once you create it:
Preparing and Uploading the code to git repository
Create a .gitignore file in your project root
Before uploading your code to github repository, you need to create a .gitignore file in the root directory of your project that will make sure you are not uploading dependencies in the virtual environment from your local machine. We are going to have all the dependencies already added in the requirements.txt.
Here is a short version of the .gitignore file that you may create:
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# Pyenv specific files
# Pyenv virtualenv specific files
# Virtualenv specific files
# Pipfile specific files
pipfile.lock
pipfile
.env
.venv
.pyvenv
venv/
venv.bak/
ENV/
.env/
.env.bak/
venv/
.venv/
# tox
.tox/
.cache/
# virtualenv
env/
venv/
ENV/
.env/
.venv/
# Spyder project settings
.spyderproject
# Rope project settings
.ropeproject
# pyright
# Pyright specific files
.pyrightconfig.json
# Pycharm specific files
.idea/
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
Now, follow this to initialize git in your codebase. Remember, you need to have the repository already created on github.com as we need that to push all our codebase.
(venv) D:\BANK_CREATOR_PYTHON_PACKAGE>code .
(venv) D:\BANK_CREATOR_PYTHON_PACKAGE>git init
Initialized empty Git repository in D:/BANK_CREATOR_PYTHON_PACKAGE/.git/
(venv) D:\BANK_CREATOR_PYTHON_PACKAGE>git add .
(venv) D:\BANK_CREATOR_PYTHON_PACKAGE>git commit -m "initial commit "
[master (root-commit) a9675a4] initial commit
13 files changed, 431 insertions(+)
create mode 100644 .gitignore
create mode 100644 bank_creator/bank_creator/README.md
create mode 100644 bank_creator/bank_creator/USAGE.md
create mode 100644 bank_creator/bank_creator/account.py
create mode 100644 bank_creator/bank_creator/bank.py
create mode 100644 bank_creator/bank_creator/decorators.py
create mode 100644 bank_creator/bank_creator/enhanced_bank.py
create mode 100644 bank_creator/bank_creator/loan.py
create mode 100644 bank_creator/bank_creator/main.py
create mode 100644 bank_creator/bank_creator/requirements.txt
create mode 100644 bank_creator/bank_creator/reward.py
create mode 100644 bank_creator/bank_creator/setup.py
create mode 100644 bank_creator/bank_creator/utilities.py
(venv) D:\BANK_CREATOR_PYTHON_PACKAGE>git branch -M main
(venv) D:\BANK_CREATOR_PYTHON_PACKAGE>git remote add origin git@github.com:winstonmhango23/bank_creator.git
(venv) D:\BANK_CREATOR_PYTHON_PACKAGE>git push -u origin main
Enumerating objects: 16, done.
Counting objects: 100% (16/16), done.
Delta compression using up to 8 threads
Compressing objects: 100% (14/14), done.
Writing objects: 100% (16/16), 5.63 KiB | 262.00 KiB/s, done.
Total 16 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To github.com:winstonmhango23/bank_creator.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.
(venv) D:\BANK_CREATOR_PYTHON_PACKAGE>
After running those commands, you should have your code uploaded to the github repository and looking like this in the screenshot below
Summary
In this post, we have looked at how to create a git repository for our project and managed to upload the code for our Python package to the git hub. In our next post, we will look at preparing to create an account at pypi.org and upload our package to it.