Skip to content

Commit

Permalink
Initial setup (#1)
Browse files Browse the repository at this point in the history
PaulJWright authored Aug 3, 2024
1 parent 27353bf commit eebd8dc
Showing 9 changed files with 152 additions and 26 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
push:
branches:
- 'main'
- '*.*'
- '!*backport*'
- '*'
tags:
- 'v*'
- '!*dev*'
- '!*pre*'
- '!*post*'
pull_request:

jobs:
pre-commit:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files
43 changes: 43 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
repos:
# This should be before any formatting hooks like isort
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.265"
hooks:
- id: ruff
args: ["--fix"]

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
exclude: ".*(.fits|.fts|.fit|.txt|.csv)$"

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
exclude: ".*(.fits|.fts|.fit|.header|.txt|tca.*|extern.*|.rst|.md|cm/__init__.py|sunpy/extern|docs/conf.py)$"

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-ast
- id: check-case-conflict
- id: trailing-whitespace
exclude: ".*(.fits|.fts|.fit|.header|.txt)$"
- id: check-yaml
- id: debug-statements
- id: check-added-large-files
args: ["--enforce-all", "--maxkb=1054"]
- id: end-of-file-fixer
exclude: ".*(.fits|.fts|.fit|.header|.txt|tca.*|.json)$|^CITATION.rst$"
- id: mixed-line-ending
exclude: ".*(.fits|.fts|.fit|.header|.txt|tca.*)$"

- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: codespell
args: ["--config setup.cfg"]
ci:
autofix_prs: false
35 changes: 35 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
Overview
--------

To get started, you can install the package and use it as follows:

.. code:: bash
pip install -e .
Then you can import the utility functions in your Python script:

.. code:: python
import weird_salads
This codebase uses pre-commit etc.

.. code:: bash
pre-commit install
.. code:: bash
(weird_salads) ➜ mad_salads git:(feature/initial_setup) ✗ pre-commit run --all
ruff.....................................................................Passed
black....................................................................Passed
isort....................................................................Passed
check python ast.........................................................Passed
check for case conflicts.................................................Passed
trim trailing whitespace.................................................Passed
check yaml...............................................................Passed
debug statements (python)................................................Passed
check for added large files..............................................Passed
fix end of files.........................................................Passed
mixed line ending........................................................Passed
codespell................................................................Passed
License
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@
master_doc = "index"

# Treat everything in single ` as a Python reference.
default_role = 'py:obj'
default_role = "py:obj"

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

3 changes: 1 addition & 2 deletions weird_salads/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .example_mod import do_primes
from .version import version as __version__

# Then you can be explicit to control what ends up in the namespace,
__all__ = ['do_primes']
__all__ = ["do_primes"]
4 changes: 2 additions & 2 deletions weird_salads/_dev/scm_version.py
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@
try:
from setuptools_scm import get_version

version = get_version(root=os.path.join('..', '..'), relative_to=__file__)
version = get_version(root=os.path.join("..", ".."), relative_to=__file__)
except ImportError:
raise
except Exception as e:
raise ValueError('setuptools_scm can not determine version.') from e
raise ValueError("setuptools_scm can not determine version.") from e
48 changes: 31 additions & 17 deletions weird_salads/example_mod.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__all__ = ['primes', 'do_primes']
__all__ = ["primes", "do_primes"]


def primes(imax):
@@ -40,41 +40,55 @@ def primes(imax):

def do_primes(n, usecython=False):
if usecython:

raise Exception("This template does not have the example C code included.")

else:
print('Using pure python primes')
print("Using pure python primes")
return primes(n)


def main(args=None):

from time import time

from astropy.utils.compat import argparse

parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('-c', '--use-cython', dest='cy', action='store_true',
help='Use the Cython-based Prime number generator.')
parser.add_argument('-t', '--timing', dest='time', action='store_true',
help='Time the Fibonacci generator.')
parser.add_argument('-p', '--print', dest='prnt', action='store_true',
help='Print all of the Prime numbers.')
parser.add_argument('n', metavar='N', type=int,
help='Get Prime numbers up to this number.')
parser = argparse.ArgumentParser(description="Process some integers.")
parser.add_argument(
"-c",
"--use-cython",
dest="cy",
action="store_true",
help="Use the Cython-based Prime number generator.",
)
parser.add_argument(
"-t",
"--timing",
dest="time",
action="store_true",
help="Time the Fibonacci generator.",
)
parser.add_argument(
"-p",
"--print",
dest="prnt",
action="store_true",
help="Print all of the Prime numbers.",
)
parser.add_argument(
"n", metavar="N", type=int, help="Get Prime numbers up to this number."
)

res = parser.parse_args(args)

pre = time()
primes = do_primes(res.n, res.cy)
post = time()

print(f'Found {len(primes)} prime numbers')
print(f'Largest prime: {primes[-1]}')
print(f"Found {len(primes)} prime numbers")
print(f"Largest prime: {primes[-1]}")

if res.time:
print(f'Running time: {post - pre} s')
print(f"Running time: {post - pre} s")

if res.prnt:
print(f'Primes: {primes}')
print(f"Primes: {primes}")
3 changes: 1 addition & 2 deletions weird_salads/tests/test_example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


def test_primes():
from ..example_mod import primes

assert primes(10) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
4 changes: 2 additions & 2 deletions weird_salads/version.py
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@
import warnings

warnings.warn(
f'could not determine {__name__.split(".")[0]} package version; this indicates a broken installation'
f'could not determine {__name__.split(".")[0]} package version; this indicates a broken installation' # noqa: 501
)
del warnings

version = '0.0.0'
version = "0.0.0"

0 comments on commit eebd8dc

Please sign in to comment.