Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit 229a80d

Browse files
committed
Fix build errors due to import order.
Parse __init__.py to find the version number instead of loading googleclouddebugger in setup.py. The native dependencies get built as part of the last stage of setup, so it's not safe to import the library anywhere in setup.py. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=113971723
1 parent 5c50e97 commit 229a80d

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/setup.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
"""Python Cloud Debugger build and packaging script."""
1616

17+
import ConfigParser
1718
from glob import glob
1819
import os
19-
import ConfigParser
20-
21-
from setuptools import setup, Extension
20+
import re
2221
from distutils import sysconfig
23-
import googleclouddebugger
22+
from setuptools import Extension
23+
from setuptools import setup
2424

2525

2626
def RemovePrefixes(optlist, bad_prefixes):
@@ -69,6 +69,20 @@ def ReadConfig(section, value, default):
6969
cvars.get('OPT').split(),
7070
['-g', '-O', '-Wstrict-prototypes']))
7171

72+
# Determine the current version of the package. The easiest way would be to
73+
# import "googleclouddebugger" and read its __version__ attribute.
74+
# Unfortunately we can't do that because "googleclouddebugger" depends on
75+
# "cdbg_native" that hasn't been built yet.
76+
version = None
77+
with open('googleclouddebugger/__init__.py', 'r') as init_file:
78+
version_pattern = re.compile(r"^\s*__version__\s*=\s*'([0-9.]*)'")
79+
for line in init_file:
80+
match = version_pattern.match(line)
81+
if match:
82+
version = match.groups()[0]
83+
print 'clouddebugger module version is {0}'.format(version)
84+
assert version
85+
7286
cdbg_native_module = Extension(
7387
'googleclouddebugger.cdbg_native',
7488
sources=glob('googleclouddebugger/*.cc'),
@@ -87,11 +101,11 @@ def ReadConfig(section, value, default):
87101
long_description=LONG_DESCRIPTION,
88102
url='https://github.com/GoogleCloudPlatform/cloud-debug-python',
89103
author='Google Inc.',
90-
version=googleclouddebugger.__version__,
104+
version=version,
91105
install_requires=['google-api-python-client'],
92106
packages=['googleclouddebugger'],
93107
ext_modules=[cdbg_native_module],
94-
license="Apache License, Version 2.0",
108+
license='Apache License, Version 2.0',
95109
keywords='google cloud debugger',
96110
classifiers=[
97111
'Programming Language :: Python :: 2.7',

0 commit comments

Comments
 (0)