Skip to content

Commit

Permalink
Significant improvemnts to python module build. (#120)
Browse files Browse the repository at this point in the history
= Add a "dist" command to setup.py, to automatically buld python module distrbution.

= Change Makefile.win32 to build multiple python modules.
  • Loading branch information
manugarg committed Mar 23, 2022
1 parent ed2b0f4 commit 7bce167
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
23 changes: 7 additions & 16 deletions src/Makefile.win32
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ pacparser.dll: pacparser.o spidermonkey/js.lib
pacparser.lib: pacparser.dll pacparser.def
lib /machine:i386 /def:pacparser.def

pactester: pactester.c pacparser.h pacparser.dll
$(CC) pactester.c -o pactester -lpacparser -L. -I.
pactester: pactester.c pacparser.h pacparser.o
$(CC) pactester.c pacparser.o -o pactester -ljs -Lspidermonkey -lws2_32

dist: pacparser.dll pactester pacparser.lib
if exist dist rmdir /s /q dist
Expand All @@ -83,21 +83,12 @@ pymod: pacparser.h pacparser.dll pacparser.o js.lib
cd pymod && $(PYTHON) setup.py build --compiler=mingw32
cd .. && $(PYTHON) tests/runtests.py

pymod37: pacparser.h pacparser.dll
cd pymod && py -3.7 setup.py build --compiler=mingw32
cd .. && py -3.7 tests\runtests.py
pymod-%: pacparser.h pacparser.dll pacparser.o js.lib
cd pymod && py -$* setup.py build --compiler=mingw32
cd .. && py -$* tests\runtests.py

pymod38: pacparser.h pacparser.dll
cd pymod && py -3.8 setup.py build --compiler=mingw32
cd .. && py -3.8 tests\runtests.py

pymod39: pacparser.h pacparser.dll
cd pymod && py -3.9 setup.py build --compiler=mingw32
cd .. && py -3.9 tests\runtests.py

pymod310: pacparser.h pacparser.dll
cd pymod && py -3.10 setup.py build --compiler=mingw32
cd .. && py -3.10 tests\runtests.py
pymod-dist-%:
cd pymod && py -$* setup.py dist

clean:
$(RM) pacparser.dll *.lib pacparser.def pacparser.exp pacparser.o pactester.exe libpacparser.a
Expand Down
43 changes: 41 additions & 2 deletions src/pymod/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,48 @@
identifying python setup and setting up some environment variables needed by
Makefiles.
"""
import sys
import glob
import os
import platform
import shutil
import sys

from unittest.mock import patch
import distutils
from setuptools import setup, Extension

import distutils.cmd

class DistCmd(distutils.cmd.Command):
"""Build pacparser python distribution."""

description = 'Build pacparser python distribution.'
user_options = []

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
setup_dir = os.path.dirname(os.path.join(os.getcwd(), sys.argv[0]))
py_ver = '.'.join([str(x) for x in sys.version_info[0:2]])
pp_ver = os.environ.get('PACPARSER_VERSION', '1.0.0')

pacparser_module_path = glob.glob(
os.path.join(setup_dir, 'build', 'lib*%s' % py_ver))[0]
sys.path.insert(0, pacparser_module_path)
import pacparser
pp_ver = pacparser.version()

dist = 'pacparser-python%s-%s-%s-%s' % (
py_ver.replace('.',''), pp_ver, platform.system(), platform.machine())
dist = dist.lower()
os.mkdir(dist)
shutil.copytree(os.path.join(pacparser_module_path, 'pacparser'), dist+'/pacparser')


@patch('distutils.cygwinccompiler.get_msvcr')
def main(patched_func):
pacparser_version = os.environ.get('PACPARSER_VERSION', '1.0.0')
Expand All @@ -53,7 +88,11 @@ def main(patched_func):
libraries = libraries,
extra_link_args = extra_link_args,
extra_objects = extra_objects)
setup (name = 'pacparser',
setup (
cmdclass={
'dist': DistCmd,
},
name = 'pacparser',
version = pacparser_version,
description = 'Pacparser package',
author = 'Manu Garg',
Expand Down

0 comments on commit 7bce167

Please sign in to comment.