Skip to content

Commit

Permalink
Fix setup for pypi
Browse files Browse the repository at this point in the history
  • Loading branch information
serpilliere committed Dec 11, 2019
1 parent a900c85 commit a46acb0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


<p align="center">
<img src="doc/logo_miasm.png">
<img src="https://raw.githubusercontent.com/cea-sec/miasm/master/doc/logo_miasm.png">
</p>


Expand Down
58 changes: 57 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from distutils.core import setup, Extension
from distutils.util import get_platform
from distutils.sysconfig import get_python_lib, get_config_vars
from distutils.dist import DistributionMetadata
from distutils.command.install_data import install_data
from tempfile import TemporaryFile
import io
import os
import platform
Expand All @@ -19,6 +22,20 @@ def set_extension_compile_args(extension):
lib_name = abs_lib_path + '.so'
extension.extra_link_args = [ '-Wl,-install_name,' + lib_name]


class smart_install_data(install_data):
"""Replacement for distutils.command.install_data to handle
configuration files location.
"""
def run(self):
# install files to /etc when target was /usr(/local)/etc
self.data_files = [
(path, files) for path, files in self.data_files
if path # skip README.md or any file with an empty path
]
return install_data.run(self)


def buil_all():
packages=[
"miasm",
Expand Down Expand Up @@ -163,20 +180,23 @@ def buil_all():
name = "miasm",
version = __import__("miasm").VERSION,
packages = packages,
data_files=[('', ["README.md"])],
package_data = {
"miasm": [
"jitter/*.h",
"jitter/arch/*.h",
"VERSION"
]
},
cmdclass={"install_data": smart_install_data},
ext_modules = ext_modules,
# Metadata
author = "Fabrice Desclaux",
author_email = "[email protected]",
description = "Machine code manipulation library",
license = "GPLv2",
long_description=io.open('README.md', encoding='utf-8').read(),
long_description=long_description,
long_description_content_type=long_description_content_type,
keywords = [
"reverse engineering",
"disassembler",
Expand All @@ -185,6 +205,12 @@ def buil_all():
"intermediate representation",
"assembler",
],
classifiers=[
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.6",
],
url = "http://miasm.re",
)
except SystemExit as e:
Expand Down Expand Up @@ -229,5 +255,35 @@ def buil_all():
print("Copying", lib, "to", dst)
copy2(lib, dst)


with io.open(os.path.join(os.path.abspath(os.path.dirname('__file__')),
'README.md'), encoding='utf-8') as fdesc:
long_description = fdesc.read()
long_description_content_type = 'text/markdown'


# Monkey patching (distutils does not handle Description-Content-Type
# from long_description_content_type parameter in setup()).
_write_pkg_file_orig = DistributionMetadata.write_pkg_file


def _write_pkg_file(self, file):
with TemporaryFile(mode="w+") as tmpfd:
_write_pkg_file_orig(self, tmpfd)
tmpfd.seek(0)
for line in tmpfd:
if line.startswith('Metadata-Version: '):
file.write('Metadata-Version: 2.1\n')
elif line.startswith('Description: '):
file.write('Description-Content-Type: %s; charset=UTF-8\n' %
long_description_content_type)
file.write(line)
else:
file.write(line)


DistributionMetadata.write_pkg_file = _write_pkg_file


buil_all()

0 comments on commit a46acb0

Please sign in to comment.