Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
python-sdk/tools/check_mit_headers.py at main · dexpace/python-sdk · 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 }}
dexpace
python-sdk
Repository navigation
Code
Issues
58
(58)
Pull requests
9
(9)
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
python-sdk
/
tools
/
check_mit_headers.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
139 lines (107 loc) · 4.28 KB
main
Breadcrumbs
python-sdk
/
tools
/
check_mit_headers.py
Copy path
Top
File metadata and controls
Code
Blame
139 lines (107 loc) · 4.28 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
136
137
138
139
# Copyright (c) 2026 dexpace and Omar Aljarrah.
# Licensed under the MIT License. See LICENSE.md in the repository root for details.
"""Enforce the MIT licence header on every Python source file.
The project is MIT-licensed and every ``.py`` file -- source, tests, and
tooling alike -- must open with the two-line header before anything else
(an optional shebang may precede it). This module is the blocking gate that
scans the tree and fails when a file is missing or mangles the header.
Run it directly to check the current tree:
uv run python tools/check_mit_headers.py
Exit code is ``0`` when every scanned file carries the header and ``1`` when
any file is missing it.
"""
from
__future__
import
annotations
import
sys
from
collections
.
abc
import
Iterator
from
pathlib
import
Path
__all__
=
[
"EXPECTED_HEADER"
,
"SKIP_DIR_NAMES"
,
"file_has_header"
,
"find_header_violations"
,
"iter_python_files"
,
"main"
,
"repo_root"
,
]
# The exact two lines every .py file must begin with.
EXPECTED_HEADER
:
tuple
[
str
,
str
]
=
(
"# Copyright (c) 2026 dexpace and Omar Aljarrah."
,
"# Licensed under the MIT License. See LICENSE.md in the repository root for details."
,
)
# Directory names pruned during the walk: build/cache artefacts, any
# dot-directory (``.git``, ``.venv``, ``.mypy_cache``, session scratch, ...),
# and gitignored local reference checkouts that live inside the repo root but
# carry no project source (see ``.gitignore``). Excluding these keeps the
# scan to real, tracked source.
SKIP_DIR_NAMES
:
frozenset
[
str
]
=
frozenset
(
{
"__pycache__"
,
"azure-sdk-for-python"
,
"build"
,
"dist"
,
"node_modules"
,
"venv"
,
}
)
def
repo_root
()
->
Path
:
"""Return the repository root (the parent of this ``tools`` directory)."""
return
Path
(
__file__
).
resolve
().
parent
.
parent
def
_is_skipped_dir
(
name
:
str
)
->
bool
:
"""Return whether a directory name should be pruned from the walk."""
return
name
.
startswith
(
"."
)
or
name
in
SKIP_DIR_NAMES
or
name
.
endswith
(
".egg-info"
)
def
iter_python_files
(
root
:
Path
)
->
Iterator
[
Path
]:
"""Yield every ``.py`` file under a repo tree, skipping non-source dirs.
Args:
root: Directory to walk.
Yields:
Absolute paths to ``.py`` files, in sorted order per directory.
"""
for
dirpath
,
dirnames
,
filenames
in
root
.
walk
():
dirnames
[:]
=
sorted
(
d
for
d
in
dirnames
if
not
_is_skipped_dir
(
d
))
for
filename
in
sorted
(
filenames
):
if
filename
.
endswith
(
".py"
):
yield
dirpath
/
filename
def
file_has_header
(
path
:
Path
)
->
bool
:
"""Return whether a file opens with the expected MIT header.
A single leading shebang line (``#!...``) is tolerated before the header;
the two header lines must then appear back to back and match exactly.
Args:
path: Path to the ``.py`` file to inspect.
Returns:
``True`` if the header is present and exact, ``False`` otherwise.
"""
try
:
lines
=
path
.
read_text
(
encoding
=
"utf-8"
).
splitlines
()
except
(
OSError
,
UnicodeDecodeError
):
return
False
start
=
1
if
lines
and
lines
[
0
].
startswith
(
"#!"
)
else
0
return
tuple
(
lines
[
start
:
start
+
2
])
==
EXPECTED_HEADER
def
find_header_violations
(
root
:
Path
)
->
list
[
Path
]:
"""Find ``.py`` files under a repo tree missing the MIT header.
Args:
root: Repository root to scan.
Returns:
Sorted list of offending paths. Empty when every file is compliant.
"""
return
[
path
for
path
in
iter_python_files
(
root
)
if
not
file_has_header
(
path
)]
def
main
()
->
int
:
"""Report header violations and return a process exit code.
Returns:
``0`` when every scanned file carries the header, ``1`` otherwise.
"""
root
=
repo_root
()
violations
=
find_header_violations
(
root
)
if
not
violations
:
print
(
"MIT header check: OK (every .py file carries the licence header)"
)
return
0
print
(
"MIT header check: FAILED -- missing or malformed MIT header:"
)
for
path
in
violations
:
print
(
f"
{
path
.
relative_to
(
root
)
}
"
)
print
(
"
\n
Every .py file (src and tests) must start with these two lines:
\n
"
f"
{
EXPECTED_HEADER
[
0
]
}
\n
"
f"
{
EXPECTED_HEADER
[
1
]
}
"
)
return
1
if
__name__
==
"__main__"
:
sys
.
exit
(
main
())
You can’t perform that action at this time.