Skip to content

Commit 0dc5f69

Browse files
feat: ✨ Introduce configuration file (#51)
1 parent 4fd60af commit 0dc5f69

File tree

9 files changed

+246
-57
lines changed

9 files changed

+246
-57
lines changed

.github/workflows/code-style.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ jobs:
1212
- name: 'Checkout sources'
1313
uses: actions/checkout@v4
1414

15+
- name: 'Set up Python'
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: 3.12
19+
20+
- name: 'Set up Poetry'
21+
uses: snok/install-poetry@v1
22+
23+
- name: 'Install dependencies'
24+
run: poetry install --no-interaction --no-root
25+
1526
- name: 'Lint code with Ruff'
16-
run: |
17-
pipx install ruff
18-
ruff check .
27+
run: poetry run ruff check .
1928

2029
- name: 'Type cheking with MyPy'
21-
run: |
22-
pipx install mypy
23-
mypy --ignore-missing-imports codelimit/
30+
run: poetry run mypy codelimit/

.github/workflows/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,35 @@ jobs:
1212
steps:
1313
- name: 'Checkout sources'
1414
uses: actions/checkout@v3
15+
1516
- name: 'Set up Python'
1617
uses: actions/setup-python@v4
1718
with:
1819
python-version: 3.12
20+
1921
- name: 'Set up Poetry'
2022
uses: snok/install-poetry@v1
23+
2124
- name: 'Install dependencies'
2225
run: poetry install --no-interaction --no-root
26+
2327
- name: 'Run unit-tests with coverage'
2428
run: poetry run pytest --cov --cov-report=xml
29+
2530
- name: 'Run codelimit'
2631
run: |
2732
poetry run codelimit scan .
33+
2834
- name: 'Build and run codelimit binary'
2935
run: |
3036
poetry run pyinstaller -n codelimit -F codelimit/__main__.py
3137
./dist/codelimit scan .
38+
3239
- name: 'Run Code Limit action'
3340
uses: getcodelimit/codelimit-action@main
3441
with:
3542
token: ${{ secrets.GITHUB_TOKEN }}
3643
upload: true
44+
3745
- name: 'Upload coverage reports to Codecov'
3846
uses: codecov/codecov-action@v3

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,33 @@
2828
Code Limit is a tool for developers with one goal: _it tells the developer when
2929
it’s time to refactor_.
3030

31-
Check out the [documentation](https://codelimit-docs.vercel.app) and start
31+
Check out the [documentation](https://getcodelimit.github.io) and start
3232
using Code Limit today to keep your code maintainable.
3333

3434
## Quickstart
3535

3636
Depending on your development workflow, Code Limit can run in many different
3737
ways (e.g.: pre-commit hook, GitHub Action, standalone, etc.). See the
38-
[Quickstart documentation](https://codelimit-docs.vercel.app/quickstart/) for
38+
[Quickstart documentation](https://getcodelimit.github.io/quickstart/) for
3939
examples.
4040

4141
## Standalone usage
4242

4343
Code Limit can run as a standalone program to check and inspect a codebase, see
44-
the [Standalone Usage documentation](https://codelimit-docs.vercel.app/usage/)
45-
to get started.
44+
the [Standalone Usage documentation](https://getcodelimit.github.io/usage/) to
45+
get started.
4646

4747
## Configuration
4848

4949
Code Limit aims to be zero-configuration. However, sometimes the exception
5050
proves the rule. Check out the [Configuration
51-
documentation](https://codelimit-docs.vercel.app/configuration/) for all
51+
documentation](https://getcodelimit.github.io/configuration/) for all
5252
configuration options.
5353

5454
## Development
5555

5656
See the [Development
57-
documentation](https://codelimit-docs.vercel.app/development) if you want to
57+
documentation](https://getcodelimit.github.io/development) if you want to
5858
extend or contribute to Code Limit.
5959

6060
## Feedback, suggestions and bug reports

codelimit/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def check(
3636
):
3737
if exclude:
3838
Configuration.excludes.extend(exclude)
39+
Configuration.load(Path('.'))
3940
check_command(paths, quiet)
4041

4142

@@ -50,6 +51,7 @@ def scan(
5051
):
5152
if exclude:
5253
Configuration.excludes.extend(exclude)
54+
Configuration.load(path)
5355
scan_command(path)
5456

5557

@@ -64,6 +66,7 @@ def report(
6466
ReportFormat, typer.Option("--format", help="Output format")
6567
] = ReportFormat.text,
6668
):
69+
Configuration.load(path)
6770
report_command(path, full, totals, fmt)
6871

6972

@@ -86,6 +89,7 @@ def main(
8689
] = None,
8790
):
8891
"""Code Limit: Your refactoring alarm."""
92+
8993
if verbose:
9094
Configuration.verbose = True
9195
if version:

codelimit/common/Configuration.py

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
1-
class Configuration:
2-
excludes = [
3-
".bzr",
4-
".direnv",
5-
".eggs",
6-
".git",
7-
".git-rewrite",
8-
".hg",
9-
".ipynb_checkpoints",
10-
".mypy_cache",
11-
".nox",
12-
".pants.d",
13-
".pytest_cache",
14-
".pytype",
15-
".ruff_cache",
16-
".svn",
17-
".tox",
18-
".venv",
19-
".vscode",
20-
"__pypackages__",
21-
"_build",
22-
"buck-out",
23-
"build",
24-
"dist",
25-
"node_modules",
26-
"venv",
27-
"test",
28-
"tests",
29-
]
1+
from pathlib import Path
2+
3+
from yaml import load, FullLoader
4+
305

6+
class Configuration:
7+
excludes: list[str] = []
318
verbose = False
9+
10+
@classmethod
11+
def load(cls, root: Path):
12+
config_path = root.joinpath(".codelimit.yml")
13+
if not config_path.exists():
14+
return
15+
with open(config_path) as f:
16+
d = load(f, Loader=FullLoader)
17+
if "excludes" in d:
18+
cls.excludes.extend(d["excludes"])
19+
if "verbose" in d:
20+
cls.verbose = d["verbose"]

codelimit/common/Scanner.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def scan_codebase(path: Path, cached_report: Union[Report, None] = None) -> Code
4040
print_header(cached_report, path)
4141
scan_totals = ScanTotals()
4242
with Live(refresh_per_second=2) as live:
43-
4443
def add_file_entry(entry: SourceFileEntry):
4544
scan_totals.add(entry)
4645
table = ScanResultTable(scan_totals)
@@ -82,12 +81,13 @@ def print_refactor_candidates(scan_totals: ScanTotals):
8281

8382

8483
def _scan_folder(
85-
codebase: Codebase,
86-
folder: Path,
87-
cached_report: Union[Report, None] = None,
88-
add_file_entry: Union[Callable[[SourceFileEntry], None], None] = None,
84+
codebase: Codebase,
85+
folder: Path,
86+
cached_report: Union[Report, None] = None,
87+
add_file_entry: Union[Callable[[SourceFileEntry], None], None] = None,
8988
):
90-
excludes = Configuration.excludes.copy()
89+
excludes = DEFAULT_EXCLUDES.copy()
90+
excludes.extend(Configuration.excludes)
9191
gitignore_excludes = _read_gitignore(folder)
9292
if gitignore_excludes:
9393
excludes.extend(gitignore_excludes)
@@ -115,11 +115,11 @@ def _scan_folder(
115115

116116

117117
def _scan_file(
118-
codebase: Codebase,
119-
lexer: Lexer,
120-
root: Path,
121-
path: str,
122-
cached_report: Union[Report, None] = None,
118+
codebase: Codebase,
119+
lexer: Lexer,
120+
root: Path,
121+
path: str,
122+
cached_report: Union[Report, None] = None,
123123
) -> SourceFileEntry:
124124
checksum = calculate_checksum(path)
125125
rel_path = relpath(path, root)
@@ -190,3 +190,33 @@ def _read_gitignore(path: Path) -> list[str] | None:
190190

191191
def is_excluded(path: Path, spec: PathSpec):
192192
return spec.match_file(path)
193+
194+
195+
DEFAULT_EXCLUDES = [
196+
".bzr",
197+
".direnv",
198+
".eggs",
199+
".git",
200+
".git-rewrite",
201+
".hg",
202+
".ipynb_checkpoints",
203+
".mypy_cache",
204+
".nox",
205+
".pants.d",
206+
".pytest_cache",
207+
".pytype",
208+
".ruff_cache",
209+
".svn",
210+
".tox",
211+
".venv",
212+
".vscode",
213+
"__pypackages__",
214+
"_build",
215+
"buck-out",
216+
"build",
217+
"dist",
218+
"node_modules",
219+
"venv",
220+
"test",
221+
"tests",
222+
]

0 commit comments

Comments
 (0)