Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds more documentation and guidelines. #6

Merged
merged 10 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# .coveragerc to control code coverage tool
# https://coverage.readthedocs.io/en/latest/config.html

[run]
# Path where source is stored
source = wxflow/

# Omit some source code patterns when computing code coverage
omit =
setup.py

# whether to measure branch coverage in addition to statement coverage.
# https://coverage.readthedocs.io/en/latest/branch.html#branch
branch = True

[report]
# number of digits after the decimal point to display for reported coverage percentages
precision = 2

# when running a summary report in terminal, show missing lines
# show_missing = True

# don’t report files that are 100% covered. This helps you focus on files that need attention.
# skip_covered = True

# don’t report files that have no executable code (such as __init__.py files)
skip_empty = True

[html]
# where to write the HTML report files
directory = htmlcov

# To view the dynamic context (cf. above) in HTML report
show_contexts = True

[xml]
# where to write the XML report
output = coverage.xml
6 changes: 6 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[flake8]
exclude = .git,.github,venv,__pycache__,docs/conf.py,old,build,dist
max-line-length = 160
per-file-ignores =
# imported but unused
__init__.py: F401
3 changes: 3 additions & 0 deletions .github/workflows/pytests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ jobs:
run: |
cd $GITHUB_WORKSPACE
pytest -v

- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v1
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos:
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
language_version: python3
2 changes: 1 addition & 1 deletion .pycodestyle
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
count = False
max-line-length = 160
statistics = True
exclude = .git,.github
exclude = .git,.github,venv,.vscode,docs/conf.py
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[![pynorms](https://github.com/NOAA-EMC/wxflow/actions/workflows/pynorms.yaml/badge.svg)](https://github.com/NOAA-EMC/wxflow/actions/workflows/pynorms.yaml)
[![pytests](https://github.com/NOAA-EMC/wxflow/actions/workflows/pytests.yaml/badge.svg)](https://github.com/NOAA-EMC/wxflow/actions/workflows/pytests.yaml)
[![Documentation Status](https://readthedocs.org/projects/wxflow/badge/?version=latest)](https://wxflow.readthedocs.io/en/latest/?badge=latest)
[![codecov](https://codecov.io/gh/noaa-emc/wxflow/branch/develop/graph/badge.svg?token=JWTPE8Z7MH)](https://codecov.io/gh/noaa-emc/wxflow)

# Tools for Weather Workflows

Expand Down
120 changes: 109 additions & 11 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,130 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import datetime
import os
import sys
sys.path.insert(0, os.path.abspath('.'))
from typing import Any, Dict

project = 'wxflow'
copyright = '2023, NOAA/NWS/NCEP/EMC'
author = 'NOAA/NWS/NCEP/EMC'
import wxflow

sys.path.insert(0, os.path.abspath("."))

current_year = datetime.datetime.now().year

# General information about the project.
project = "wxflow"
copyright = "2023-{}, NOAA/NWS/NCEP/EMC".format(current_year)
author = "NOAA/NWS/NCEP/EMC"
version = wxflow.__version__
release = wxflow.__version__

# The language for content autogenerated by Sphinx. Refer to documentation for
# a list of supported languages.
language = "en"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"sphinx.ext.napoleon",
"sphinx.ext.autodoc",
"sphinx.ext.viewcode"
"sphinx.ext.extlinks",
"sphinx.ext.viewcode",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx_copybutton",
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# -- Options for extlinks ----------------------------------------------------
#

extlinks = {
"pypi": ("https://pypi.org/project/%s/", "%s"),
}

# -- Options for intersphinx -------------------------------------------------
#

intersphinx_mapping = {"python": ("https://docs.python.org/3/", None)}

# -- Options for TODOs -------------------------------------------------------
#

todo_include_todos = True

napoleon_google_docstring = False
napoleon_use_param = False
napoleon_use_ivar = True

templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The suffix of source filenames.
source_suffix = ".rst"

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"
pygments_dark_style = "monokai"

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []

# The encoding of source files.
source_encoding = "utf-8"

# The master toctree document.
master_doc = "index"

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_rtd_theme'
html_theme_path = ["_themes", ]
html_static_path = ['_static']
# on_rtd is whether we are on readthedocs.org
on_rtd = os.environ.get("READTHEDOCS", None) == "True"

try:
import furo

html_theme = "furo"
html_theme_options: Dict[str, Any] = {
"navigation_with_keys": True,
"source_repository": "https://github.com/NOAA-EMC/wxflow",
"source_branch": "develop",
"source_directory": "docs/",
"footer_icons": [
{
"name": "GitHub",
"url": "https://github.com/NOAA-EMc/wxflow",
"html": """
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path>
</svg>
""",
"class": "",
},
],
}
except ImportError:
html_theme = "default"

show_cloud_banner = True

html_theme_path = [
"_themes",
]
html_static_path = ["_static"]

html_context = {
"display_github": True,
"github_user": "NOAA-EMC",
"github_repo": "wxflow",
"github_version": version,
"conf_py_path": "/docs/",
}

# Show documentation from class as well as __init__ docstring
autoclass_content = 'both'
autoclass_content = "both"
118 changes: 118 additions & 0 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
Contributing
============

We love contributions here in ``wxflow``! If you're looking for something to work on then check out our
`issue tracker <https://github.com/noaa-emc/wxflow/issues>`_ for open issues.

If you want to make a contribution to ``wxflow`` then please raise a
`Pull Request <https://github.com/noaa-emc/wxflow/pulls>`_ on GitHub.

To help speed up the review process please ensure the following:

- The PR addresses an open issue.
- All tests are passing locally with ``pytest``.
- The project passes linting with ``black`` and ``flake8``.
- If adding a new feature you also add documentation.

Developing
----------

To check out a local copy of the project you can `fork the project on GitHub <https://github.com/noaa-emc/wxflow/fork>`_
and then clone it locally.

.. code-block:: bash

$ git clone https://github.com/yourusername/wxflow
$ cd wxflow

This project uses ``isort`` to sort Python import definitions alphabetically, ``black`` to format code and ``flake8`` for linting. We also support ``pre-commit`` to ensure
these have been run. To configure your local environment please install these development dependencies and set up
the commit hooks.

.. code-block:: bash

$ pip install isort black flake8 pre-commit
$ pre-commit install

You can check that things are working correctly by calling pre-commit directly.

.. code-block:: bash

$ pre-commit run --all-files
isort......................................Passed
black......................................Passed
flake8.....................................Passed

These checks will be run automatically when you make a commit (if ``pre-commit`` has been installed).

Testing
-------

This project uses ``pytest`` to run tests and also to test docstring examples.

Install the test dependencies.

.. code-block:: bash

$ pip install .dev

Run the tests.

.. code-block:: bash

$ pytest
=== 3 passed in 0.13 seconds ===

If you are working on a new feature please add tests to ensure the feature works as expected. If you are working on
a bug fix then please add a test to ensure there is no regression.

Tests are stored in ``wxflow/tests`` and follow the pytest format.

.. code-block:: python

from datetime import datetime
from wxflow import to_datetime

def test_to_datetime():
assert to_datetime('20220314') == datetime(2022, 3, 14)

Making a Pull Request
---------------------

Once you've made your changes and are ready to make a Pull Request please ensure tests and linting pass locally before pushing to GitHub.
When making your Pull Request please include a short description of the changes, but more importantly why they are important. Perhaps by
writing a before and after paragraph with user examples.

Also consider how your title look when it appears in a changelog. Does it full describe the change to an outside user? For example
``Add support for checking supported datetime`` is a much better title than ``Fixes #56``.

.. code-block:: markdown

# Add support for validating a string can be transformed into a datetime object

Closes #56

**Changes**

This PR allows the inspection of strings to check if it can be transformed into a datetime object.

**Before**

If a user passed a random string to `is_supported_datetime` it would return `False`.

```python
>>> from wxflow import is_supported_datetime
>>> is_supported_datetime('2012 Jun 15, 12:23')
False
```

**After**

If a user passes a valid, supported datetime string, it will return true


```python
>>> from wxflow import is_supported_datetime
>>> is_supported_datetime('20120615T1223z')
True
```
Loading