Commit 3d7b64cc by Jörg Stucke

switched to pyproject.toml setup

parent f35022e1
include fact_helper_file/bin/custommime.mgc
include custommime.mgc
include *.mgc
[build-system]
requires = [
"setuptools >= 61.0.0",
"wheel",
]
build-backend = "setuptools.build_meta"
[project]
name = "fact_helper_file"
version = "0.2.13"
authors = [
{name = "Johannes vom Dorp"}
]
license = {file = "LICENSE"}
urls = {homepage = "https://github.com/fkie-cad/fact_helper_file"}
dependencies = [
"python-magic",
]
requires-python = ">=3.7"
[tool.setuptools.packages.find]
where = ["."]
include = ["fact_helper_file"]
exclude = ["test"]
[tool.setuptools.package-data]
mypkg = ["*.mgc"]
[tool.black]
line-length = 120
skip-string-normalization = true
target-version = ['py37']
target-version = ["py37"]
[tool.pylint.main]
init-hook = 'import sys; sys.path.append("./src")'
......
#!/usr/bin/env python
from __future__ import annotations
import os
import sys
from pathlib import Path
from subprocess import Popen, PIPE
from subprocess import run, STDOUT
from setuptools import setup
MODULE_NAME = 'fact_helper_file'
MIME_DIR = Path(__file__).parent / MODULE_NAME / 'mime'
MODULE_DIR = Path(__file__).parent / MODULE_NAME
MIME_DIR = MODULE_DIR / 'mime'
BIN_DIR = MODULE_DIR / 'bin'
class OperateInDirectory:
def __init__(self, target_directory: str):
def __init__(self, target_directory: str | Path):
self._current_working_dir = None
self._target_directory = target_directory
def __enter__(self):
self._current_working_dir = os.getcwd()
self._current_working_dir = Path.cwd()
os.chdir(self._target_directory)
def __exit__(self, *_):
os.chdir(self._current_working_dir)
def execute_shell_command(shell_command):
with Popen(shell_command, shell=True, stdout=PIPE, stderr=PIPE) as pl:
output = pl.communicate()[0].decode('utf-8', errors='replace')
return output, pl.returncode
BIN_DIR.mkdir(exist_ok=True)
os.makedirs(str(MIME_DIR.parent / 'bin'), exist_ok=True)
with OperateInDirectory(str(MIME_DIR)):
FILE_OUTPUT, FILE_CODE = execute_shell_command(
with OperateInDirectory(MIME_DIR):
process = run(
'(cat custom_* > custommime)'
' && file -C -m custommime'
' && mv -f custommime.mgc ../bin/'
' && rm custommime'
' && rm custommime',
shell=True,
stderr=STDOUT,
)
if FILE_CODE != 0:
sys.exit('Failed to properly compile magic file\n{}'.format(FILE_OUTPUT))
setup(
name=MODULE_NAME,
version='0.2.12',
description='Helper functions for file type generation',
author='Johannes vom Dorp',
url='https://github.com/fkie-cad/fact_helper_file',
install_requires=['python-magic'],
python_requires='>=3.5',
packages=[MODULE_NAME, ],
package_data={MODULE_NAME: [str(MIME_DIR.parent / 'bin' / 'custommime.mgc'), ]}
)
if process.returncode != 0:
sys.stderr.write(f'Failed to properly compile magic file\n{process.stdout}\n')
sys.exit(1)
setup()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment