Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
patchwork/patchwork/config.py at main · bikini/patchwork · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
bikini
/
patchwork
Public
Notifications
You must be signed in to change notification settings
Fork
14
Star
145
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
main
Breadcrumbs
patchwork
/
patchwork
/
config.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
135 lines (114 loc) · 4.21 KB
main
Breadcrumbs
patchwork
/
patchwork
/
config.py
Copy path
Top
File metadata and controls
Code
Blame
135 lines (114 loc) · 4.21 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from
__future__
import
annotations
import
json
from
pathlib
import
Path
from
typing
import
Any
DEFAULT_CONFIG
:
dict
[
str
,
Any
]
=
{
"seed"
:
None
,
"layers"
:
3
,
"stage2_layers"
:
3
,
"rename"
:
True
,
"encrypt_strings"
:
True
,
"obfuscate_numbers"
:
True
,
"opaque_predicates"
:
True
,
"mba"
:
True
,
"junk_branches"
:
True
,
"lazy_funcs"
:
True
,
"anti_debug"
:
True
,
"abyss"
:
False
,
"abyss_functions"
: [],
"lower_fstrings"
:
True
,
"lower_match"
:
True
,
"keep"
: [],
"max_output_bytes"
:
None
,
"max_ratio"
:
None
,
"max_review_indicators"
:
None
,
}
BOOLEAN_KEYS
=
{
"rename"
,
"encrypt_strings"
,
"obfuscate_numbers"
,
"opaque_predicates"
,
"mba"
,
"junk_branches"
,
"lazy_funcs"
,
"anti_debug"
,
"abyss"
,
"lower_fstrings"
,
"lower_match"
,
}
INTEGER_KEYS
=
{
"seed"
,
"layers"
,
"stage2_layers"
,
"max_output_bytes"
,
"max_review_indicators"
}
FLOAT_KEYS
=
{
"max_ratio"
}
LIST_KEYS
=
{
"keep"
,
"abyss_functions"
}
class
ConfigError
(
ValueError
):
pass
def
load_config
(
path
:
str
|
Path
|
None
)
->
dict
[
str
,
Any
]:
if
path
is
None
:
return
{}
config_path
=
Path
(
path
)
try
:
raw
=
json
.
loads
(
config_path
.
read_text
(
encoding
=
"utf-8"
))
except
FileNotFoundError
as
exc
:
raise
ConfigError
(
f"config file not found:
{
config_path
}
"
)
from
exc
except
json
.
JSONDecodeError
as
exc
:
raise
ConfigError
(
f"invalid config JSON:
{
exc
}
"
)
from
exc
if
not
isinstance
(
raw
,
dict
):
raise
ConfigError
(
"config file must contain a JSON object"
)
unknown
=
sorted
(
set
(
raw
)
-
set
(
DEFAULT_CONFIG
))
if
unknown
:
raise
ConfigError
(
f"unknown config option(s):
{
', '
.
join
(
unknown
)
}
"
)
return
dict
(
raw
)
def
read_keep_file
(
path
:
str
|
Path
|
None
)
->
list
[
str
]:
if
path
is
None
:
return
[]
keep_path
=
Path
(
path
)
try
:
lines
=
keep_path
.
read_text
(
encoding
=
"utf-8"
).
splitlines
()
except
FileNotFoundError
as
exc
:
raise
ConfigError
(
f"keep file not found:
{
keep_path
}
"
)
from
exc
names
:
list
[
str
]
=
[]
for
line
in
lines
:
value
=
line
.
split
(
"#"
,
1
)[
0
].
strip
()
if
not
value
:
continue
names
.
extend
(
part
.
strip
()
for
part
in
value
.
split
(
","
)
if
part
.
strip
())
return
names
def
normalize_config
(
config
:
dict
[
str
,
Any
])
->
dict
[
str
,
Any
]:
normalized
=
dict
(
DEFAULT_CONFIG
)
normalized
.
update
(
config
)
for
key
in
BOOLEAN_KEYS
:
if
not
isinstance
(
normalized
[
key
],
bool
):
raise
ConfigError
(
f"
{
key
}
must be a boolean"
)
for
key
in
INTEGER_KEYS
:
value
=
normalized
[
key
]
if
value
is
None
:
continue
if
not
isinstance
(
value
,
int
)
or
isinstance
(
value
,
bool
):
raise
ConfigError
(
f"
{
key
}
must be an integer"
)
for
key
in
FLOAT_KEYS
:
value
=
normalized
[
key
]
if
value
is
None
:
continue
if
not
isinstance
(
value
, (
int
,
float
))
or
isinstance
(
value
,
bool
):
raise
ConfigError
(
f"
{
key
}
must be a number"
)
normalized
[
key
]
=
float
(
value
)
for
key
in
LIST_KEYS
:
value
=
normalized
[
key
]
if
not
isinstance
(
value
,
list
)
or
not
all
(
isinstance
(
item
,
str
)
for
item
in
value
):
raise
ConfigError
(
f"
{
key
}
must be a list of strings"
)
normalized
[
key
]
=
sorted
(
set
(
item
for
item
in
value
if
item
))
if
normalized
[
"layers"
]
<
1
:
raise
ConfigError
(
"layers must be at least 1"
)
if
normalized
[
"stage2_layers"
]
<
1
:
raise
ConfigError
(
"stage2_layers must be at least 1"
)
if
normalized
[
"max_output_bytes"
]
is
not
None
and
normalized
[
"max_output_bytes"
]
<
1
:
raise
ConfigError
(
"max_output_bytes must be at least 1"
)
if
normalized
[
"max_ratio"
]
is
not
None
and
normalized
[
"max_ratio"
]
<=
0
:
raise
ConfigError
(
"max_ratio must be positive"
)
if
normalized
[
"max_review_indicators"
]
is
not
None
and
normalized
[
"max_review_indicators"
]
<
0
:
raise
ConfigError
(
"max_review_indicators cannot be negative"
)
return
normalized
def
write_config
(
path
:
str
|
Path
,
config
:
dict
[
str
,
Any
])
->
Path
:
output_path
=
Path
(
path
)
output_path
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
output_path
.
write_text
(
json
.
dumps
(
normalize_config
(
config
),
indent
=
2
,
sort_keys
=
True
)
+
"
\n
"
,
encoding
=
"utf-8"
)
return
output_path
You can’t perform that action at this time.