Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Core Modules
dune-common
Commits
56bb6619
Commit
56bb6619
authored
5 years ago
by
Andreas Dedner
Browse files
Options
Downloads
Patches
Plain Diff
tried to add a lock to avoid race conditions when multiple processes need to generate dune-py
parent
45d440c3
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!790
Feature/add python bindings
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
module.py
+41
-27
41 additions, 27 deletions
module.py
with
41 additions
and
27 deletions
module.py
+
41
−
27
View file @
56bb6619
...
...
@@ -522,39 +522,53 @@ def get_cmake_definitions():
return
definitions
try
:
from
portalocker
import
Lock
from
portalocker.constants
import
LOCK_EX
,
LOCK_SH
except
:
class
Lock
:
def
__init__
(
*
args
,
**
kwargs
):
pass
def
__enter__
(
self
):
pass
def
__exit__
(
self
,
*
args
):
pass
LOCK_EX
=
None
LOCK_SH
=
None
def
make_dune_py_module
(
dune_py_dir
=
None
):
if
dune_py_dir
is
None
:
dune_py_dir
=
get_dune_py_dir
()
descFile
=
os
.
path
.
join
(
dune_py_dir
,
'
dune.module
'
)
if
not
os
.
path
.
isfile
(
descFile
):
logger
.
info
(
'
Creating new dune-py module in
'
+
dune_py_dir
)
if
not
os
.
path
.
isdir
(
dune_py_dir
):
os
.
makedirs
(
dune_py_dir
)
# create python/dune/generated
generated_dir_rel
=
os
.
path
.
join
(
'
python
'
,
'
dune
'
,
'
generated
'
)
generated_dir
=
os
.
path
.
join
(
dune_py_dir
,
generated_dir_rel
)
if
not
os
.
path
.
isdir
(
generated_dir
):
os
.
makedirs
(
generated_dir
)
cmake_content
=
[
'
add_executable(generated_test EXCLUDE_FROM_ALL generated_test.cc)
'
,
'
add_dune_mpi_flags(generated_test)
'
,
'
target_compile_definitions(generated_test PRIVATE USING_DUNE_PYTHON)
'
,
'
target_link_libraries(generated_test ${DUNE_LIBS})
'
,
'
file(WRITE
"
${CMAKE_CURRENT_BINARY_DIR}/__init__.py
"
)
'
,
''
,
'
# The builder will append rules for dynamically generated modules, here
'
]
project
.
write_cmake_file
(
generated_dir
,
cmake_content
)
with
open
(
os
.
path
.
join
(
generated_dir
,
'
generated_test.cc
'
),
'
w
'
)
as
file
:
file
.
write
(
'
#include <config.h>
\n\n
'
)
file
.
write
(
'
#define USING_DUNE_PYTHON 1
\n\n
'
)
file
.
write
(
'
\n
#include
"
generated_module.hh
"
\n
'
)
modules
,
_
=
select_modules
()
description
=
Description
(
module
=
'
dune-py
'
,
version
=
get_dune_py_version
(),
maintainer
=
'
dune@lists.dune-project.org
'
,
depends
=
list
(
modules
.
values
()))
logger
.
debug
(
'
dune-py will depend on
'
+
'
'
.
join
([
m
+
(
'
'
+
str
(
c
)
if
c
else
''
)
for
m
,
c
in
description
.
depends
]))
project
.
make_project
(
dune_py_dir
,
description
,
subdirs
=
[
generated_dir
])
os
.
makedirs
(
dune_py_dir
,
exist_ok
)
with
Lock
(
os
.
path
.
join
(
self
.
dune_py_dir
,
'
lock-module.lock
'
),
flags
=
LOCK_EX
):
logger
.
info
(
'
Creating new dune-py module in
'
+
dune_py_dir
)
# create python/dune/generated
generated_dir_rel
=
os
.
path
.
join
(
'
python
'
,
'
dune
'
,
'
generated
'
)
generated_dir
=
os
.
path
.
join
(
dune_py_dir
,
generated_dir_rel
)
if
not
os
.
path
.
isdir
(
generated_dir
):
os
.
makedirs
(
generated_dir
)
cmake_content
=
[
'
add_executable(generated_test EXCLUDE_FROM_ALL generated_test.cc)
'
,
'
add_dune_mpi_flags(generated_test)
'
,
'
target_compile_definitions(generated_test PRIVATE USING_DUNE_PYTHON)
'
,
'
target_link_libraries(generated_test ${DUNE_LIBS})
'
,
'
file(WRITE
"
${CMAKE_CURRENT_BINARY_DIR}/__init__.py
"
)
'
,
''
,
'
# The builder will append rules for dynamically generated modules, here
'
]
project
.
write_cmake_file
(
generated_dir
,
cmake_content
)
with
open
(
os
.
path
.
join
(
generated_dir
,
'
generated_test.cc
'
),
'
w
'
)
as
file
:
file
.
write
(
'
#include <config.h>
\n\n
'
)
file
.
write
(
'
#define USING_DUNE_PYTHON 1
\n\n
'
)
file
.
write
(
'
\n
#include
"
generated_module.hh
"
\n
'
)
modules
,
_
=
select_modules
()
description
=
Description
(
module
=
'
dune-py
'
,
version
=
get_dune_py_version
(),
maintainer
=
'
dune@lists.dune-project.org
'
,
depends
=
list
(
modules
.
values
()))
logger
.
debug
(
'
dune-py will depend on
'
+
'
'
.
join
([
m
+
(
'
'
+
str
(
c
)
if
c
else
''
)
for
m
,
c
in
description
.
depends
]))
project
.
make_project
(
dune_py_dir
,
description
,
subdirs
=
[
generated_dir
])
else
:
description
=
Description
(
descFile
)
if
description
.
name
!=
'
dune-py
'
:
...
...
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