Skip to content

Commit e5f636b

Browse files
Add pytest GitHub workflow & convert to src/ layout (#19)
* Add pre-commit hooks and run hooks on all files * Refactor project to use src/ layout * Add basic tox.ini file to test across python versions * Add pytest GitHub workflow to run tox * Update README to include poetry run tox * minor: Wrap python version in string * Improve GitHub tox workflow to target specific python version * Rename test workflow for improved readability * test: Create test to run executable * Run black on single file * build: Update tox - resolve deps w/ pyproject.toml * Update ShadowFinder import in Jupyter Notebook
1 parent 9d5bfcf commit e5f636b

16 files changed

Lines changed: 448 additions & 182 deletions

.github/workflows/tox.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: tox
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
pytest:
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
python-version: ["3.9", "3.10", "3.11", "3.12"]
18+
fail-fast: false
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v3
23+
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v4
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install tox
33+
34+
- name: Run Tests
35+
run: tox run -m ${{ matrix.python-version }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
__pycache__/
33
*.py[cod]
44
*$py.class
5+
dist/
56

67
# Environments
78
.env
@@ -11,6 +12,7 @@ venv/
1112
ENV/
1213
env.bak/
1314
venv.bak/
15+
.tox/
1416

1517
# Output files
1618
*.png

.pre-commit-config.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@ repos:
88
- id: end-of-file-fixer
99
- id: check-yaml
1010
- id: check-added-large-files
11-
- repo: https://github.com/psf/black
12-
rev: 24.2.0
11+
12+
- repo: local
1313
hooks:
1414
- id: black
15+
name: black
16+
entry: poetry run black
17+
language: system
18+
types: [ python ]
19+
20+
- id: poetry-lock
21+
name: poetry lock
22+
entry: poetry lock --no-update
23+
language: system
24+
types: [yaml]
25+
files: ^pyproject\.toml$

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pip install shadowfinder
2929
If you want to use ShadowFinder directly from Python, the usage is as follows.
3030

3131
```python
32-
from shadowfinder.shadowfinder import ShadowFinder
32+
from shadowfinder import ShadowFinder
3333

3434
finder = ShadowFinder()
3535

@@ -111,7 +111,10 @@ poetry run pre-commit install
111111
# Run the tool
112112
poetry run shadowfinder --help
113113

114-
# After making changes, format your code with black:
115-
poetry run black ./
114+
# Run tests against your current Python interpreter
115+
poetry run pytest
116+
117+
# Or, run pytest against all shadowfinder supported Python versions
118+
poetry run tox p # p=run in parallel
116119
```
117120
</details>

ShadowFinderColab.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"![ ! -f \"timezone_grid.json\" ] && wget https://raw.githubusercontent.com/bellingcat/ShadowFinder/main/timezone_grid.json >> {logfile} 2>&1\n",
4848
"![ ! -f \"deps_loaded\" ] && pip install shadowfinder >> {logfile} 2>&1 && touch deps_loaded\n",
4949
"\n",
50-
"from shadowfinder.shadowfinder import ShadowFinder\n",
50+
"from shadowfinder import ShadowFinder\n",
5151
"import datetime\n",
5252
"\n",
5353
"datetime_date = datetime.datetime.strptime(date, \"%Y-%m-%d\").date()\n",

poetry.lock

Lines changed: 304 additions & 160 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
[tool.poetry]
22
name = "ShadowFinder"
3-
version = "0.3.1"
3+
version = "0.4.0"
44
description = "Find possible locations of shadows."
55
authors = ["Bellingcat"]
66
license = "MIT License"
77
readme = "README.md"
8+
packages = [{ include = "shadowfinder", from = "src" }]
89
repository = "https://github.com/bellingcat/ShadowFinder"
910
classifiers = [
1011
"Intended Audience :: Developers",
@@ -20,7 +21,7 @@ keywords=["shadow", "finder", "locator", "map"]
2021
"Bug Tracker" = "https://github.com/bellingcat/ShadowFinder/issues"
2122

2223
[tool.poetry.scripts]
23-
shadowfinder = "shadowfinder.main:main_entrypoint"
24+
shadowfinder = "shadowfinder.__main__:main"
2425

2526
[tool.poetry.dependencies]
2627
python = ">=3.9,<3.13"
@@ -34,10 +35,11 @@ numpy = "^1"
3435
pytz = "^2024.1"
3536

3637
[tool.poetry.group.dev.dependencies]
37-
black = "^24.2.0"
38+
black = "24.2.0"
3839
pre-commit = "^3.7.1"
39-
40+
tox = "^4.15.1"
41+
pytest = "^8.2.2"
4042

4143
[build-system]
42-
requires = ["poetry-core"]
44+
requires = ["poetry-core>=1.0.0"]
4345
build-backend = "poetry.core.masonry.api"

shadowfinder/__init__.py

Whitespace-only changes.

shadowfinder/main.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/shadowfinder/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .shadowfinder import ShadowFinder
2+
from .cli import ShadowFinderCli
3+
4+
__all__ = ["ShadowFinder", "ShadowFinderCli"]

0 commit comments

Comments
 (0)