Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tinyarray
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jörg Behrmann
tinyarray
Commits
be5ba866
Commit
be5ba866
authored
8 years ago
by
Christoph Groth
Browse files
Options
Downloads
Patches
Plain Diff
setup.py: add build configuration
parent
4ee86e4e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
setup.py
+102
-7
102 additions, 7 deletions
setup.py
with
103 additions
and
7 deletions
.gitignore
+
1
−
0
View file @
be5ba866
*~
*.pyc
*.so
build.conf
/tinyarray.egg-info/
/build/
/dist/
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
102
−
7
View file @
be5ba866
...
...
@@ -9,9 +9,13 @@
# top-level directory of this distribution and at
# https://gitlab.kwant-project.org/kwant/tinyarray.
from
__future__
import
print_function
import
subprocess
import
os
import
sys
import
collections
import
configparser
from
setuptools
import
setup
,
Extension
,
Command
from
sysconfig
import
get_platform
from
distutils.errors
import
DistutilsError
,
DistutilsModuleError
...
...
@@ -37,6 +41,93 @@ SAVED_VERSION_FILE = 'version'
distr_root
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
def
configure_extensions
(
exts
,
aliases
=
(),
build_summary
=
None
):
"""
Modify extension configuration according to the configuration file
`exts` must be a dict of (name, kwargs) tuples that can be used like this:
`Extension(name, **kwargs). This function modifies the kwargs according to
the configuration file.
This function modifies `sys.argv`.
"""
global
config_file
,
config_file_present
#### Determine the name of the configuration file.
config_file_option
=
'
--configfile
'
# Handle command line option
for
i
,
opt
in
enumerate
(
sys
.
argv
):
if
not
opt
.
startswith
(
config_file_option
):
continue
l
,
_
,
config_file
=
opt
.
partition
(
'
=
'
)
if
l
!=
config_file_option
or
not
config_file
:
print
(
'
error: Expecting {}=PATH
'
.
format
(
config_file_option
),
file
=
sys
.
stderr
)
exit
(
1
)
sys
.
argv
.
pop
(
i
)
break
else
:
config_file
=
'
build.conf
'
#### Read build configuration file.
configs
=
configparser
.
ConfigParser
()
try
:
with
open
(
config_file
)
as
f
:
configs
.
read_file
(
f
)
except
IOError
:
config_file_present
=
False
else
:
config_file_present
=
True
#### Handle section aliases.
for
short
,
long
in
aliases
:
if
short
in
configs
:
if
long
in
configs
:
print
(
'
Error: both {} and {} sections present in {}.
'
.
format
(
short
,
long
,
config_file
))
exit
(
1
)
configs
[
long
]
=
configs
[
short
]
del
configs
[
short
]
#### Apply config from file. Use [DEFAULT] section for missing sections.
defaultconfig
=
configs
.
defaults
()
for
name
,
kwargs
in
exts
.
items
():
config
=
configs
[
name
]
if
name
in
configs
else
defaultconfig
for
key
,
value
in
config
.
items
():
# Most, but not all, keys are lists of strings
if
key
==
'
language
'
:
pass
elif
key
==
'
optional
'
:
value
=
bool
(
int
(
value
))
else
:
value
=
value
.
split
()
if
key
==
'
define_macros
'
:
value
=
[
tuple
(
entry
.
split
(
'
=
'
,
1
))
for
entry
in
value
]
value
=
[(
entry
[
0
],
None
)
if
len
(
entry
)
==
1
else
entry
for
entry
in
value
]
if
key
in
kwargs
:
msg
=
'
Caution: user config in file {} shadows {}.{}.
'
if
build_summary
is
not
None
:
build_summary
.
append
(
msg
.
format
(
config_file
,
name
,
key
))
kwargs
[
key
]
=
value
kwargs
.
setdefault
(
'
depends
'
,
[]).
append
(
config_file
)
if
config
is
not
defaultconfig
:
del
configs
[
name
]
unknown_sections
=
configs
.
sections
()
if
unknown_sections
:
print
(
'
Error: Unknown sections in file {}: {}
'
.
format
(
config_file
,
'
,
'
.
join
(
unknown_sections
)))
exit
(
1
)
return
exts
def
get_version_from_git
():
try
:
p
=
subprocess
.
Popen
([
'
git
'
,
'
rev-parse
'
,
'
--show-toplevel
'
],
...
...
@@ -153,12 +244,15 @@ class our_sdist(sdist):
def
main
():
exts
=
[
Extension
(
'
tinyarray
'
,
language
=
'
c++
'
,
sources
=
[
'
src/arithmetic.cc
'
,
'
src/array.cc
'
,
'
src/functions.cc
'
],
depends
=
[
'
src/arithmetic.hh
'
,
'
src/array.hh
'
,
'
src/conversion.hh
'
,
'
src/functions.hh
'
])]
exts
=
collections
.
OrderedDict
([
(
'
tinyarray
'
,
dict
(
language
=
'
c++
'
,
sources
=
[
'
src/arithmetic.cc
'
,
'
src/array.cc
'
,
'
src/functions.cc
'
],
depends
=
[
'
src/arithmetic.hh
'
,
'
src/array.hh
'
,
'
src/conversion.hh
'
,
'
src/functions.hh
'
]))])
exts
=
configure_extensions
(
exts
)
classifiers
=
"""
\
Development Status :: 5 - Production/Stable
...
...
@@ -188,7 +282,8 @@ def main():
classifiers
=
classifiers
.
split
(
'
\n
'
),
cmdclass
=
{
'
build_ext
'
:
our_build_ext
,
'
sdist
'
:
our_sdist
},
ext_modules
=
exts
,
ext_modules
=
[
Extension
(
name
,
**
kwargs
)
for
name
,
kwargs
in
exts
.
items
()],
test_suite
=
'
nose.collector
'
,
tests_require
=
[
'
nose >= 1.0
'
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment