Skip to content

Commit

Permalink
chore(sca): add flag to disable subproject change detection (#335)
Browse files Browse the repository at this point in the history
Adds a new flag to pass from the app to the CLI that forces the CLI to
resolve
dependencies for all subprojects, all the time (even for diff scans).
Some
customers want this so that we get a full picture of their dependencies
for
every branch.

- [x] I ran `make setup && make` to update the generated code after
editing a `.atd` file (TODO: have a CI check)
- [x] I made sure we're still backward compatible with old versions of
the CLI.
For example, the Semgrep backend need to still be able to *consume* data
	  generated by Semgrep 1.50.0.
See
https://atd.readthedocs.io/en/latest/atdgen-tutorial.html#smooth-protocol-upgrades
	  Note that the types related to the semgrep-core JSON output or the
	  semgrep-core RPC do not need to be backward compatible!
  • Loading branch information
bkettle authored Jan 15, 2025
1 parent 1d13c0e commit 147dcde
Show file tree
Hide file tree
Showing 10 changed files with 555 additions and 125 deletions.
74 changes: 71 additions & 3 deletions ast_generic_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5807,15 +5807,15 @@ def to_json_string(self, **kw: Any) -> str:
class ImportFrom:
"""Original type: directive = [ ... | ImportFrom of ... | ... ]"""

value: Tuple[Tok, ModuleName, List[Tuple[Alias, Optional[Alias]]]]
value: Tuple[Tok, ModuleName, List[ImportFromKind]]

@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'ImportFrom'

def to_json(self) -> Any:
return ['ImportFrom', (lambda x: [(lambda x: x.to_json())(x[0]), (lambda x: x.to_json())(x[1]), _atd_write_list((lambda x: [(lambda x: x.to_json())(x[0]), _atd_write_nullable((lambda x: x.to_json()))(x[1])] if isinstance(x, tuple) and len(x) == 2 else _atd_bad_python('tuple of length 2', x)))(x[2])] if isinstance(x, tuple) and len(x) == 3 else _atd_bad_python('tuple of length 3', x))(self.value)]
return ['ImportFrom', (lambda x: [(lambda x: x.to_json())(x[0]), (lambda x: x.to_json())(x[1]), _atd_write_list((lambda x: x.to_json()))(x[2])] if isinstance(x, tuple) and len(x) == 3 else _atd_bad_python('tuple of length 3', x))(self.value)]

def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)
Expand Down Expand Up @@ -5945,7 +5945,7 @@ def from_json(cls, x: Any) -> 'Directive':
if isinstance(x, List) and len(x) == 2:
cons = x[0]
if cons == 'ImportFrom':
return cls(ImportFrom((lambda x: (Tok.from_json(x[0]), ModuleName.from_json(x[1]), _atd_read_list((lambda x: (Alias.from_json(x[0]), _atd_read_nullable(Alias.from_json)(x[1])) if isinstance(x, list) and len(x) == 2 else _atd_bad_json('array of length 2', x)))(x[2])) if isinstance(x, list) and len(x) == 3 else _atd_bad_json('array of length 3', x))(x[1])))
return cls(ImportFrom((lambda x: (Tok.from_json(x[0]), ModuleName.from_json(x[1]), _atd_read_list(ImportFromKind.from_json)(x[2])) if isinstance(x, list) and len(x) == 3 else _atd_bad_json('array of length 3', x))(x[1])))
if cons == 'ImportAs':
return cls(ImportAs((lambda x: (Tok.from_json(x[0]), ModuleName.from_json(x[1]), _atd_read_nullable(Alias.from_json)(x[2])) if isinstance(x, list) and len(x) == 3 else _atd_bad_json('array of length 3', x))(x[1])))
if cons == 'ImportAll':
Expand Down Expand Up @@ -7331,6 +7331,74 @@ def from_json_string(cls, x: str) -> 'IdInfo':
def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)

@dataclass
class Direct:
"""Original type: import_from_kind = [ ... | Direct of ... | ... ]"""

value: Alias

@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Direct'

def to_json(self) -> Any:
return ['Direct', (lambda x: x.to_json())(self.value)]

def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)


@dataclass
class Aliased:
"""Original type: import_from_kind = [ ... | Aliased of ... | ... ]"""

value: Tuple[Ident, Alias]

@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return 'Aliased'

def to_json(self) -> Any:
return ['Aliased', (lambda x: [(lambda x: x.to_json())(x[0]), (lambda x: x.to_json())(x[1])] if isinstance(x, tuple) and len(x) == 2 else _atd_bad_python('tuple of length 2', x))(self.value)]

def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)


@dataclass
class ImportFromKind:
"""Original type: import_from_kind = [ ... ]"""

value: Union[Direct, Aliased]

@property
def kind(self) -> str:
"""Name of the class representing this variant."""
return self.value.kind

@classmethod
def from_json(cls, x: Any) -> 'ImportFromKind':
if isinstance(x, List) and len(x) == 2:
cons = x[0]
if cons == 'Direct':
return cls(Direct(Alias.from_json(x[1])))
if cons == 'Aliased':
return cls(Aliased((lambda x: (Ident.from_json(x[0]), Alias.from_json(x[1])) if isinstance(x, list) and len(x) == 2 else _atd_bad_json('array of length 2', x))(x[1])))
_atd_bad_json('ImportFromKind', x)
_atd_bad_json('ImportFromKind', x)

def to_json(self) -> Any:
return self.value.to_json()

@classmethod
def from_json_string(cls, x: str) -> 'ImportFromKind':
return cls.from_json(json.loads(x))

def to_json_string(self, **kw: Any) -> str:
return json.dumps(self.to_json(), **kw)

@dataclass
class Item:
"""Original type: item"""
Expand Down
Loading

0 comments on commit 147dcde

Please sign in to comment.