Unverified Commit 0dcee561 by René Helmke Committed by GitHub

Merge pull request #21 from fkie-cad/installation-bugfix

switched to pyproject.toml setup
parents 199365e8 67b31422
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] [tool.black]
line-length = 120 line-length = 120
skip-string-normalization = true skip-string-normalization = true
target-version = ['py37'] target-version = ["py37"]
[tool.pylint.main] [tool.pylint.main]
init-hook = 'import sys; sys.path.append("./src")' init-hook = 'import sys; sys.path.append("./src")'
......
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import annotations
import os import os
import sys import sys
from pathlib import Path from pathlib import Path
from subprocess import Popen, PIPE from subprocess import run, STDOUT
from setuptools import setup from setuptools import setup
MODULE_NAME = 'fact_helper_file' 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: class OperateInDirectory:
def __init__(self, target_directory: str): def __init__(self, target_directory: str | Path):
self._current_working_dir = None self._current_working_dir = None
self._target_directory = target_directory self._target_directory = target_directory
def __enter__(self): def __enter__(self):
self._current_working_dir = os.getcwd() self._current_working_dir = Path.cwd()
os.chdir(self._target_directory) os.chdir(self._target_directory)
def __exit__(self, *_): def __exit__(self, *_):
os.chdir(self._current_working_dir) os.chdir(self._current_working_dir)
def execute_shell_command(shell_command): BIN_DIR.mkdir(exist_ok=True)
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
with OperateInDirectory(MIME_DIR):
os.makedirs(str(MIME_DIR.parent / 'bin'), exist_ok=True) process = run(
with OperateInDirectory(str(MIME_DIR)):
FILE_OUTPUT, FILE_CODE = execute_shell_command(
'(cat custom_* > custommime)' '(cat custom_* > custommime)'
' && file -C -m custommime' ' && file -C -m custommime'
' && mv -f custommime.mgc ../bin/' ' && mv -f custommime.mgc ../bin/'
' && rm custommime' ' && rm custommime',
shell=True,
stderr=STDOUT,
) )
if FILE_CODE != 0: if process.returncode != 0:
sys.exit('Failed to properly compile magic file\n{}'.format(FILE_OUTPUT)) sys.stderr.write(f'Failed to properly compile magic file\n{process.stdout}\n')
sys.exit(1)
setup(
name=MODULE_NAME, setup()
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'), ]}
)
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