Skip to content

Commit 3153237

Browse files
committed
Add various static checker config
1 parent 20f3f72 commit 3153237

12 files changed

+307
-0
lines changed

.flake8

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E203
4+
exclude =
5+
test/resources/*
6+
venv

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
venv
2+
dist
3+
build
4+
site
5+
*.py[ocd]
6+
__pycache__
7+
*.egg-info

.pre-commit-config.yaml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: check-case-conflict
6+
- id: check-merge-conflict
7+
- id: check-json
8+
- id: check-yaml
9+
args: ["--unsafe"]
10+
- id: check-toml
11+
- id: mixed-line-ending
12+
- id: trailing-whitespace
13+
- repo: https://github.com/pycqa/flake8
14+
rev: 6.0.0
15+
hooks:
16+
- id: flake8
17+
args: ["--config=.flake8"]
18+
types: [python]
19+
- repo: https://github.com/ambv/black
20+
rev: 23.3.0
21+
hooks:
22+
- id: black
23+
language_version: python3.9
24+
- repo: https://github.com/pycqa/isort
25+
rev: 5.12.0
26+
hooks:
27+
- id: isort
28+
name: isort (python)
29+
files: (^astro_pi_orbit/|^test/)
30+
types: [python]
31+
- repo: https://github.com/PyCQA/bandit
32+
rev: 1.7.5
33+
hooks:
34+
- id: bandit
35+
args: ["-c", "pyproject.toml"]
36+
files: (^astro_pi_orbit/|^test/)
37+
types: [python]
38+
additional_dependencies: [ "bandit[toml]" ]
39+
40+
- repo: https://github.com/pre-commit/mirrors-mypy
41+
rev: v1.3.0
42+
hooks:
43+
- id: mypy
44+
files: ^astro_pi_orbit/
45+
types: [python]
46+
additional_dependencies: [ ]
47+

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Raspberry Pi Foundation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

MANIFEST.in

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
include LICENSE
2+
include README.md
3+
exclude mkdocs.yml
4+
exclude requirements.txt
5+
exclude requirements-dev.txt
6+
exclude .DS_Store
7+
exclude MANIFEST.in
8+
prune dist
9+
prune docs
10+
prune scripts
11+
prune test
12+
prune venv
13+
global-exclude *.egg-info
14+
global-exclude *.py[cod]
15+
global-exclude __pycache__
16+

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# astro_pi_orbit
2+
3+
The `astro_pi_orbit` library provides functionality to assist Astro Pi Mission Space Lab participants in working with orbital data.
4+
5+
Documentation is available at [docs](./docs).
6+
7+
## Contributing
8+
9+
We welcome all contributions!
10+
Please install and run the dependencies in `requirements-dev.txt`, and run `pre-commit` prior to opening a PR. On Unix, `pre-commit` can be installed by running the following:
11+
12+
```bash
13+
pip install pre-commit
14+
pre-commit install
15+
```
16+

mkdocs.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
site_name: astro_pi_orbit
2+
site_description: Miscellaneous functions for use in the Astro Pi Mission Space Lab challenge
3+
theme:
4+
name: material
5+
logo: images/rpf-logo.svg
6+
favicon: images/astro-pi-logo.svg
7+
features:
8+
- content.code.copy
9+
nav:
10+
- Home: index.md
11+
- Recipes: recipes.md
12+
- API: api.md
13+
14+
# markdown_extensions:
15+
# - pymdownx.snippets:
16+
# check_paths: true
17+
# base_path: [docs/recipes, "."]
18+
# - pymdownx.highlight:
19+
# anchor_linenums: true
20+
# line_spans: __span
21+
# pygments_lang_class: true
22+
# - pymdownx.inlinehilite
23+
# - pymdownx.superfences
24+

pyproject.toml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "astro_pi_orbit"
7+
description = "Module for interfacing with the Astro Pi"
8+
dynamic = ["version"]
9+
authors = [
10+
{ name="Ben Nuttall", email="[email protected]" },
11+
{ name="George Boukeas", email="[email protected]" },
12+
{ name="Geraint Ballinger", email="[email protected]" }
13+
]
14+
license = {file="LICENSE"}
15+
readme = "README.md"
16+
requires-python = ">=3.7"
17+
classifiers = [
18+
"Programming Language :: Python :: 3",
19+
"Operating System :: OS Independent"
20+
]
21+
dependencies = [
22+
"skyfield"
23+
]
24+
25+
[tool.setuptools]
26+
packages = ["astro_pi_orbit"]
27+
28+
[tool.setuptools.dynamic]
29+
version = {attr = "astro_pi_orbit.__init__.__version__"}
30+
31+
32+
# Configure static checkers/tools
33+
[tool.isort]
34+
atomic = true
35+
line_length = 88
36+
profile = "black"
37+
skip_gitignore = true
38+
src_paths = ["astro_pi_orbit", "test"]
39+
skip_glob = ["test/resources", "venv", "dist", "site", "docs", "scripts"]
40+
41+
[tool.black]
42+
line-length = 88
43+
target-version = ['py39']
44+
include = '\.pyi?$'
45+
extend-exclude = '''
46+
(
47+
^/test/resources
48+
)
49+
'''
50+
51+
[tool.bandit]
52+
skips = ["B101", "B404"]
53+
exclude = ["test/resources"]
54+

requirements-dev.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pytest==8.3.3
2+
build==1.2.2
3+
twine==5.1.1
4+
check-manifest==0.50
5+
black==24.10.0
6+
isort==5.13.2
7+
mypy==1.13.0
8+
mypy-extensions==1.0.0
9+
bandit==1.7.10

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mkdocs==1.6.1
2+
mkdocs-material==9.5.46

scripts/ci.py

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
from pathlib import Path
2+
import subprocess
3+
import platform
4+
import shutil
5+
from typing import Optional, Union
6+
7+
CURRENT_DIR = Path(__file__).parent
8+
PROJECT_DIR = CURRENT_DIR.parent
9+
VENV_DIR = PROJECT_DIR / "venv"
10+
11+
PYTHON_SYNONYMS = ["python3", "python"]
12+
PIP_SYNONYMS = ["pip3", "pip"]
13+
14+
15+
class ResolvedVenv:
16+
venv_dir: Path
17+
scripts_dir: Path
18+
pip: Path
19+
python: Path
20+
pytest: Path
21+
22+
def __init__(self, venv_dir: Path) -> None:
23+
self.venv_dir: Path = venv_dir
24+
if platform.system == "Windows":
25+
self.scripts_dir = VENV_DIR / "Scripts"
26+
get_script_name = lambda x: f"{x}.exe" # noqa: E731
27+
28+
else:
29+
self.scripts_dir = VENV_DIR / "bin"
30+
get_script_name = lambda x: x # noqa: E731
31+
32+
found_pip = None
33+
for pip in PIP_SYNONYMS:
34+
pip_path = self.scripts_dir / get_script_name(pip)
35+
if pip_path.exists():
36+
found_pip = pip_path
37+
if not found_pip:
38+
raise RuntimeError("Couldn't find pip")
39+
self.pip = found_pip
40+
41+
found_python = None
42+
for python in PYTHON_SYNONYMS:
43+
python_path = self.scripts_dir / get_script_name(python)
44+
if python_path.exists():
45+
found_python = python_path
46+
if not found_python:
47+
raise RuntimeError("Couldn't find python")
48+
self.python = found_python
49+
50+
def install(
51+
self,
52+
dependency: Optional[str] = None,
53+
requirements_txt: Optional[Union[str, Path]] = None,
54+
):
55+
args: list[str] = [str(self.pip), "install"]
56+
if requirements_txt:
57+
args.extend(["-r", str(requirements_txt)])
58+
elif dependency:
59+
args.append(dependency)
60+
else:
61+
raise RuntimeError(
62+
"Please specify either a dependency "
63+
+ "to install or a requirements.txt file"
64+
)
65+
subprocess.run(args, check=True, text=True)
66+
67+
68+
def find_python() -> str:
69+
synonyms = [python for python in PYTHON_SYNONYMS if shutil.which]
70+
if len(synonyms) == 0:
71+
raise RuntimeError("Couldn't find Python")
72+
return synonyms[0]
73+
74+
75+
def prepare_venv(python: str) -> ResolvedVenv:
76+
if not VENV_DIR.exists():
77+
subprocess.run([python, "-m", "venv", str(VENV_DIR)], text=True, check=True)
78+
79+
venv = ResolvedVenv(VENV_DIR)
80+
venv.install(requirements_txt=PROJECT_DIR / "requirements-dev.txt")
81+
else:
82+
venv = ResolvedVenv(VENV_DIR)
83+
84+
return venv
85+
86+
87+
def run_tests(venv: ResolvedVenv):
88+
subprocess.run(
89+
[str(venv.scripts_dir / "pytest")], cwd=PROJECT_DIR, check=True, text=True
90+
)
91+
92+
93+
def run_build(venv: ResolvedVenv):
94+
subprocess.run(
95+
[str(venv.python), "-m", "build"], cwd=PROJECT_DIR, check=True, text=True
96+
)
97+
98+
99+
if __name__ == "__main__":
100+
venv: ResolvedVenv = prepare_venv(find_python())
101+
run_tests(venv)
102+
run_build(venv)

test/test_astro_pi_orbit.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_foo():
2+
pass

0 commit comments

Comments
 (0)