Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils-sfg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
pystencils-sfg
Commits
f56a6c68
Commit
f56a6c68
authored
1 year ago
by
Frederik Hennig
Browse files
Options
Downloads
Patches
Plain Diff
refactored indentation
parent
e02732bf
No related branches found
No related tags found
No related merge requests found
Pipeline
#57753
passed
1 year ago
Stage: pretest
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/pystencilssfg/configuration.py
+3
-3
3 additions, 3 deletions
src/pystencilssfg/configuration.py
src/pystencilssfg/context.py
+11
-4
11 additions, 4 deletions
src/pystencilssfg/context.py
src/pystencilssfg/emitters/cpu/basic_cpu.py
+3
-8
3 additions, 8 deletions
src/pystencilssfg/emitters/cpu/basic_cpu.py
with
17 additions
and
15 deletions
src/pystencilssfg/configuration.py
+
3
−
3
View file @
f56a6c68
...
@@ -7,11 +7,10 @@ from os import path
...
@@ -7,11 +7,10 @@ from os import path
from
enum
import
Enum
,
auto
from
enum
import
Enum
,
auto
from
dataclasses
import
dataclass
,
replace
,
asdict
,
InitVar
from
dataclasses
import
dataclass
,
replace
,
asdict
,
InitVar
from
argparse
import
ArgumentParser
from
argparse
import
ArgumentParser
from
textwrap
import
indent
from
importlib
import
util
as
iutil
from
importlib
import
util
as
iutil
from
jinja2.filters
import
do_indent
from
.exceptions
import
SfgException
from
.exceptions
import
SfgException
HEADER_FILE_EXTENSIONS
=
{
'
h
'
,
'
hpp
'
}
HEADER_FILE_EXTENSIONS
=
{
'
h
'
,
'
hpp
'
}
...
@@ -39,7 +38,8 @@ class SfgCodeStyle:
...
@@ -39,7 +38,8 @@ class SfgCodeStyle:
indent_width
:
int
=
2
indent_width
:
int
=
2
def
indent
(
self
,
s
:
str
):
def
indent
(
self
,
s
:
str
):
return
do_indent
(
s
,
self
.
indent_width
,
first
=
True
)
prefix
=
"
"
*
self
.
indent_width
return
indent
(
s
,
prefix
)
@dataclass
@dataclass
...
...
This diff is collapsed.
Click to expand it.
src/pystencilssfg/context.py
+
11
−
4
View file @
f56a6c68
...
@@ -15,7 +15,7 @@ class SfgContext:
...
@@ -15,7 +15,7 @@ class SfgContext:
self
.
_code_namespace
:
str
|
None
=
None
self
.
_code_namespace
:
str
|
None
=
None
# Source Components
# Source Components
self
.
_prelude
:
list
[
str
]
=
[]
self
.
_prelude
:
str
=
""
self
.
_includes
:
set
[
SfgHeaderInclude
]
=
set
()
self
.
_includes
:
set
[
SfgHeaderInclude
]
=
set
()
self
.
_definitions
:
list
[
str
]
=
[]
self
.
_definitions
:
list
[
str
]
=
[]
self
.
_kernel_namespaces
=
{
self
.
_default_kernel_namespace
.
name
:
self
.
_default_kernel_namespace
}
self
.
_kernel_namespaces
=
{
self
.
_default_kernel_namespace
.
name
:
self
.
_default_kernel_namespace
}
...
@@ -58,12 +58,19 @@ class SfgContext:
...
@@ -58,12 +58,19 @@ class SfgContext:
# Prelude, Includes, Definitions, Namespace
# Prelude, Includes, Definitions, Namespace
# ----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
def
prelude
(
self
)
->
Generator
[
str
,
None
,
None
]:
@property
def
prelude_comment
(
self
)
->
str
:
"""
The prelude is a comment block printed at the top of both generated files.
"""
"""
The prelude is a comment block printed at the top of both generated files.
"""
yield
from
self
.
_prelude
return
self
.
_prelude
def
append_to_prelude
(
self
,
code_str
:
str
):
def
append_to_prelude
(
self
,
code_str
:
str
):
self
.
_prelude
.
append
(
code_str
)
if
self
.
_prelude
:
self
.
_prelude
+=
"
\n
"
self
.
_prelude
+=
code_str
if
not
code_str
.
endswith
(
"
\n
"
):
self
.
_prelude
+=
"
\n
"
def
includes
(
self
)
->
Generator
[
SfgHeaderInclude
,
None
,
None
]:
def
includes
(
self
)
->
Generator
[
SfgHeaderInclude
,
None
,
None
]:
"""
Includes of headers. Public includes are added to the header file, private includes
"""
Includes of headers. Public includes are added to the header file, private includes
...
...
This diff is collapsed.
Click to expand it.
src/pystencilssfg/emitters/cpu/basic_cpu.py
+
3
−
8
View file @
f56a6c68
from
typing
import
cast
from
typing
import
cast
from
jinja2
import
Environment
,
PackageLoader
,
StrictUndefined
from
jinja2
import
Environment
,
PackageLoader
,
StrictUndefined
from
textwrap
import
indent
from
os
import
path
from
os
import
path
...
@@ -59,13 +60,7 @@ class BasicCpuEmitter:
...
@@ -59,13 +60,7 @@ class BasicCpuEmitter:
def
get_prelude_comment
(
ctx
:
SfgContext
):
def
get_prelude_comment
(
ctx
:
SfgContext
):
prelude_lines
=
[]
if
not
ctx
.
prelude_comment
:
for
p
in
ctx
.
prelude
():
prelude_lines
+=
p
.
splitlines
()
prelude_lines
+=
[
""
]
# empty line in-between
prelude_lines
=
prelude_lines
[:
-
1
]
if
not
prelude_lines
:
return
""
return
""
return
"
\n
"
.
join
([
"
/**
"
]
+
[
f
"
*
{
line
}
"
for
line
in
prelude_lines
]
+
[
"
*/
"
])
return
"
/*
\n
"
+
indent
(
ctx
.
prelude_comment
,
"
*
"
,
predicate
=
lambda
_
:
True
)
+
"
*/
\n
"
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