Skip to content

Commit 76be40c

Browse files
Update README with motivation (#3)
1 parent c7497fa commit 76be40c

File tree

5 files changed

+83
-14
lines changed

5 files changed

+83
-14
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,13 @@ repos:
3737
- id: flake8
3838
args: ["--config=setup.cfg"]
3939
additional_dependencies: [flake8-isort]
40+
41+
# ===========================
42+
# Python static type checking
43+
# ===========================
44+
# NOTE: Uncomment for optional static type checking
45+
# - repo: https://github.com/pre-commit/mirrors-mypy
46+
# rev: v1.1.1
47+
# hooks:
48+
# - id: mypy
49+
# args: ["--config=pyproject.toml"]

README.rst

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@ Python Template Repo
22
====================
33

44
Python Template Repo aims to help you **quickly jumpstart new Python libraries with
5-
integrated developer tooling**. Try this template out if you intend on **distributing
6-
your Python library as an open-source Anaconda package** and **don't want to deal with
7-
the repository infrastructure**!
5+
integrated developer tooling to efficiently develop high quality and robust software.**
6+
If you want to focus on developing open-source software without dedicating significant
7+
time and effort on repo setup, try this template out!
88

99
Simply follow the "Getting Started" guides below. It is also easily configurable based
1010
on your library's needs.
1111

12+
Motivation
13+
----------
14+
15+
This template was driven from the desire to reduce the overhead in setting up and
16+
maintaining Python libraries that follow software engineering practices (e.g., code
17+
styling, unit testing, documentation). The target audience was originally developers
18+
from the E3SM Project and LLNL Climate Program, but it can be used by anyone in the
19+
open-source community!
20+
21+
The template is based on a common system design pattern integrated in `E3SM Project`_ post-processing tools (e3sm_diags, zppy, zstash, polaris), `xCDAT`_, and `PCMDI Metrics`_.
22+
23+
.. _`E3SM Project`: https://github.com/E3SM-Project
24+
.. _`xCDAT`: https://github.com/xCDAT/xcdat
25+
.. _`PCMDI Metrics`: https://github.com/PCMDI/pcmdi_metrics
26+
1227
Features
1328
--------
1429

@@ -83,7 +98,8 @@ The library's documentation is setup with `Sphinx`_ and `Read the Docs Sphinx Th
8398
You just need to do a few things to get up and running:
8499

85100
1. Update ``README.rst``, ``AUTHORS.rst``, ``HISTORY.rst``, and ``/docs/index.rst`` as needed
86-
2. Decide how to deploy the documentation. Follow the instructions in the provided links.
101+
2. Decide how to deploy the documentation. This step is left up to you based on your needs.
102+
Follow the instructions in the provided links.
87103

88104
- Option 1: `Read the Docs`_
89105
- Option 2: `GitHub Pages`_ (via GitHub Actions)
@@ -111,10 +127,9 @@ To build the documentation locally (useful for reviewing):
111127
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
112128

113129
This repository includes quality assurance (QA) tools for code formatting (``black``,
114-
``isort``), linting (``flake8``), and unit testing (``pytest``). These tools ensure
115-
that you can easily catch issues and follow good Python practices without sacrificing
116-
energy on them. These tools are integrated in the `pre-commit`_ package as "hooks" that
117-
automatically run when committing changes to files.
130+
``isort``), linting (``flake8``), unit testing (``pytest``), and optional static type
131+
checking (``mypy``). These tools ensure that you can easily catch issues and follow good
132+
Python practices without sacrificing energy on them. These tools are integrated in the `pre-commit`_ package as "hooks" that automatically run when committing changes to files.
118133

119134
To run these QA tools through ``pre-commit``:
120135

@@ -175,16 +190,49 @@ Information on QA tools:
175190
automatically separated into sections and by type.
176191
- `flake8`_ - A Python linter that checks Python code for style and syntax errors, and
177192
for enforcing a style guide with `PEP (Python Enhancement Proposals)`_.
193+
- `mypy`_ (enable in ``pre-commit-config.yaml``) - A static type checker for Python.
194+
"Type checkers help ensure that you’re using variables and functions in your code
195+
correctly. With mypy, add type hints (PEP 484) to your Python programs, and mypy will
196+
warn you when you use those types incorrectly."
178197

179198
.. _pre-commit: https://pre-commit.com/
180199
.. _black: https://black.readthedocs.io/en/stable/
181200
.. _isort: https://pycqa.github.io/isort/
182201
.. _flake8: https://flake8.pycqa.org/en/latest/
202+
.. _mypy: https://mypy.readthedocs.io/en/stable/
183203
.. _PEP (Python Enhancement Proposals): https://peps.python.org/pep-0000/
184204

205+
206+
5. Decide How to Distribute Software on Anaconda
207+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
208+
209+
There are several ways of distributing software on Anaconda including:
210+
211+
1. Using `conda-forge`_ (recommended)
212+
2. Managing your own `Anaconda channel`_ and uploading packages there
213+
214+
I recommend using `conda-forge`. "conda-forge is a GitHub organization containing
215+
repositories of conda recipes. Thanks to some awesome continuous integration providers
216+
(AppVeyor, Azure Pipelines, CircleCI and TravisCI), each repository, also known as a
217+
feedstock, automatically builds its own recipe in a clean and repeatable way on Windows,
218+
Linux and OSX.""
219+
220+
.. _`conda-forge`: https://conda-forge.org/
221+
.. _`Anaconda channel`: https://docs.anaconda.com/navigator/tutorials/manage-channels/
222+
185223
Helpful Knowledge
186224
-----------------
187225

226+
Reminder to Routinely Maintain the Software Infrastructure
227+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
228+
229+
It is generally good practice to maintain your software infrastructure. Here is a
230+
routine software maintenance checklist. I recommend doing these before every new
231+
software version release.
232+
233+
1. Maintain conda environment dependencies in `.yml` files
234+
2. Update `pre-commit` hooks in `.pre-commit-config.yml`
235+
188236
How GitHub Actions is Used for CI/CD
189237
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190238

@@ -209,4 +257,6 @@ Additional Configuration
209257
- Feel free to modify the configuration for QA tools in ``pyproject.toml`` and ``setup.cfg``
210258
- You can also remove some or all the QA tools if you want (not recommended though).
211259
Just make sure to delete them from your Anaconda ``.yml`` files and remove their entries
212-
in ``pre-commit-config.yaml`` and their configs in ``pyproject.toml`` and/or ``setup.cfg``
260+
in ``pre-commit-config.yaml`` and their configs in ``pyproject.toml`` and/or ``setup.cfg``.
261+
- `mypy` is disabled by default with `pre-commit`. Enable `mypy` by uncommenting the
262+
lines related lines in ``pre-commit-config.yaml``.

conda-env/dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
# ==========================================
1515
# Quality Assurance - for linting and formatting
1616
# ==========================================
17-
# NOTE: If versions are updated, also update 'rev' in `.pre-commit.config.yaml`
17+
# NOTE: If versions are updated, also update 'rev' in `.pre-commit.config.yaml`
1818
- black=23.1.0
1919
- flake8=6.0.0
2020
- flake8-isort=6.0.0

pyproject.toml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# pyproject.toml is the latest adopted standard for configuring tools.
33

44
[tool.black]
5-
# Source: https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html
5+
# Docs: https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html
66
line-length = 88
77
target-version = ['py39']
88
include = '\.pyi?$'
@@ -27,14 +27,23 @@ exclude = '''
2727
'''
2828

2929
[tool.isort]
30-
# Source: https://pycqa.github.io/isort/docs/configuration/options.html#example-pyprojecttoml_4
30+
# Docs: https://pycqa.github.io/isort/docs/configuration/options.html#example-pyprojecttoml_4
3131
multi_line_output = 3
3232
include_trailing_comma = true
3333
force_grid_wrap = 0
3434
use_parentheses = true
3535
line_length = 88
3636

3737
[tool.pytest.ini_options]
38-
# Source: https://docs.pytest.org/en/7.2.x/reference/customize.html#configuration
38+
# Docs: https://docs.pytest.org/en/7.2.x/reference/customize.html#configuration
3939
junit_family = "xunit2"
4040
python_files = ["tests.py", "test_*.py"]
41+
42+
[tool.mypy]
43+
# Docs: https://mypy.readthedocs.io/en/stable/config_file.html
44+
python_version = 3.10
45+
check_untyped_defs = true
46+
ignore_missing_imports = true
47+
warn_unused_ignores = true
48+
warn_redundant_casts = true
49+
warn_unused_configs = true

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file is used for configuring flake8, which does not currently support pyproject.toml
22

33
[flake8]
4-
# Source: https://flake8.pycqa.org/en/latest/user/configuration.html
4+
# Docs: https://flake8.pycqa.org/en/latest/user/configuration.html
55
# Error codes: https://pep8.readthedocs.io/en/latest/intro.html#error-codes
66
ignore =
77
# whitespace before ‘:’

0 commit comments

Comments
 (0)