Skip to content

Commit

Permalink
Add pre-commit hooks with black code formatting (ARM-DOE#419)
Browse files Browse the repository at this point in the history
* use black for formatting

* add pre-commit to deps

* add pre-commit to dev req

* update contributing docs
  • Loading branch information
mgrover1 authored Mar 15, 2022
1 parent a016bc7 commit 611aacb
Show file tree
Hide file tree
Showing 105 changed files with 6,425 additions and 4,200 deletions.
35 changes: 35 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-json
- id: check-yaml
- id: double-quote-string-fixer
- id: debug-statements
- id: mixed-line-ending

- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
hooks:
- id: pyupgrade
args:
- '--py38-plus'

- repo: https://github.com/psf/black
rev: 22.1.0
hooks:
- id: black
- id: black-jupyter

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
101 changes: 50 additions & 51 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ to `act`.

4. Create or modified code so that it produces doc string and follows standards.

5. PEP8 check using `flake8 <https://pypi.org/project/flake8/>`_. The command we
use in testing is flake8 --max-line-length=115 --ignore=F401,E402,W504,W605
5. Install your `pre-commit <https://pre-commit.com>` hooks, by using `pre-commit install`

6. Local unit testing using Pytest.

Expand Down Expand Up @@ -129,7 +128,7 @@ To delete a branch both locally and remotely, if done with it::
git branch -d <branch_name>

or in this case::

git push origin --delete wind_rose_plot
git branch -d wind_rose_plot

Expand Down Expand Up @@ -176,13 +175,13 @@ For example:

.. code-block:: python
import glob
import os
import numpy as np
import numpy.ma as ma
import glob
import os
import numpy as np
import numpy.ma as ma
from .dataset import ACTAccessor
from .dataset import ACTAccessor
Following the main function def line, but before the code within it, a doc
string is needed to explain arguments, returns, references if needed, and
Expand All @@ -197,38 +196,38 @@ An example:

.. code-block:: python
def read_netcdf(filenames, variables=None):
def read_netcdf(filenames, variables=None):
"""
Returns `xarray.Dataset` with stored data and metadata from a
user-defined query of standard netCDF files from a single
datastream.
"""
Returns `xarray.Dataset` with stored data and metadata from a
user-defined query of standard netCDF files from a single
datastream.
Parameters
----------
filenames : str or list
Name of file(s) to read
variables : list, optional
List of variable name(s) to read
Parameters
----------
filenames : str or list
Name of file(s) to read
variables : list, optional
List of variable name(s) to read
Returns
-------
act_obj : Object
ACT dataset
Returns
-------
act_obj : Object
ACT dataset
Examples
--------
This example will load the example sounding data used for unit
testing.
Examples
--------
This example will load the example sounding data used for unit
testing.
.. code-block:: python
.. code-block:: python
import act
import act
the_ds, the_flag = act.io.armfiles.read_netcdf(
act.tests.sample_files.EXAMPLE_SONDE_WILDCARD)
print(the_ds.act.datastream)
"""
the_ds, the_flag = act.io.armfiles.read_netcdf(
act.tests.sample_files.EXAMPLE_SONDE_WILDCARD)
print(the_ds.act.datastream)
"""
As seen, each argument has what type of object it is, an explanation of
what it is, mention of units, and if an argument has a default value, a
Expand All @@ -240,8 +239,8 @@ An example:

.. code-block:: python
def _get_value(self):
""" Gets a value that is used in a public function. """
def _get_value(self):
"""Gets a value that is used in a public function."""
Code Style
----------
Expand Down Expand Up @@ -269,7 +268,7 @@ To install pylint::

To use pylint::

pylint path/to/code/to/check.py
pylint path/to/code/to/check.py

Both of these tools are highly configurable to suit a user's taste. Refer to
the tools documentation for details on this process.
Expand All @@ -294,21 +293,21 @@ An example:

.. code-block:: python
import act
import numpy as np
import xarray as xr
import act
import numpy as np
import xarray as xr
def test_correct_ceil():
# Make a fake dataset to test with, just an array with 1e-7
# for half of it.
fake_data = 10 * np.ones((300, 20))
fake_data[:, 10:] = -1
arm_obj = {}
arm_obj['backscatter'] = xr.DataArray(fake_data)
arm_obj = act.corrections.ceil.correct_ceil(arm_obj)
assert np.all(arm_obj['backscatter'].data[:, 10:] == -7)
assert np.all(arm_obj['backscatter'].data[:, 1:10] == 1)
def test_correct_ceil():
# Make a fake dataset to test with, just an array with 1e-7
# for half of it.
fake_data = 10 * np.ones((300, 20))
fake_data[:, 10:] = -1
arm_obj = {}
arm_obj["backscatter"] = xr.DataArray(fake_data)
arm_obj = act.corrections.ceil.correct_ceil(arm_obj)
assert np.all(arm_obj["backscatter"].data[:, 10:] == -7)
assert np.all(arm_obj["backscatter"].data[:, 1:10] == 1)
Pytest is used to run unit tests in ACT.

Expand Down Expand Up @@ -344,7 +343,7 @@ filename is the filename and location, such as::
pytest /home/user/act/act/tests/test_correct.py

Relative paths can also be used::

cd ACT
pytest ./act/tests/test_correct.py

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Copyright © 2019, UChicago Argonne, LLC
All Rights Reserved
Software Name: Atmospheric data Community Toolkit (ACT)
By: Argonne National Laboratory, University of Oklahoma, and
By: Argonne National Laboratory, University of Oklahoma, and
Oak Ridge National Laboratory
OPEN SOURCE LICENSE

Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ When installing with pip, the ACT dependencies found in
pip install act-atmos

The easiest method for installing ACT is to use the conda packages from
the latest release. To do this you must download and install
`Anaconda <https://www.anaconda.com/download/#>`_ or
the latest release. To do this you must download and install
`Anaconda <https://www.anaconda.com/download/#>`_ or
`Miniconda <https://conda.io/miniconda.html>`_.
With Anaconda or Miniconda install, it is recommended to create a new conda
environment when using ACT or even other packages. To create a new
Expand All @@ -117,7 +117,7 @@ To update an older version of ACT to the latest release use::
conda update -c conda-forge act-atmos

If you do not wish to use Anaconda or Miniconda as a Python environment or want
to use the latest, unreleased version of ACT see the section below on
to use the latest, unreleased version of ACT see the section below on
**Installing from source**.

Installing from Source
Expand Down Expand Up @@ -148,7 +148,7 @@ ACT is an open source, community software project. Contributions to the
package are welcomed from all users.

The latest source code can be obtained with the command::

git clone https://github.com/ARM-DOE/ACT.git

If you are planning on making changes that you would like included in ACT,
Expand Down
16 changes: 5 additions & 11 deletions act/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
"""

from . import io
from . import plotting
from . import corrections
from . import utils
from . import tests
from . import discovery
from . import retrievals
from . import qc
from ._version import get_versions

# No more pandas warnings
from pandas.plotting import register_matplotlib_converters

from . import corrections, discovery, io, plotting, qc, retrievals, tests, utils
from ._version import get_versions

register_matplotlib_converters()

# Version for source builds
vdict = get_versions()
__version__ = vdict["version"]
__version__ = vdict['version']
Loading

0 comments on commit 611aacb

Please sign in to comment.