Skip to content

Commit

Permalink
Changes for deployment (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Sep 28, 2023
1 parent c6ec7fc commit 5033b62
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 210 deletions.
49 changes: 27 additions & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
matrix:
python-version: ['3.11']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
Expand All @@ -32,42 +32,47 @@ jobs:
run: |
python run_tests.py
build_ubuntu:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ['3.11']
architecture: ['x86', 'x64']
include:
- python-version: '3.7'
toxenv: 'py37'
- python-version: '3.8'
toxenv: 'py38'
- python-version: '3.9'
toxenv: 'py39'
- python-version: '3.10'
toxenv: 'py310'
- python-version: '3.11'
toxenv: 'py311'
- python-version: '3.12'
toxenv: 'py312'
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- uses: actions/checkout@v3
- name: Install build dependencies
run: |
sudo apt-get install automake autotools-dev build-essential git libtool python3 python3-dev python3-distutils python3-setuptools
- name: Build Python module
sudo add-apt-repository universe &&
sudo add-apt-repository -y ppa:deadsnakes/ppa &&
sudo add-apt-repository -y ppa:gift/dev &&
sudo apt-get update &&
sudo apt-get install -y autoconf automake autopoint autotools-dev build-essential git libtool pkg-config python${{ matrix.python-version }} python${{ matrix.python-version }}-dev python${{ matrix.python-version }}-venv python3-distutils python3-pip python3-setuptools
- name: Install tox
run: |
python3 -m pip install tox
- name: Build and test Python module
run: |
python setup.py update
python setup.py build
python setup.py install
- name: Test Python module
run: |
python run_tests.py
- name: Build source distribution package (sdist)
run: |
python setup.py sdist
- name: Build binary distribution package (bdist)
run: |
python setup.py bdist
tox -e${{ matrix.toxenv }}
build_windows:
runs-on: windows-latest
strategy:
matrix:
python-version: ['3.11']
architecture: ['x86', 'x64']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Back-up files
*~
*.so
*.swp

# Generic auto-generated build files
Expand Down
2 changes: 1 addition & 1 deletion class_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
DEBUG = 0

# The pytsk3 version.
VERSION = "20230125"
VERSION = "20230928"

# These functions are used to manage library memory.
FREE = "aff4_free"
Expand Down
4 changes: 2 additions & 2 deletions dpkg/changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pytsk3 (20230125-1) unstable; urgency=low
pytsk3 (20230928-1) unstable; urgency=low

* Auto-generated

-- Joachim Metz <joachim.metz@gmail.com> Wed, 25 Jan 2023 20:56:07 -0100
-- Joachim Metz <joachim.metz@gmail.com> Thu, 28 Sep 2023 12:43:50 -0100
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

18 changes: 17 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
[metadata]
name = pytsk3
version = 20230125
description = Python bindings for the SleuthKit
long_description = Python bindings for the SleuthKit
author = Michael Cohen
author_email = scudette@gmail.com
maintainer = Joachim Metz
maintainer_email = joachim.metz@gmail.com
url = https://github.com/py4n6/pytsk
license = Apache License, Version 2.0
license_files = LICENSE sleuthkit/licenses/cpl1.0.txt sleuthkit/licenses/IBM-LICENSE
classifiers =
Development Status :: 3 - Alpha
Programming Language :: Python

[options]
python_requires = >=3.7

[bdist_rpm]
release = 1
packager = Joachim Metz <joachim.metz@gmail.com>
doc_files = LICENSE README
doc_files = LICENSE sleuthkit/licenses/cpl1.0.txt sleuthkit/licenses/IBM-LICENSE README
build_requires = python-setuptools
189 changes: 11 additions & 178 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,174 +46,28 @@
from distutils.ccompiler import new_compiler
from distutils.dep_util import newer_group

try:
from distutils.command.bdist_msi import bdist_msi
except ImportError:
bdist_msi = None

try:
from distutils.command.bdist_rpm import bdist_rpm
except ImportError:
bdist_rpm = None
# Change PYTHONPATH.
sys.path.insert(0, '.')

import generate_bindings
import run_tests


version_tuple = (sys.version_info[0], sys.version_info[1])
if version_tuple < (3, 5):
if version_tuple < (3, 7):
print((
'Unsupported Python version: {0:s}, version 3.5 or higher '
'Unsupported Python version: {0:s}, version 3.7 or higher '
'required.').format(sys.version))
sys.exit(1)


if not bdist_msi:
BdistMSICommand = None
else:
class BdistMSICommand(bdist_msi):
"""Custom handler for the bdist_msi command."""

def run(self):
"""Builds an MSI."""
# Make a deepcopy of distribution so the following version changes
# only apply to bdist_msi.
self.distribution = copy.deepcopy(self.distribution)

# bdist_msi does not support the library version so we add ".1"
# as a work around.
self.distribution.metadata.version += ".1"

bdist_msi.run(self)


if not bdist_rpm:
BdistRPMCommand = None
else:
class BdistRPMCommand(bdist_rpm):
"""Custom handler for the bdist_rpm command."""

def make_spec_file(self, spec_file):
"""Make an RPM Spec file."""
# Note that bdist_rpm can be an old style class.
if issubclass(BdistRPMCommand, object):
spec_file = super(BdistRPMCommand, self)._make_spec_file()
else:
spec_file = bdist_rpm._make_spec_file(self)

if sys.version_info[0] < 3:
python_package = 'python2'
else:
python_package = 'python3'

description = []
requires = ''
summary = ''
in_description = False

python_spec_file = []
for line in iter(spec_file):
if line.startswith('Summary: '):
summary = line

elif line.startswith('BuildRequires: '):
line = 'BuildRequires: {0:s}-setuptools, {0:s}-devel'.format(
python_package)

elif line.startswith('Requires: '):
requires = line[10:]
if python_package == 'python3':
requires = requires.replace('python-', 'python3-')
requires = requires.replace('python2-', 'python3-')

elif line.startswith('%description'):
in_description = True

elif line.startswith('python setup.py build'):
if python_package == 'python3':
line = '%py3_build'
else:
line = '%py2_build'

elif line.startswith('python setup.py install'):
if python_package == 'python3':
line = '%py3_install'
else:
line = '%py2_install'

elif line.startswith('%files'):
lines = [
'%files -n {0:s}-%{{name}}'.format(python_package),
'%defattr(644,root,root,755)',
'%license LICENSE',
'%doc README']

if python_package == 'python3':
lines.extend([
'%{_libdir}/python3*/site-packages/*.so',
'%{_libdir}/python3*/site-packages/pytsk3*.egg-info/*',
'',
'%exclude %{_prefix}/share/doc/*'])

else:
lines.extend([
'%{_libdir}/python2*/site-packages/*.so',
'%{_libdir}/python2*/site-packages/pytsk3*.egg-info/*',
'',
'%exclude %{_prefix}/share/doc/*'])

python_spec_file.extend(lines)
break

elif line.startswith('%prep'):
in_description = False

python_spec_file.append(
'%package -n {0:s}-%{{name}}'.format(python_package))
if python_package == 'python2':
python_spec_file.extend([
'Obsoletes: python-pytsk3 < %{version}',
'Provides: python-pytsk3 = %{version}'])

if requires:
python_spec_file.append('Requires: {0:s}'.format(requires))

python_spec_file.extend([
'{0:s}'.format(summary),
'',
'%description -n {0:s}-%{{name}}'.format(python_package)])

python_spec_file.extend(description)

elif in_description:
# Ignore leading white lines in the description.
if not description and not line:
continue

description.append(line)

python_spec_file.append(line)

return python_spec_file

def _make_spec_file(self):
"""Generates the text of an RPM spec file.
Returns:
list[str]: lines of text.
"""
return self.make_spec_file(
bdist_rpm._make_spec_file(self))


class BuildExtCommand(build_ext):
"""Custom handler for the build_ext command."""

def build_extension(self, extension):
"""Builds the extension.
Args:
extentsion: distutils extentsion object.
extension: distutils extension object.
"""
if (extension.sources is None or
not isinstance(extension.sources, (list, tuple))):
Expand Down Expand Up @@ -501,9 +355,8 @@ def run(self):
class ProjectBuilder(object):
"""Class to help build the project."""

def __init__(self, project_config, argv):
def __init__(self, argv):
"""Initializes a project builder object."""
self._project_config = project_config
self._argv = argv

# The path to the sleuthkit/tsk directory.
Expand Down Expand Up @@ -543,35 +396,15 @@ def build(self):
source_files = sorted(self._source_files)
ext_modules = [Extension("pytsk3", source_files, **self.extension_args)]

setup(
setup_args = dict(
cmdclass={
"build_ext": BuildExtCommand,
"bdist_msi": BdistMSICommand,
"bdist_rpm": BdistRPMCommand,
"sdist": SDistCommand,
"update": UpdateCommand},
ext_modules=ext_modules,
**self._project_config)
ext_modules=ext_modules)

setup(**setup_args)


if __name__ == "__main__":
__version__ = open("version.txt").read().strip()

setup_args = dict(
name="pytsk3",
version=__version__,
description="Python bindings for the sleuthkit",
long_description=(
"Python bindings for the sleuthkit (http://www.sleuthkit.org/)"),
long_description_content_type="text/plain",
license="Apache 2.0",
url="https://github.com/py4n6/pytsk/",
author="Michael Cohen",
author_email="scudette@gmail.com",
maintainer="Joachim Metz",
maintainer_email="joachim.metz@gmail.com",
zip_safe=False,
install_requires=[],
tests_require=[])

ProjectBuilder(setup_args, sys.argv).build()
ProjectBuilder(sys.argv).build()
20 changes: 15 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
[tox]
envlist = py27, py34
envlist = py3{7,8,9,10,11,12}

[testenv]
pip_pre = True
deps =
pip >= 7.0.0
pytest
commands = python run_tests.py
passenv =
CFLAGS
CPPFLAGS
INCLUDE
LDFLAGS
LIB
deps =
build
setuptools
wheel
commands =
python -m pip wheel --no-build-isolation --wheel-dir=dist pytsk3
python -m pip install --no-index --find-links=dist pytsk3
python run_tests.py
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20230125
20230928

0 comments on commit 5033b62

Please sign in to comment.