Skip to content

Commit 62927e4

Browse files
author
Gal Ben David
committed
Upgrade dependencies. Update github actions workflows. Code updates
1 parent f81f1a1 commit 62927e4

File tree

10 files changed

+163
-114
lines changed

10 files changed

+163
-114
lines changed

.github/workflows/build.yml

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
name: Build
2-
on: [push, pull_request]
2+
on:
3+
- push
4+
- pull_request
35
jobs:
46
lint:
57
if: github.event_name == 'push' && !startsWith(github.event.ref, 'refs/tags')
68
runs-on: ubuntu-latest
79
steps:
810
- name: Checkout
9-
uses: actions/checkout@v2
11+
uses: actions/checkout@v3
1012
- name: Install latest rust
1113
uses: actions-rs/toolchain@v1
1214
with:
1315
toolchain: stable
16+
profile: minimal
1417
override: true
1518
components: clippy
1619
- name: Lint with clippy
@@ -24,17 +27,24 @@ jobs:
2427
strategy:
2528
fail-fast: false
2629
matrix:
27-
python-version: ['3.7', '3.8', '3.9', '3.10']
28-
os: [ubuntu-latest , macos-latest, windows-latest]
30+
python-version:
31+
- '3.7'
32+
- '3.8'
33+
- '3.9'
34+
- '3.10'
35+
os:
36+
- ubuntu-latest
37+
- macos-latest
38+
- windows-latest
2939
steps:
3040
- name: Checkout
31-
uses: actions/checkout@v2
41+
uses: actions/checkout@v3
3242
- name: Set up Python ${{ matrix.python-version }}
33-
uses: actions/setup-python@v2
43+
uses: actions/setup-python@v3
3444
with:
3545
python-version: ${{ matrix.python-version }}
36-
- name: Run image
37-
uses: abatilo/actions-poetry@v2.0.0
46+
- name: Install Poetry
47+
uses: abatilo/actions-poetry@v2.1.3
3848
- name: Install Rust
3949
uses: actions-rs/toolchain@v1
4050
with:

.github/workflows/deploy.yml

+14-19
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
name: Deploy
22
on:
33
release:
4-
types: [released]
4+
types:
5+
- released
56
jobs:
67
deploy:
78
runs-on: ${{ matrix.os }}
89
strategy:
910
fail-fast: false
1011
matrix:
11-
python-version: ['3.7', '3.8', '3.9', '3.10']
12-
os: [ubuntu-latest, macos-latest, windows-latest]
12+
python-version:
13+
- '3.7'
14+
- '3.8'
15+
- '3.9'
16+
- '3.10'
17+
os:
18+
- ubuntu-latest
19+
- macos-latest
20+
- windows-latest
1321
steps:
1422
- name: Checkout
15-
uses: actions/checkout@v2
23+
uses: actions/checkout@v3
1624
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v2
25+
uses: actions/setup-python@v3
1826
with:
1927
python-version: ${{ matrix.python-version }}
2028
- name: Install Rust
@@ -24,22 +32,9 @@ jobs:
2432
toolchain: stable
2533
override: true
2634
- name: Publish Package
27-
if: matrix.os != 'windows-latest'
2835
uses: messense/maturin-action@v1
2936
with:
30-
maturin-version: latest
3137
command: publish
32-
manylinux: 2014
33-
args: --username=__token__ --no-sdist --interpreter=python${{ matrix.python-version }}
34-
env:
35-
MATURIN_PASSWORD: ${{ secrets.pypi_password }}
36-
- name: Publish Package
37-
if: matrix.os == 'windows-latest'
38-
uses: messense/maturin-action@v1
39-
with:
40-
maturin-version: latest
41-
command: publish
42-
manylinux: 2014
43-
args: --username=__token__ --no-sdist --interpreter=python
38+
args: --username=__token__ --no-sdist --interpreter=python${{ !startsWith(matrix.os, 'windows') && matrix.python-version || '' }}
4439
env:
4540
MATURIN_PASSWORD: ${{ secrets.pypi_password }}

.gitignore

+46-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,rust,python
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,rust,python
4+
5+
### Python ###
16
# Byte-compiled / optimized / DLL files
27
__pycache__/
38
*.py[cod]
@@ -94,6 +99,13 @@ ipython_config.py
9499
# install all needed dependencies.
95100
#Pipfile.lock
96101

102+
# poetry
103+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
104+
# This is especially recommended for binary packages to ensure reproducibility, and is more
105+
# commonly ignored for libraries.
106+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
107+
#poetry.lock
108+
97109
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
98110
__pypackages__/
99111

@@ -136,17 +148,48 @@ dmypy.json
136148

137149
# Cython debug symbols
138150
cython_debug/
139-
.gitignore
140-
.gitignore
141151

152+
# PyCharm
153+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
154+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
155+
# and can be added to the global gitignore or merged into this file. For a more nuclear
156+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
157+
#.idea/
158+
159+
### Rust ###
142160
# Generated by Cargo
143161
# will have compiled files and executables
144162
debug/
145-
target/
146163

147164
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
148165
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
149166
Cargo.lock
150167

151168
# These are backup files generated by rustfmt
152169
**/*.rs.bk
170+
171+
# MSVC Windows builds of rustc generate these, which store debugging information
172+
*.pdb
173+
174+
### VisualStudioCode ###
175+
.vscode/*
176+
!.vscode/settings.json
177+
!.vscode/tasks.json
178+
!.vscode/launch.json
179+
!.vscode/extensions.json
180+
!.vscode/*.code-snippets
181+
182+
# Local History for Visual Studio Code
183+
.history/
184+
185+
# Built Visual Studio Code Extensions
186+
*.vsix
187+
188+
### VisualStudioCode Patch ###
189+
# Ignore all local history of files
190+
.history
191+
.ionide
192+
193+
# Support for Project snippet scope
194+
195+
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,rust,python

Cargo.toml

+9-9
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@ name = "pyrepscan"
3535
crate-type = ["cdylib"]
3636

3737
[dependencies]
38-
regex = "1"
39-
chrono = "0.4"
40-
num_cpus = "1"
41-
parking_lot = "0.12"
42-
crossbeam = "0.8"
43-
crossbeam-utils = "0.8"
38+
regex = "1.6.0"
39+
chrono = "0.4.19"
40+
num_cpus = "1.13.1"
41+
parking_lot = "0.12.1"
42+
crossbeam = "0.8.1"
43+
crossbeam-utils = "0.8.10"
4444

4545
[dependencies.libgit2-sys]
46-
version = "0.12"
46+
version = "0.13.4"
4747
features = ["https"]
4848

4949
[dependencies.git2]
50-
version = "0.13"
50+
version = "0.14.4"
5151
features = ["vendored-openssl"]
5252

5353
[dependencies.pyo3]
54-
version = "0.15.1"
54+
version = "0.16.5"
5555
features = ["extension-module"]
5656

5757
[profile.release]

benchmarks/gitleaks.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
~/go/bin/gitleaks --repo-path=$REPO_PATH --config=gitleaks.toml
1+
docker pull zricethezav/gitleaks:latest
2+
docker run -v ${FOLDER_TO_SCAN}:/path -v ${PWD}/benchmarks/gitleaks.toml:/gitleaks.toml zricethezav/gitleaks:latest detect --source="/path" --config=/gitleaks.toml

benchmarks/pyrepscan_bench.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
repository_path='/path/to/repository',
1313
branch_glob_pattern='*',
1414
)
15+
print(len(results))

pyproject.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
[build-system]
2-
requires = ["maturin>=0.11,<0.12"]
2+
requires = ["maturin>=0.12,<0.13"]
33
build-backend = "maturin"
44

55
[tool.maturin]
66
sdist-include = [
7-
"src/*",
87
"Cargo.toml",
8+
"pyproject.toml",
99
"pyrepscan/*.py",
10-
"pyrepscan/*.pyi"
10+
"pyrepscan/*.pyi",
11+
"src/*",
1112
]
1213

1314
[tool.poetry]

src/git_repository_scanner.rs

+23-27
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use crate::rules_manager;
33
use chrono::prelude::*;
44
use crossbeam_utils::atomic::AtomicCell;
55
use crossbeam_utils::thread as crossbeam_thread;
6-
use crossbeam::queue::SegQueue;
6+
use crossbeam::queue::ArrayQueue;
77
use git2::{Oid, Repository, Delta};
88
use parking_lot::Mutex;
9+
use pyo3::exceptions::PyRuntimeError;
910
use pyo3::prelude::*;
1011
use std::collections::HashMap;
1112
use std::path::Path;
@@ -124,18 +125,7 @@ fn scan_commit_oid(
124125
Ok(())
125126
}
126127

127-
pub fn get_file_content(
128-
repository_path: &str,
129-
file_oid: &str,
130-
) -> Result<Vec<u8>, git2::Error> {
131-
let git_repo = Repository::open(repository_path)?;
132-
let oid = Oid::from_str(file_oid)?;
133-
let blob = git_repo.find_blob(oid)?;
134-
135-
Ok(blob.content().to_vec())
136-
}
137-
138-
fn get_oids(
128+
fn get_commit_oids(
139129
repository_path: &str,
140130
branch_glob_pattern: &str,
141131
from_timestamp: i64,
@@ -166,40 +156,46 @@ pub fn scan_repository(
166156
from_timestamp: i64,
167157
rules_manager: &rules_manager::RulesManager,
168158
output_matches: Arc<Mutex<Vec<HashMap<&str, String>>>>,
169-
) -> Result<(), PyErr> {
170-
let oids_queue = Arc::new(SegQueue::new());
171-
match get_oids(
159+
) -> PyResult<()> {
160+
let commit_oids_queue;
161+
162+
match get_commit_oids(
172163
repository_path,
173164
branch_glob_pattern,
174165
from_timestamp
175166
) {
176-
Ok(oids) => {
177-
for oid in oids {
178-
oids_queue.push(oid);
167+
Ok(commit_oids) => {
168+
if commit_oids.is_empty() {
169+
return Ok(());
170+
}
171+
172+
commit_oids_queue = ArrayQueue::new(commit_oids.len());
173+
for commit_oid in commit_oids {
174+
commit_oids_queue.push(commit_oid).unwrap();
179175
}
180176
},
181177
Err(error) => {
182-
return Err(pyo3::exceptions::PyRuntimeError::new_err(error.to_string()))
178+
return Err(PyRuntimeError::new_err(error.to_string()))
183179
},
184180
}
185181

186-
py.check_signals()?;
187-
188182
let mut py_signal_error: PyResult<()> = Ok(());
189183

190184
let should_stop = AtomicCell::new(false);
185+
let number_of_cores = std::thread::available_parallelism().unwrap().get();
186+
191187
crossbeam_thread::scope(
192188
|scope| {
193-
for _ in 0..num_cpus::get() {
189+
for _ in 0..number_of_cores {
194190
scope.spawn(
195191
|_| {
196192
if let Ok(git_repo) = Repository::open(repository_path) {
197193
while !should_stop.load() {
198-
if let Some(oid) = oids_queue.pop() {
194+
if let Some(commit_oid) = commit_oids_queue.pop() {
199195
scan_commit_oid(
200196
&should_stop,
201197
&git_repo,
202-
&oid,
198+
&commit_oid,
203199
rules_manager,
204200
output_matches.clone(),
205201
).unwrap_or(());
@@ -212,7 +208,7 @@ pub fn scan_repository(
212208
);
213209
}
214210

215-
while !oids_queue.is_empty() {
211+
while !commit_oids_queue.is_empty() {
216212
py_signal_error = py.check_signals();
217213
if py_signal_error.is_err() {
218214
should_stop.store(true);
@@ -223,7 +219,7 @@ pub fn scan_repository(
223219
thread::sleep(time::Duration::from_millis(100));
224220
}
225221
}
226-
).unwrap_or(());
222+
).unwrap_or_default();
227223

228224
py_signal_error?;
229225

0 commit comments

Comments
 (0)