What are we going to do?
How are we going to do it?
Some topics to help define requirements include:
Warning: Each person involved in the project may have a different need.
What is the software architecture?
When designing software, the object-oriented approach is a common programming paradigm.
Object-oriented components:
Some principles: abstraction, encapsulation, decomposition, generalisation
Is this where the fun begins?
Take your time
Development is usually the most time consuming step in a Software Development Life Cycle.
Is this software good?
In this step, errors and failures are identified by exposing the code to an environment similar to the end-user experience.
There are several types of testing, some examples include:
Can other people use my code?
You can use platforms like GitHub to release your software.
Is it over?
We can classify maintenance into a few categories:
# The most basic structure for a code project should look like:
my-model
├── README.md
├── requirements.txt
├── src <- Source code for this project
└── tests <- Test code for this project
freecodecamp
post.environment.yml
, pyproject.toml
, setup.py
.Template based on mkrapp/cookiecutter-reproducible-science github
.
├── AUTHORS.md
├── LICENSE
├── README.md
├── bin <- Your compiled model code can be stored here (not tracked by git)
├── config <- Configuration files, e.g., for doxygen or for your model if needed
├── data
│ ├── external <- Data from third party sources.
│ ├── interim <- Intermediate data that has been transformed.
│ ├── processed <- The final, canonical data sets for modeling.
│ └── raw <- The original, immutable data dump.
├── docs <- Documentation, e.g., doxygen or scientific papers (not tracked by git)
├── notebooks <- Ipython or R notebooks
├── reports <- For a manuscript source, e.g., LaTeX, Markdown, etc., or any project reports
│ └── figures <- Figures for the manuscript or reports
├── src <- Source code for this project
│ ├── data <- scripts and programs to process data
│ ├── external <- Any external source code, e.g., pull other git projects, or external libraries
│ ├── models <- Source code for your own model
│ ├── tools <- Any helper scripts go here
│ └── visualization <- Scripts for visualisation of your results, e.g., matplotlib, ggplot2 related.
└── tests <- Test code for this project
If application A needs version 1.0 of a particular module but application B needs version 2.0, then the requirements are in conflict and installing either version 1.0 or 2.0 will leave one application unable to run.
The solution for this problem is to create a virtual environment, a self-contained directory tree that contains installation for particular versions of software/packages.
If your language or project has a standard policy, use that. For example:
Linters are automated tools which enforce coding conventions and check for common mistakes. For example:
$ conda install flake8
$ flake8 myscript.py
myscript.py:2:6: E201 whitespace after '{'
myscript.py:2:11: E231 missing whitespace after ':'
myscript.py:2:14: E231 missing whitespace after ','
myscript.py:2:18: E231 missing whitespace after ':'
myscript.py:3:1: E128 continuation line under-indented for visual indent
myscript.py:3:4: E231 missing whitespace after ':'
myscript.py:4:13: E225 missing whitespace around operator
myscript.py:4:14: E222 multiple spaces after operator
myscript.py:5:1: E302 expected 2 blank lines, found 0
myscript.py:5:13: E201 whitespace after '('
myscript.py:5:25: E202 whitespace before ')'
myscript.py:6:4: E111 indentation is not a multiple of 4
myscript.py:6:9: E211 whitespace before '('
myscript.py:6:20: E202 whitespace before ')'
myscript.py:7:8: E111 indentation is not a multiple of 4
myscript.py:7:14: E271 multiple spaces after keyword
myscript.py:7:25: E225 missing whitespace around operator
myscript.py:8:4: E301 expected 1 blank line, found 0
myscript.py:8:4: E111 indentation is not a multiple of 4
myscript.py:8:17: E203 whitespace before ':'
myscript.py:8:18: E231 missing whitespace after ':'
myscript.py:9:8: E128 continuation line under-indented for visual indent
myscript.py:9:9: E203 whitespace before ':'
myscript.py:9:15: E252 missing whitespace around parameter equals
myscript.py:9:16: E252 missing whitespace around parameter equals
myscript.py:10:8: E124 closing bracket does not match visual indentation
myscript.py:10:8: E125 continuation line with same indent as next logical line
myscript.py:11:8: E111 indentation is not a multiple of 4
myscript.py:12:1: E302 expected 2 blank lines, found 0
myscript.py:12:6: E211 whitespace before '('
myscript.py:12:9: E201 whitespace after '('
myscript.py:12:13: E202 whitespace before ')'
myscript.py:12:15: E203 whitespace before ':'
myscript.py:13:4: E111 indentation is not a multiple of 4
myscript.py:13:10: E271 multiple spaces after keyword
myscript.py:13:26: E203 whitespace before ':'
myscript.py:13:34: W291 trailing whitespace
Install and run Black
Check the file!
Using an Integrated development environment (IDE) will certainly save you time, but the advantages of using an IDE go beyond that. Below are some IDE advantages
To install VS Code follow the instructions here.
Configure VSC to use Black: Code (or File) > Preferences > Settings
python formatting provider
and choose black
format on save
and check the box to enableSelect interpreter: View > Command Palette..
(or Ctrl+Shift+P
)
Python: Select Interpreter
Now the Black package is going to fix your codes layout every time you save a code file.
Example, suppose we need to find the result of a number divided by another number:
This clearly works — after all, thousands of scientists are doing it right now — but there’s a better way
a_div_b
function that should pass those tests.a_div_b
produces any wrong answers, fix it and re-run the test functions.Writing the tests before writing the function they exercise is called test-driven development (TDD). Its advocates believe it produces better code faster because:
a_div_b
exampleLet’s think in all possible scenarios for this problem and how we could test them.
4
and 2
, the answer should be 2
.larger
than 1
.2
and 4
, the answer should be 0.5
.smaller
than 1
.Calculating the hypotenuse
\[ c = \sqrt{a^2 + b^2} \]
General Design
test_
)autoDocstring - Python Docstring Generator on VS Code
)sphinx
$ sphinx-quickstart docs
$ sphinx-apidoc -o docs .
'sphinx.ext.todo', 'sphinx.ext.viewcode', 'sphinx.ext.autodoc'
.sphinx_rtd_theme
src
(change the folder name as necessary!) folder as path:Add extra files after Contents
.. toctree::
:maxdepth: 2
:caption: Contents:
dependencies
usage
functions
List all your dependencies:
Dependencies
============
- python
- pytest
- flake8
- black
- sphinx
Explain how to use your software
Usage Guide
============
To start working with this repository you need to clone it onto your local
machine: ::
$ git clone https://github.com/...
Next ...
Create a function file with the following:
API reference
=============
.. automodule:: calc
:members:
:undoc-members:
:show-inheritance:
Create a new GH action to create a nice website for your documentation.
write
gh-pages
branch to activate your websiteCreate a setup.py
file like:
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="hypot",
version="0.1.0",
author="Patricia Ternes",
author_email="p.ternesdallagnollo@leeds.ac.uk",
description="The hypot SWD3 demo package",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3.9",
"Intended Audience :: Science/Research/Learning",
],
python_requires=">=3.9",
)
Install: install the hypot package into the environment using:
Usage: if you want to create a personalised script, you can import the hypot modules as follows:
Remove: If you want to remove your package, use pip:
Release in GitHub are based in tags with the following structure:
v0.5.2
Change | Release | Example |
---|---|---|
Major | Breaking | 0 |
Minor | Feature | 5 |
Patch | Fix | 2 |