Skip to content
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
24 changes: 14 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@ name: "Testing"

on:
push:
paths-ignore:
- 'tutorials/**'
- 'README.md'
- '.gitignore'
- 'examples/**'
branches:
- main
pull_request:
Copy link
Collaborator Author

@dpaiton dpaiton Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will now run the tests after the PR was merged, which is a good failsafe for the production branch (main)


jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python all python version
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.11
architecture: x64

- name: Install dependencies
run: pip install -r requirements.txt
run: |
python -m venv --upgrade-deps .venv
source .venv/bin/activate
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using a venv here to emulate how we suggest people set up in the README.

pip install -r requirements.txt
pip install -r requirements-dev.txt

- name: Run Test
run: python -m unittest discover tests -v
run: |
source .venv/bin/activate
python -m pytest .
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# OS specific
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -130,3 +133,4 @@ dmypy.json

# data
raw_data
data
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this because that is where the tutorial and example notebooks often look. We could also rename all of those hardcoded paths to "raw_data" and not add a "data" field here.

30 changes: 30 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest
import torch

from sparsecoding.test_utils import (
bars_datas_fixture,
bars_datasets_fixture,
bars_dictionary_fixture,
dataset_size_fixture,
patch_size_fixture,
priors_fixture,
)


@pytest.fixture(autouse=True)
def set_seed():
torch.manual_seed(1997)


# We import and define all fixtures in this file.
# This allows users to avoid any dependency fixtures.
# NOTE: This means pytest should only be run from this directory.
__all__ = [
"bars_datas_fixture",
"bars_datasets_fixture",
"bars_dictionary_fixture",
"dataset_size_fixture",
"patch_size_fixture",
"priors_fixture",
"set_seed",
]
32 changes: 19 additions & 13 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
# Contributing

All contributions are welcome!

## Bug Reporting
If you find a bug, submit a bug report on GitHub Issues.

If you find a bug, submit a bug report on GitHub Issues.

## Adding Features/Fixing Bugs

If you have identified a new feature or bug that you can fix yourself, please follow the following procedure.

1. Clone `main` branch.
2. Create a new branch to contain your changes.
2. `add`, `commit`, and `push` your changes to this branch.
3. Create a pull request (PR). See more information on submitting a PR request below.
1. Fork `main` branch.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cloning does not work because outside people do not have write permission. One has to fork to contribute, which is standard practice for open-source repos.

2. Create a new branch to contain your changes.
3. `add`, `commit`, and `push` your changes to this branch.
4. Create a pull request (PR). See more information on submitting a PR request below.

### Submitting a Pull Request
1. If necessary, please **write your own unit tests** and add them to [the tests directory](https://github.com/rctn/sparsecoding/blob/main/docs/contributing.md).
2. Verify that all tests are passed by running `python -m unittest tests/*`.
3. Be sure that your PR follows formatting guidelines, [PEP8](https://peps.python.org/pep-0008/) and [flake8](https://flake8.pycqa.org/en/latest/).
4. Make sure the title of your PR summarizes the features/issues resolved in your branch.
5. Submit your pull request and add reviewers.

1. If necessary, please **write your own unit tests** and place them near the code being tested. High-level tests, such as integration or example tests can be placed in the top-level "tests" folder.
2. Verify that all tests are passed by running `python -m pytest .`.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using pytest instead of unittest

3. Be sure that your PR follows formatting guidelines, [PEP8](https://peps.python.org/pep-0008/) and [flake8](https://flake8.pycqa.org/en/latest/).
4. Make sure the title of your PR summarizes the features/issues resolved in your branch.
5. Submit your pull request and add reviewers.

## Coding Style Guidelines
The following are some guidelines on how new code should be written. Of course, there are special cases, and there will be exceptions to these rules.

The following are some guidelines on how new code should be written. Of course, there are special cases, and there will be exceptions to these rules.

1. Format code in accordance with [flake8](https://flake8.pycqa.org/en/latest/) standard.
2. Use underscores to separate words in non-class names: `n_samples` rather than `nsamples`.
3. Avoid single-character variable names.

## Docstrings

When writing docstrings, please follow the following example.

```
```py
def count_beans(self, baz, use_gpu=False, foo="vector"
bar=None):
"""Write a one-line summary for the method.
Expand Down Expand Up @@ -69,4 +75,4 @@ def count_beans(self, baz, use_gpu=False, foo="vector"
quantum-mechanical description of physical reality be
considered complete?. Physical review, 47(10), 777.
"""
```
```
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pylint
pytest
pyright
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
python_requires='>=3.8',
)
Loading
Loading