Skip to content

Commit aeba014

Browse files
Address review comments
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
1 parent 26fe35e commit aeba014

File tree

4 files changed

+133
-129
lines changed

4 files changed

+133
-129
lines changed

scanpipe/pipelines/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ def __init__(self, run_instance):
182182
self.selected_groups = run_instance.selected_groups
183183
self.selected_steps = run_instance.selected_steps
184184

185+
self.ecosystem_config = None
186+
185187
@classmethod
186188
def get_initial_steps(cls):
187189
"""Add the ``download_inputs`` step as an initial step if enabled."""

scanpipe/pipelines/deploy_to_develop.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
from scanpipe import pipes
2525
from scanpipe.pipelines import Pipeline
2626
from scanpipe.pipes import d2d
27+
from scanpipe.pipes import d2d_config
2728
from scanpipe.pipes import flag
2829
from scanpipe.pipes import input
2930
from scanpipe.pipes import matchcode
3031
from scanpipe.pipes import purldb
3132
from scanpipe.pipes import scancode
32-
from scanpipe.pipes.d2d_config import DefaultEcosystemConfig
3333

3434

35-
class DeployToDevelop(Pipeline, DefaultEcosystemConfig):
35+
class DeployToDevelop(Pipeline):
3636
"""
3737
Establish relationships between two code trees: deployment and development.
3838
@@ -133,7 +133,7 @@ def flag_whitespace_files(self):
133133

134134
def load_ecosystem_config(self):
135135
"""Load ecosystem specific configurations for d2d steps for selected options."""
136-
d2d.load_ecosystem_config(pipeline=self, options=self.selected_groups)
136+
d2d_config.load_ecosystem_config(pipeline=self, options=self.selected_groups)
137137

138138
@optional_step("Ruby")
139139
def load_ecosystem_config_ruby(self):
@@ -285,12 +285,12 @@ def perform_house_keeping_tasks(self):
285285
d2d.handle_dangling_deployed_legal_files(project=self.project, logger=self.log)
286286
d2d.ignore_unmapped_resources_from_config(
287287
project=self.project,
288-
patterns_to_ignore=self.deployed_resource_path_exclusions,
288+
patterns_to_ignore=self.ecosystem_config.deployed_resource_path_exclusions,
289289
logger=self.log,
290290
)
291291
d2d.match_unmapped_resources(
292292
project=self.project,
293-
matched_extensions=self.purldb_resource_extensions,
293+
matched_extensions=self.ecosystem_config.purldb_resource_extensions,
294294
logger=self.log,
295295
)
296296
d2d.flag_undeployed_resources(project=self.project)
@@ -326,5 +326,5 @@ def flag_deployed_from_resources_with_missing_license(self):
326326
"""Update the status for deployed from files with missing license."""
327327
d2d.flag_deployed_from_resources_with_missing_license(
328328
self.project,
329-
doc_extensions=self.doc_extensions,
329+
doc_extensions=self.ecosystem_config.doc_extensions,
330330
)

scanpipe/pipes/d2d.py

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,6 @@
7070
TO = "to/"
7171

7272

73-
ECOSYSTEM_CONFIGS = [
74-
d2d_config.DefaultEcosystemConfig,
75-
d2d_config.JavaEcosystemConfig,
76-
d2d_config.JavaScriptEcosystemConfig,
77-
d2d_config.RubyEcosystemConfig,
78-
d2d_config.RustEcosystemConfig,
79-
d2d_config.GoEcosystemConfig,
80-
]
81-
8273

8374
def get_inputs(project):
8475
"""
@@ -128,55 +119,6 @@ def get_best_path_matches(to_resource, matches):
128119
return matches
129120

130121

131-
def load_ecosystem_config(pipeline, options):
132-
"""
133-
Add ecosystem specific configurations for each ecosystem selected
134-
as `options` to the `pipeline`.
135-
"""
136-
configs_by_ecosystem = {
137-
ecosystem.ecosystem_option: ecosystem for ecosystem in ECOSYSTEM_CONFIGS
138-
}
139-
140-
# Add default configurations which are common accross ecosystems
141-
add_ecosystem_config(
142-
pipeline=pipeline,
143-
configs_by_ecosystem=configs_by_ecosystem,
144-
selected_option="Default",
145-
)
146-
147-
# Add configurations for each selected ecosystem
148-
for selected_option in options:
149-
if selected_option not in configs_by_ecosystem:
150-
continue
151-
152-
add_ecosystem_config(
153-
pipeline=pipeline,
154-
configs_by_ecosystem=configs_by_ecosystem,
155-
selected_option=selected_option,
156-
)
157-
158-
159-
def add_ecosystem_config(pipeline, configs_by_ecosystem, selected_option):
160-
d2d_pipeline_configs = [
161-
"purldb_package_extensions",
162-
"purldb_resource_extensions",
163-
"deployed_resource_path_exclusions",
164-
]
165-
166-
ecosystem_config = configs_by_ecosystem.get(selected_option)
167-
168-
for pipeline_config in d2d_pipeline_configs:
169-
config_value = getattr(ecosystem_config, pipeline_config)
170-
pipeline_config_value = getattr(pipeline, pipeline_config)
171-
if config_value:
172-
if not pipeline_config_value:
173-
new_config_value = config_value
174-
else:
175-
new_config_value = pipeline_config_value.extend(config_value)
176-
177-
setattr(pipeline, pipeline_config, new_config_value)
178-
179-
180122
def get_from_files_for_scanning(resources):
181123
"""
182124
Return resources in the "from/" side which has been mapped to the "to/"

scanpipe/pipes/d2d_config.py

Lines changed: 125 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -21,95 +21,155 @@
2121
# Visit https://github.com/aboutcode-org/scancode.io for support and download.
2222

2323

24+
from dataclasses import dataclass, field
25+
26+
27+
28+
@dataclass
2429
class EcosystemConfig:
2530
"""
26-
Base class for ecosystem specific configurations to be defined
27-
for each ecosystems.
31+
Base class for ecosystem-specific configurations to be defined
32+
for each ecosystem.
2833
"""
2934

3035
# This should be defined for each ecosystem which
3136
# are options in the pipelines
32-
ecosystem_option = None
37+
ecosystem_option: str = "Default"
3338

3439
# These are extensions for packages of this ecosystem which
35-
# needs to be matched from purldb
36-
purldb_package_extensions = []
40+
# need to be matched from purldb
41+
purldb_package_extensions: list = field(default_factory=list)
3742

3843
# These are extensions for resources of this ecosystem which
39-
# needs to be macthed from purldb
40-
purldb_resource_extensions = []
44+
# need to be matched from purldb
45+
purldb_resource_extensions: list = field(default_factory=list)
4146

4247
# Extensions for document files which do not require review
43-
doc_extensions = []
48+
doc_extensions: list = field(default_factory=list)
4449

4550
# Paths in the deployed binaries/archives (on the to/ side) which
4651
# do not need review even if they are not matched to the source side
47-
deployed_resource_path_exclusions = []
52+
deployed_resource_path_exclusions: list = field(default_factory=list)
4853

49-
# Paths in the developement/source archive (on the from/ side) which
54+
# Paths in the development/source archive (on the from/ side) which
5055
# should not be considered even if unmapped to the deployed side when
51-
# assesing what to review on the deployed side
52-
devel_resource_path_exclusions = []
56+
# assessing what to review on the deployed side
57+
devel_resource_path_exclusions: list = field(default_factory=list)
5358

54-
# Symbols which are found in ecosystem specific standard libraries
59+
# Symbols which are found in ecosystem-specific standard libraries
5560
# which are not so useful in mapping
56-
standard_symbols_to_exclude = []
57-
58-
59-
class DefaultEcosystemConfig(EcosystemConfig):
60-
"""Configurations which are common across multiple ecosystems."""
61-
62-
ecosystem_option = "Default"
63-
purldb_package_extensions = [".zip", ".tar.gz", ".tar.xz"]
64-
devel_resource_path_exclusions = ["*/tests/*"]
65-
doc_extensions = [
66-
".pdf",
67-
".doc",
68-
".docx",
69-
".ppt",
70-
".pptx",
71-
".tex",
72-
".odt",
73-
".odp",
74-
]
61+
standard_symbols_to_exclude: list = field(default_factory=list)
62+
63+
64+
# Dictionary of ecosystem configurations
65+
ECOSYSTEM_CONFIGS = {
66+
"Default": EcosystemConfig(
67+
purldb_package_extensions=[".zip", ".tar.gz", ".tar.xz"],
68+
devel_resource_path_exclusions=["*/tests/*"],
69+
doc_extensions=[
70+
".pdf",
71+
".doc",
72+
".docx",
73+
".ppt",
74+
".pptx",
75+
".tex",
76+
".odt",
77+
".odp",
78+
],
79+
),
80+
"Java": EcosystemConfig(
81+
ecosystem_option="Java",
82+
purldb_package_extensions=[".jar", ".war"],
83+
purldb_resource_extensions=[".class"],
84+
),
85+
"JavaScript": EcosystemConfig(
86+
ecosystem_option="JavaScript",
87+
purldb_resource_extensions=[
88+
".map",
89+
".js",
90+
".mjs",
91+
".ts",
92+
".d.ts",
93+
".jsx",
94+
".tsx",
95+
".css",
96+
".scss",
97+
".less",
98+
".sass",
99+
".soy",
100+
],
101+
),
102+
"Go": EcosystemConfig(
103+
ecosystem_option="Go",
104+
purldb_resource_extensions=[".go"],
105+
),
106+
"Rust": EcosystemConfig(
107+
ecosystem_option="Rust",
108+
purldb_resource_extensions=[".rs"],
109+
),
110+
"Ruby": EcosystemConfig(
111+
ecosystem_option="Ruby",
112+
purldb_package_extensions=[".gem"],
113+
purldb_resource_extensions=[".rb"],
114+
deployed_resource_path_exclusions=["*checksums.yaml.gz*", "*metadata.gz*"],
115+
),
116+
}
117+
118+
119+
def get_ecosystem_config(ecosystem):
120+
"""Return the ``ecosystem`` config."""
121+
return ECOSYSTEM_CONFIGS.get(ecosystem, ECOSYSTEM_CONFIGS["Default"])
122+
123+
124+
def load_ecosystem_config(pipeline, options):
125+
"""
126+
Add ecosystem specific configurations for each ecosystem selected
127+
as `options` to the `pipeline`. These configurations are used for:
128+
- which resource/package extensions to match to purldb
129+
- which source files to get source symbols from
130+
- which unmapped paths to ignore in deployed binaries
131+
"""
132+
configs_by_ecosystem = {
133+
ecosystem.ecosystem_option: ecosystem for ecosystem in ECOSYSTEM_CONFIGS.values()
134+
}
75135

136+
# Add default configurations which are common accross ecosystems
137+
pipeline.ecosystem_config = ECOSYSTEM_CONFIGS.get("Default")
76138

77-
class JavaEcosystemConfig(EcosystemConfig):
78-
ecosystem_option = "Java"
79-
purldb_package_extensions = [".jar", ".war"]
80-
purldb_resource_extensions = [".class"]
81-
82-
83-
class JavaScriptEcosystemConfig(EcosystemConfig):
84-
ecosystem_option = "JavaScript"
85-
purldb_resource_extensions = [
86-
".map",
87-
".js",
88-
".mjs",
89-
".ts",
90-
".d.ts",
91-
".jsx",
92-
".tsx",
93-
".css",
94-
".scss",
95-
".less",
96-
".sass",
97-
".soy",
98-
]
139+
# Add configurations for each selected ecosystem
140+
for selected_option in options:
141+
if selected_option not in configs_by_ecosystem:
142+
continue
143+
144+
add_ecosystem_config(
145+
pipeline_ecosystem_config=pipeline.ecosystem_config,
146+
configs_by_ecosystem=configs_by_ecosystem,
147+
selected_option=selected_option,
148+
)
99149

100150

101-
class GoEcosystemConfig(EcosystemConfig):
102-
ecosystem_option = "Go"
103-
purldb_resource_extensions = [".go"]
151+
def add_ecosystem_config(pipeline_ecosystem_config, configs_by_ecosystem, selected_option):
152+
"""
153+
Set the `pipeline_ecosystem_config` values from all the individual ecosystem based configurations
154+
defined in `configs_by_ecosystem`, based on pipeline `selected_option` which selects an
155+
ecosytem.
156+
"""
157+
d2d_pipeline_configs = [
158+
"purldb_package_extensions",
159+
"purldb_resource_extensions",
160+
"deployed_resource_path_exclusions",
161+
]
104162

163+
ecosystem_config = configs_by_ecosystem.get(selected_option)
105164

106-
class RustEcosystemConfig(EcosystemConfig):
107-
ecosystem_option = "Rust"
108-
purldb_resource_extensions = [".rs"]
165+
for config_name in d2d_pipeline_configs:
166+
config_value = getattr(ecosystem_config, config_name)
167+
pipeline_config_value = getattr(pipeline_ecosystem_config, config_name)
168+
if config_value:
169+
if not pipeline_config_value:
170+
new_config_value = config_value
171+
else:
172+
new_config_value = pipeline_config_value.extend(config_value)
109173

174+
setattr(pipeline_ecosystem_config, config_name, new_config_value)
110175

111-
class RubyEcosystemConfig(EcosystemConfig):
112-
ecosystem_option = "Ruby"
113-
purldb_package_extensions = [".gem"]
114-
purldb_resource_extensions = [".rb"]
115-
deployed_resource_path_exclusions = ["*checksums.yaml.gz*", "*metadata.gz*"]

0 commit comments

Comments
 (0)