Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvement and bug fixes #47

Merged
merged 9 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry==1.6.1
pip install poetry
- name: Build and publish
env:
PYPI_TOKEN: ${{ secrets.PYPI_PASSWORD }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.8, 3.9, '3.10', '3.11']
python-version: ['3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
Expand All @@ -27,7 +27,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox poetry==1.6.1
pip install tox poetry
- name: Lint
run: |
tox -e lint
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ usage: libsast [-h] [-o OUTPUT] [-p PATTERN_FILE] [-s SGREP_PATTERN_FILE]
[--ignore-filenames IGNORE_FILENAMES [IGNORE_FILENAMES ...]]
[--ignore-extensions IGNORE_EXTENSIONS [IGNORE_EXTENSIONS ...]]
[--ignore-paths IGNORE_PATHS [IGNORE_PATHS ...]]
[--show-progress] [-v]
[path [path ...]]
[--show-progress] [--cpu-core CPU_CORE] [-v]
[path ...]

positional arguments:
path Path can be file(s) or directories

optional arguments:
options:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Output filename to save JSON report.
Expand All @@ -46,7 +46,8 @@ optional arguments:
-s SGREP_PATTERN_FILE, --sgrep-pattern-file SGREP_PATTERN_FILE
sgrep rules directory
--sgrep-file-extensions SGREP_FILE_EXTENSIONS [SGREP_FILE_EXTENSIONS ...]
File extensions that should be scanned with sgrep
File extensions that should be scanned with semantic
grep
--file-extensions FILE_EXTENSIONS [FILE_EXTENSIONS ...]
File extensions that should be scanned with pattern
matcher
Expand All @@ -57,6 +58,7 @@ optional arguments:
--ignore-paths IGNORE_PATHS [IGNORE_PATHS ...]
Path(s) to ignore
--show-progress Show scan progress
--cpu-core CPU_CORE No of CPU cores to use. Use all cores by default
-v, --version Show libsast version
```

Expand Down
8 changes: 6 additions & 2 deletions libsast/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf_8 -*-
from datetime import datetime

from .core_matcher.pattern_matcher import PatternMatcher
from .core_matcher.choice_matcher import ChoiceMatcher
from .core_sgrep.semantic_sgrep import SemanticGrep
from .scanner import Scanner


year = str(datetime.now().year)
__title__ = 'libsast'
__authors__ = 'Ajin Abraham'
__copyright__ = 'Copyright 2020 Ajin Abraham, OpenSecurity'
__version__ = '2.0.3'
__copyright__ = f'Copyright {year} Ajin Abraham, opensecurity.in'
__version__ = '3.0.0'
__version_info__ = tuple(int(i) for i in __version__.split('.'))
__all__ = [
'Scanner',
Expand Down
7 changes: 6 additions & 1 deletion libsast/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def main():
parser.add_argument('--sgrep-file-extensions',
nargs='+',
help=('File extensions that should be scanned'
' with sgrep'),
' with semantic grep'),
required=False)
parser.add_argument('--file-extensions',
nargs='+',
Expand All @@ -74,6 +74,10 @@ def main():
help='Show scan progress',
required=False,
action='store_true')
parser.add_argument('--cpu-core',
help='No of CPU cores to use. Use all cores by default',
type=int,
required=False)
parser.add_argument('-v', '--version',
help='Show libsast version',
required=False,
Expand All @@ -89,6 +93,7 @@ def main():
'ignore_extensions': args.ignore_extensions,
'ignore_paths': args.ignore_paths,
'show_progress': args.show_progress,
'cpu_core': args.cpu_core,
}
result = Scanner(options, args.path).scan()
output(args.output, result)
Expand Down
21 changes: 12 additions & 9 deletions libsast/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def progress_print(self, index):
self.output.write(f'- {self.prefix} {prog} {index}\r')
self.output.flush()

def progrees_loop(self, iterator):
def progress_loop(self, iterator):
"""Show progress for loop."""
self.progress_print(0)
for index, item in enumerate(iterator):
Expand Down Expand Up @@ -74,15 +74,18 @@ def read_yaml(file_obj, text=False):

def get_worker_count():
"""Get worker count for pool."""
libsast_workers = os.getenv('LIBSAST_WORKERS')
if libsast_workers:
try:
return int(libsast_workers)
except ValueError:
return 1
try:
worker_count = os.cpu_count()
if not worker_count:
worker_count = 1
if worker_count != 1 and sys.platform == 'win32':
# Work around https://bugs.python.org/issue26903
worker_count = min(worker_count, 61)
if os.getenv('LIBSAST_WORKERS'):
worker_count = int(os.getenv('LIBSAST_WORKERS'))
except Exception:
worker_count = 16
worker_count = 1

# Adjust worker count for Windows
if sys.platform == 'win32':
worker_count = min(worker_count, 61)
return worker_count
Loading
Loading