Skip to content

Commit bb0f93d

Browse files
committed
Merge branch 'main' into bump_dfxml_version_references
2 parents 6094392 + 68fef71 commit bb0f93d

File tree

100 files changed

+402
-204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+402
-204
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ jobs:
1212
strategy:
1313
matrix:
1414
os: ['ubuntu-latest', 'macos-latest']
15-
python-version: [3.8, 3.9]
15+
python-version:
16+
- '3.8'
17+
- '3.12'
1618
steps:
1719
- name: Checkout
1820
uses: actions/checkout@v4
@@ -35,6 +37,11 @@ jobs:
3537
sudo apt update
3638
sudo apt install --yes libxml2-utils
3739
40+
- name: Pre-commit Checks
41+
run: |
42+
pip -q install pre-commit
43+
pre-commit run --all-files
44+
3845
- name: Make check
3946
run: make check
4047

.github/workflows/supply-chain.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
matrix:
3030
python-version:
3131
- '3.8'
32-
- '3.9'
32+
- '3.12'
3333

3434
steps:
3535
- uses: actions/checkout@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ python/demo.dfxml
1111
.pytest_cache
1212
*.egg-info
1313
*.log
14+
.venv-pre-commit

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
repos:
2+
- repo: https://github.com/pycqa/isort
3+
rev: 5.13.2
4+
hooks:
5+
- id: isort
6+
name: isort (python)

CONTRIBUTE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
# Contributing to DFXML's Python code base
22

33

4+
## Pre-commit
5+
6+
This project uses [the `pre-commit` tool](https://pre-commit.com/) for linting.
7+
8+
`pre-commit` hooks into Git's commit machinery to run a set of linters and static analyzers over each change. To install `pre-commit` into Git's hooks, run one (not both) of the following sets of commands:
9+
10+
```bash
11+
pip install pre-commit
12+
pre-commit --version
13+
pre-commit install
14+
```
15+
16+
Or:
17+
18+
```bash
19+
make
20+
```
21+
22+
423
## Installable tools versus in-place scripts
524

625
The [`dfxml/bin/`](dfxml/bin/) directory contains scripts for interacting with DFXML. Some of the tools are installed in the command-line `$PATH` when the `dfxml` package is installed.

Makefile

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@ ifeq ($(shell basename $(SHELL)),sh)
1818
SHELL := $(shell which /bin/bash 2>/dev/null || which /usr/local/bin/bash)
1919
endif
2020

21-
all:
21+
PYTHON3 ?= python3
22+
ifeq ($(PYTHON3),)
23+
$(error python3 not found)
24+
endif
25+
26+
all: \
27+
.venv-pre-commit/var/.pre-commit-built.log
2228

2329
.PHONY: \
2430
check-mypy \
25-
check-supply-chain
31+
check-supply-chain \
32+
check-supply-chain-pre-commit
2633

2734
.git_submodule_init.done.log: .gitmodules
2835
# Confirm dfxml_schema has been checked out at least once.
@@ -31,28 +38,86 @@ all:
3138
test -r dependencies/dfxml_schema/dfxml.xsd
3239
touch $@
3340

41+
# This virtual environment is meant to be built once and then persist, even through 'make clean'.
42+
# If a recipe is written to remove this flag file, it should first run `pre-commit uninstall`.
43+
.venv-pre-commit/var/.pre-commit-built.log:
44+
rm -rf .venv-pre-commit
45+
test -r .pre-commit-config.yaml \
46+
|| (echo "ERROR:Makefile:pre-commit is expected to install for this repository, but .pre-commit-config.yaml does not seem to exist." >&2 ; exit 1)
47+
$(PYTHON3) -m venv \
48+
.venv-pre-commit
49+
source .venv-pre-commit/bin/activate \
50+
&& pip install \
51+
--upgrade \
52+
pip \
53+
setuptools \
54+
wheel
55+
source .venv-pre-commit/bin/activate \
56+
&& pip install \
57+
pre-commit
58+
source .venv-pre-commit/bin/activate \
59+
&& pre-commit install
60+
mkdir -p \
61+
.venv-pre-commit/var
62+
touch $@
63+
3464
clean:
3565
find . -name '*~' -exec rm {} \;
3666
$(MAKE) \
3767
--directory tests \
3868
clean
3969

4070
check: \
41-
check-mypy
71+
.git_submodule_init.done.log \
72+
.venv-pre-commit/var/.pre-commit-built.log
4273
$(MAKE) \
74+
PYTHON3=$(PYTHON3) \
4375
SHELL=$(SHELL) \
4476
--directory tests \
4577
check
4678

4779
check-mypy: \
4880
.git_submodule_init.done.log
4981
$(MAKE) \
82+
PYTHON3=$(PYTHON3) \
5083
SHELL=$(SHELL) \
5184
--directory tests \
5285
check-mypy
5386

5487
check-supply-chain: \
88+
check-supply-chain-pre-commit \
5589
check-mypy
5690

91+
# Update pre-commit configuration and use the updated config file to
92+
# review code. Only have Make exit if 'pre-commit run' modifies files.
93+
check-supply-chain-pre-commit: \
94+
.venv-pre-commit/var/.pre-commit-built.log
95+
source .venv-pre-commit/bin/activate \
96+
&& pre-commit autoupdate
97+
git diff \
98+
--exit-code \
99+
.pre-commit-config.yaml \
100+
|| ( \
101+
source .venv-pre-commit/bin/activate \
102+
&& pre-commit run \
103+
--all-files \
104+
--config .pre-commit-config.yaml \
105+
) \
106+
|| git diff \
107+
--stat \
108+
--exit-code \
109+
|| ( \
110+
echo \
111+
"WARNING:Makefile:pre-commit configuration can be updated. It appears the updated would change file formatting." \
112+
>&2 \
113+
; exit 1 \
114+
)
115+
@git diff \
116+
--exit-code \
117+
.pre-commit-config.yaml \
118+
|| echo \
119+
"INFO:Makefile:pre-commit configuration can be updated. It appears the update would not change file formatting." \
120+
>&2
121+
57122
check-tools:
58123
(cd tests/misc_object_tests;make check)

demos/demo_fiwalk_diskimage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
if the required buffer size exceeds available RAM!
77
"""
88

9-
import sys
109
import io
10+
import sys
11+
1112
from dfxml import fiwalk
1213

14+
1315
def writeDfxml(imageFile: str, outFile: str) -> None:
1416
"""Generate filesystem metadata for disk image and and write resulting
1517
dfxml to file"""

demos/demo_mac_timeline.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
sys.path.append( os.path.join(os.path.dirname(__file__), ".."))
88
import dfxml
99

10-
1110
timeline = []
1211

1312
def process(fi):

demos/demo_mac_timeline_iter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
sys.path.append( os.path.join(os.path.dirname(__file__), ".."))
2323
import dfxml
2424

25+
2526
def main():
2627
if len(sys.argv) < 2:
2728
print("Usage: {} <filename.xml>".format(sys.argv[0]))

demos/demo_piecewise.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
import sys
1010

1111
sys.path.append( os.path.join(os.path.dirname(__file__), ".."))
12-
import dfxml
13-
12+
import collections
13+
import math
14+
import sys
1415

15-
import math,sys,collections
16+
import dfxml
1617

1718

1819
class SectorCorrelator:

0 commit comments

Comments
 (0)