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

pre-commit hooks #92

Merged
merged 4 commits into from
Jun 18, 2020
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
130 changes: 83 additions & 47 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Contributing Guidelines
=======================
# Contributing Guidelines

First off, thanks for taking the time to contribute! :clap::+1::tada:

Expand All @@ -8,40 +7,75 @@ First off, thanks for taking the time to contribute! :clap::+1::tada:
[Contributing Code](#contributing-code)

[How Can I Contribute?](#how-can-i-contribute)
* [Reporting Bugs](#reporting-bugs)
* [Suggesting Enhancements](#suggesting-enhancements)
* [Submitting pull requests](#pull-requests)

- [Reporting Bugs](#reporting-bugs)
- [Suggesting Enhancements](#suggesting-enhancements)
- [Submitting pull requests](#pull-requests)

[Style guides](#style-guides)
* [git commit messages](#git-commit-messages)
* [documentation style guide](#documentation-style-guide)
* [python style guide](#python-style-guide)

### Contributing Code
- [git commit messages](#git-commit-messages)
- [documentation style guide](#documentation-style-guide)
- [python style guide](#python-style-guide)

1. Fork the KwanLab Autometa repository. You can do this [here](https://github.com/KwanLab/Autometa).
2. <details><summary>Add the KwanLab as the upstream remote.</summary><code>
git remote add upstream https://github.com/KwanLab/Autometa.git</code></details>
3. Update your local repository with the most recent updates from the Kwan Lab.
- <details><summary>Update your local repository.</summary><code>git pull upstream master</code></details>
- <details><summary>Push changes to update your remote repository.</summary><code>git push origin master</code></details>
4. <details><summary>Check out a branch corresponding to the feature you wish to add.</summary><code>git checkout -b your-new-feature master</code></details>
5. File an issue with the feature you plan on adding. This will open a channel of
communication with the core developers. See [suggesting enhancements](#suggesting-enhancements) for details.
6. Submit a pull request! To submit a pull request - see [instructions below](#pull-requests).
### Contributing Code

1. File an issue with the feature you plan on adding. This will open a channel of
communication with the core developers. See [suggesting enhancements](#suggesting-enhancements) for details.

2. <details>
<summary>Fork the KwanLab Autometa repository.</summary><summary> You can do this here: https://github.com/KwanLab/Autometa</summary>
<summary>Clone your fork.</summary><code>git clone https://github.com/YourUserName/Autometa.git</code>
<summary>Then navigate to the Autometa directory.</summary><code>cd Autometa</code>
</details>

3. <details>
<summary>Add the KwanLab as the upstream remote.</summary>
<code>git remote add upstream https://github.com/KwanLab/Autometa.git</code>
</details>

4. <details>
<summary>Check out a branch respective to the contribution you plan to make.</summary>
<summary>Check out the <code>hotfix</code> branch from <code>master</code> if fixing a bug.</summary><code>git checkout -b hotfix master</code>
<summary>If adding a feature, check out a branch corresponding to the feature you wish to add from <code>dev</code>.</summary>
<summary> First checkout dev</summary><code>git checkout dev</code>
<summary>Then checkout your feature</summary><code>git checkout -b your-new-feature dev</code>
</details>

5. <details>
<summary>Update your local repository with the most recent updates from the Kwan Lab.</summary>
<summary>Update the <code>master</code> branch if fixing a bug.</summary><code>git pull upstream master</code>
<summary>Otherwise update <code>your-new-feature</code> branch with <code>dev</code> and resolve any merge conflicts.</summary><code>git pull upstream dev</code>
<summary><b>Note: Whenver you return to the feature, make sure to pull from upstream to ensure you are working on the most up-to-date code.</b></summary>
<summary>Update your local repository with any changes from the Kwan Lab.</summary>
<code>git push origin master</code>
<br>
or
<br>
<code>git push origin dev</code>
<br>
<code>git push origin your-new-feature</code>
</details>

6. <details>
<summary>Ensure pre-commit hooks are installed.</summary>
<code>conda install -c conda-forge pre-commit</code>
<br>
<code>pre-commit install</code>
</details>

7. Submit a pull request! To submit a pull request - see [instructions below](#pull-requests).

## How can I contribute?

### Reporting Bugs

> **Note:** If you find a **Closed** issue that seems like it is the same thing
that you're experiencing, open a new issue and include a link to the original
issue in the body of your new one.
> that you're experiencing, open a new issue and include a link to the original
> issue in the body of your new one.

When submitting a bug report, please follow the bug report [template](https://github.com/KwanLab/Autometa/blob/master/.github/ISSUE_TEMPLATE/bug_report.md).


### Suggesting Enhancements

Feature requests may be submitted by creating a new issue. When creating this issue, please follow [this template](https://github.com/KwanLab/Autometa/blob/master/.github/ISSUE_TEMPLATE/feature_request.md). After your feature request has been submitted, a maintainer will respond with a determination of whether this feature is appropriate for Autometa. If a maintainer has not responded within a reasonable time period, you can notify the Autometa team. See [notifying the team](#notifying-the-team) for details.
Expand All @@ -58,9 +92,10 @@ Please follow these steps to have your contribution considered by the maintainer

1. Follow all instructions in respective [bug_fix](https://github.com/KwanLab/Autometa/blob/master/.github/PULL_REQUEST_TEMPLATE/bug_fix.md) or [feature_change](https://github.com/KwanLab/Autometa/blob/master/.github/PULL_REQUEST_TEMPLATE/feature_change.md) templates.
2. Follow the [style guides](#style-guides).
>Note: If writing a new file, a template.py file is provided within the autometa code base to help follow the structure requested by the Autometa team.
Please copy and rename this file before you start writing your feature.
The template file may be found [here](https://github.com/KwanLab/Autometa/blob/dev/docs/template.py), or you may find it within your cloned repository under 'Autometa/docs/template.py'

> Note: If writing a new file, a `template.py` file is provided within the autometa code base to help follow the structure requested by the Autometa team.
> Please copy and rename this file before you start writing your feature.
> The template file may be found [here](https://github.com/KwanLab/Autometa/blob/dev/docs/template.py), or you may find it within your cloned repository under 'Autometa/docs/template.py'

3. After you submit your pull request, verify that all [status checks](https://help.github.com/articles/about-status-checks/) are passing. <details><summary>What if the status checks are failing?</summary>If a status check is failing, and you believe that the failure is unrelated to your change, please leave a comment on the pull request explaining why you believe the failure is unrelated. A maintainer will re-run the status check for you. If we conclude that the failure was a false positive, then we will open an issue to track that problem with our status check suite.</details>

Expand All @@ -70,42 +105,43 @@ While the above must be satisfied, additional prerequisites may be present, depe

### Git Commit Messages

* Use the present tense ("Add feature" not "Added feature")
* Limit the first line to 72 characters or less
* Reference issues and pull requests liberally after the first line
* Consider starting the commit message with an applicable emoji:
* :art: `:art:` when improving the format/structure of the code
* :racehorse: `:racehorse:` when improving performance
* :memo: `:memo:` when writing docs
* :penguin: `:penguin:` when fixing something on Linux
* :apple: `:apple:` when fixing something on macOS
* :bug: `:bug:` when fixing a bug
* :fire: `:fire:` when removing code or files
* :green_heart: `:green_heart:` when fixing the CI build
* :white_check_mark: `:white_check_mark:` when adding tests
* :arrow_up: `:arrow_up:` when upgrading dependencies
* :arrow_down: `:arrow_down:` when downgrading dependencies
- Use the present tense ("Add feature" not "Added feature")
- Limit the first line to 72 characters or less
- Reference issues and pull requests liberally after the first line
- Consider starting the commit message with an applicable emoji:
- :art: `:art:` when improving the format/structure of the code
- :racehorse: `:racehorse:` when improving performance
- :memo: `:memo:` when writing docs
- :penguin: `:penguin:` when fixing something on Linux
- :apple: `:apple:` when fixing something on macOS
- :bug: `:bug:` when fixing a bug
- :fire: `:fire:` when removing code or files
- :green_heart: `:green_heart:` when fixing the CI build
- :white_check_mark: `:white_check_mark:` when adding tests
- :arrow_up: `:arrow_up:` when upgrading dependencies
- :arrow_down: `:arrow_down:` when downgrading dependencies

### Documentation Style Guide

Documentation is hosted on reathedocs.org which uses sphinx, a python documentation generator. Therefore a common syntax for
documenting files within the source code is required. The Autometa team follows numpy syntax to automate as much of the documentation build as possible.

* Numpy documentation [style guide](https://numpydoc.readthedocs.io/en/latest/format.html)
* Sphinx restructured text [style guide](http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#paragraphs)
- Numpy documentation [style guide](https://numpydoc.readthedocs.io/en/latest/format.html)
- Sphinx restructured text [style guide](http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#paragraphs)

### Python Style Guide

When in doubt, you may reference:

* google's python [style guide](https://github.com/google/styleguide/blob/gh-pages/pyguide.md)
* [PEP8](https://www.python.org/dev/peps/pep-0008/)
We have moved all development to using the [black](black.readthedocs.io) formatter and run
[pre-commit](https://pre-commit.com/) hooks with black such that all of the fuss with formatting according to code
specifications can be ignored! When first cloning the repository, you should first install
pre-commit and run `pre-commit install`. This will ensure any commits you make will be
formatted appropriately.

### Notifying the Team

You may notify the Autometa team corresponding to the respective update/bug by mentioning them in a comment within your issue or pull request.

>Note: Please only use <code>@KwanLab/autometa</code> if you receive no response from any of the other teams below.
> Note: Please only use <code>@KwanLab/autometa</code> if you receive no response from any of the other teams below.

| Team | Area of Development |
| -------------------------------------- | ----------------------------------------- |
Expand Down
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
exclude: "^autometa/validation"
default_language_version:
python: python3.7
repos:
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0 # Use the ref you want to point at
hooks:
- id: trailing-whitespace
- id: check-executables-have-shebangs
- id: end-of-file-fixer
- id: debug-statements
- id: check-merge-conflict
2 changes: 0 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ sphinx:

# Optionally build your docs in additional formats such as PDF and ePub
formats: all


2 changes: 1 addition & 1 deletion autometa.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@

from autometa.__main__ import entrypoint

if __name__ == '__main__':
if __name__ == "__main__":
entrypoint()
65 changes: 41 additions & 24 deletions autometa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from autometa.config.user import AutometaUser


logger = logging.getLogger('autometa')
logger = logging.getLogger("autometa")


def init_logger(fpath=None, verbosity=0):
Expand Down Expand Up @@ -73,15 +73,16 @@ def init_logger(fpath=None, verbosity=0):
}

if type(verbosity) is not int:
raise TypeError(f'{verbosity} must be an int! {type(verbosity)}')
raise TypeError(f"{verbosity} must be an int! {type(verbosity)}")
if verbosity and verbosity not in log_levels:
raise ValueError(f'{verbosity} not in log_levels: {log_levels}!')
raise ValueError(f"{verbosity} not in log_levels: {log_levels}!")

level = log_levels.get(verbosity)

formatter = logging.Formatter(
fmt='[%(asctime)s %(levelname)s] %(name)s: %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p')
fmt="[%(asctime)s %(levelname)s] %(name)s: %(message)s",
datefmt="%m/%d/%Y %I:%M:%S %p",
)
# Construct file/stream logging handlers
streamhandler = logging.StreamHandler()
streamhandler.setFormatter(formatter)
Expand All @@ -95,6 +96,7 @@ def init_logger(fpath=None, verbosity=0):
logger.setLevel(logging.DEBUG)
return logger


def main(args):
"""Main logic for running autometa pipeline.

Expand Down Expand Up @@ -126,6 +128,7 @@ def main(args):
# user.process_binning()
# user.get_pangenomes()


def entrypoint():
"""Main entrypoint for autometa pipeline.

Expand All @@ -139,43 +142,57 @@ def entrypoint():

"""
import argparse

# import time
cpus = mp.cpu_count()
parser = argparse.ArgumentParser(
description='Main script to run the Autometa pipeline.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('config',
help='Path to your metagenome.config file',
nargs='*')
parser.add_argument('--cpus',
help='Num. cpus to use when updating/constructing databases',
description="Main script to run the Autometa pipeline.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("config", help="Path to your metagenome.config file", nargs="*")
parser.add_argument(
"--cpus",
help="Num. cpus to use when updating/constructing databases",
type=int,
default=cpus)
default=cpus,
)
parser.add_argument(
'-v', '--verbose', dest='verbosity', action='count', default=0,
help='Verbosity (between 1-2 occurrences with more leading to more '
'verbose logging). WARN=0, INFO=1, DEBUG=2')
parser.add_argument('--log', help='Path to write a log file (e.g. </path/to/autometa.log>)', type=str)
parser.add_argument('--check-dependencies',
help='Check user executables and databases accessible to Autometa and exit.',
action='store_true')
"-v",
"--verbose",
dest="verbosity",
action="count",
default=0,
help="Verbosity (between 1-2 occurrences with more leading to more "
"verbose logging). WARN=0, INFO=1, DEBUG=2",
)
parser.add_argument(
"--log",
help="Path to write a log file (e.g. </path/to/autometa.log>)",
type=str,
)
parser.add_argument(
"--check-dependencies",
help="Check user executables and databases accessible to Autometa and exit.",
action="store_true",
)
args = parser.parse_args()

try:
main(args)
except KeyboardInterrupt:
logger.info('User cancelled run. Exiting...')
logger.info("User cancelled run. Exiting...")
sys.exit(1)
except Exception as err:
issue_request = '''
issue_request = """

Please help us fix your problem!

You may file an issue with us at https://github.com/KwanLab/Autometa/issues/new/choose
'''
"""
err.issue_request = issue_request
logger.exception(err)
logger.info(err.issue_request)

if __name__ == '__main__':

if __name__ == "__main__":
entrypoint()
Loading