Skip to content

Commit c9a2d52

Browse files
authored
Refactoring and enhancements for codebase excellence (#97)
This changes incorporates a comprehensive set of refactoring, optimization, and enhancement initiatives designed to elevate the codebase in terms of clarity, maintainability, testing resilience, documentation, and overall performance. Signed-off-by: Ryuu Mitsuki <[email protected]>
2 parents fc2f2f2 + ee404ab commit c9a2d52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3807
-2162
lines changed

.github/workflows/tests.yml

+59-79
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
name: Project Tester
1+
name: Test
22

33
on:
44
# Run on push, pull request, and manual trigger
55
push:
66
# Only run when the specific files are changed
77
paths:
8-
- 'src/**/*.java' # Java files
9-
- 'src/**/*.py' # Python files
8+
- '**/*.java' # Java files
9+
- '**/*.py' # Python files
1010

1111
# Unlike push, the workflow always runs on pull requests
1212
pull_request:
@@ -20,20 +20,34 @@ on:
2020
required: false
2121
type: boolean
2222

23+
# Environment variables definitions
24+
env:
25+
## For Java installation
26+
java-dist: temurin
27+
28+
## For Python installation
29+
arch: x64
30+
31+
## Other environments
32+
debug: ${{ inputs.debug }}
33+
deps: requirements.txt
34+
2335
jobs:
2436
# ::---:: Maven Test ::---:: #
2537
maven-test:
26-
name: Maven Test / ${{ matrix.os }}
38+
name: Maven Test / ${{ matrix.os }} / ${{ matrix.java-ver }}
2739
runs-on: ${{ matrix.os }}-latest
2840

2941
env:
30-
java-ver: 11
31-
java-dist: temurin
32-
DEBUG: ${{ inputs.debug }}
42+
# Maven's debug flag (`-X`)
43+
mvnDebugFlag: ${{ inputs.debug == true && '-X' || '' }}
3344

3445
strategy:
46+
# Set to maximum number of processes to speed up jobs run
47+
max-parallel: 6
3548
matrix:
36-
os: [Ubuntu, Windows]
49+
os: [Ubuntu, Windows, macOS]
50+
java-ver: [11, 17, 20] # JDK 11, 17 & 20
3751

3852
steps:
3953
# Checkout repository
@@ -46,89 +60,70 @@ jobs:
4660
uses: actions/cache@v3
4761
with:
4862
path: ~/.m2/repository
49-
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
63+
key: ${{ runner.os }}-jdk-${{ matrix.java-ver }}-${{ env.java-dist }}-maven-${{ hashFiles('**/pom.xml') }}
5064
restore-keys: |
51-
${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
52-
${{ runner.os }}-maven-
65+
${{ runner.os }}-jdk-${{ matrix.java-ver }}-${{ env.java-dist }}-maven-${{ hashFiles('**/pom.xml') }}
66+
${{ runner.os }}-jdk-${{ matrix.java-ver }}-${{ env.java-dist }}-maven-
5367
5468
# Setup Java
55-
- name: Setup Java / ${{ matrix.os }}
69+
- name: Setup Java / ${{ matrix.os }} / ${{ matrix.java-ver }}
5670
uses: actions/setup-java@v4
5771
with:
58-
java-version: ${{ env.java-ver }}
72+
java-version: ${{ matrix.java-ver }}
5973
distribution: ${{ env.java-dist }}
74+
cache: 'maven'
75+
cache-dependency-path: '**/pom.xml'
6076

61-
# Install deps
62-
- name: Install dependencies
63-
if: ${{ steps.cache-maven.outputs.cache-hit != true && env.DEBUG != true }}
64-
run: mvn install -DskipTests
65-
66-
- name: Install dependencies (Debug)
67-
if: ${{ steps.cache-maven.outputs.cache-hit != true && env.DEBUG == true }}
68-
run: mvn install -DskipTests -X
69-
70-
# Packaging with source files
71-
- name: Package source
72-
if: ${{ env.DEBUG != true }}
73-
run: mvn package -P include-src
74-
75-
- name: Package source (Debug)
76-
if: ${{ env.DEBUG == true }}
77-
run: mvn package -P include-src -X
78-
79-
# Test
80-
- name: Test project
81-
if: ${{ env.DEBUG != true }}
82-
run: mvn test
83-
84-
- name: Test project (Debug)
85-
if: ${{ env.DEBUG == true }}
86-
run: mvn test -X
77+
# Build the project
78+
- name: Build with Maven
79+
run: mvn -B package -P include-src -P lint ${{ env.mvnDebugFlag }}
80+
shell: bash
8781

8882
# Clean up
8983
- name: Clean up the project
90-
run: mvn clean
84+
run: mvn clean ${{ env.mvnDebugFlag }}
85+
shell: bash
9186

9287

9388
# ::---:: Make Test ::---:: #
9489
make-test:
95-
name: Make Test
90+
name: Make Test / Ubuntu / ${{ matrix.py-ver }}
9691
runs-on: ubuntu-latest
97-
continue-on-error: true
92+
93+
env:
94+
MAKE: ${{ inputs.debug == true && 'make -d' || 'make' }}
9895

9996
strategy:
97+
# Set to maximum number of processes to speed up jobs run
98+
max-parallel: 6
10099
matrix:
101-
py-ver: ['3.7', '3.x']
102-
103-
env:
104-
arch: x64
105-
DEPS_FILE: 'requirements.txt'
106-
DEBUG: ${{ inputs.debug }}
100+
py-ver: [3.7, 3.x] # Python 3.7 & latest of version 3
107101

108102
steps:
109103
# Checkout
110104
- name: Checkout repository
111105
uses: actions/checkout@v4
112106

113107
# Setup Python
114-
- name: Setup Python ${{ matrix.py-ver }}
108+
- name: Setup Python / Ubuntu / ${{ matrix.py-ver }}
115109
id: setup-py
116110
uses: actions/setup-python@v4
117111
with:
118112
python-version: ${{ matrix.py-ver }}
119113
architecture: ${{ env.arch }}
120-
cache: 'pip'
121-
cache-dependency-path: '**/${{ env.DEPS_FILE }}'
114+
cache: pip
115+
cache-dependency-path: '**/${{ env.deps }}'
122116

123117
# Install deps
124-
- name: Install dependencies
118+
- name: Install Python dependencies
125119
if: ${{ steps.setup-py.outputs.cache-hit != true }}
126120
run: |
127-
if [ $DEBUG = 'true' ]; then
128-
python -m pip install -r $DEPS_FILE --debug
121+
if [ $debug = 'true' ]; then
122+
python -m pip install -r $(git ls-files **/$deps) --debug
129123
else
130-
python -m pip install -r $DEPS_FILE
124+
python -m pip install -r $(git ls-files **/$deps)
131125
fi
126+
shell: bash
132127

133128
# Sadly, Make cannot tests the project thoroughly due to unavailability
134129
# of necessary packages (e.g "org.junit"), so here it just tests
@@ -137,31 +132,16 @@ jobs:
137132
# Compile
138133
- name: Compile the project
139134
run: |
140-
[ -d target/classes ] && make clean
141-
make compile VERBOSE=$DEBUG LINT=true
142-
143-
# Package
144-
- name: Packaging the project
145-
run: |
146-
make package VERBOSE=$DEBUG
147-
148-
- name: Packaging the project (with source)
149-
run: |
150-
make package INCLUDE-SRC=true VERBOSE=$DEBUG
135+
[ -d target ] && make clean > /dev/null
136+
$MAKE compile LINT=true VERBOSE=$debug
137+
shell: bash
151138

152-
# Build docs
153-
- name: Build the docs
154-
run: |
155-
# Build docs
156-
# For more information on debugging, we prefer to change it
157-
# to "all" mode.
158-
if [ $DEBUG = 'true' ]; then
159-
make build-docs VERBOSE=all
160-
else
161-
make build-docs
162-
fi
139+
# Build
140+
- name: Build with Make
141+
run: $MAKE package INCLUDE_SRC=true VERBOSE=$debug
142+
shell: bash
163143

164144
# Clean up
165145
- name: Clean up the project
166-
run: |
167-
[ -d target ] && echo "Clean the project" && make clean
146+
run: $MAKE clean VERBOSE=$debug
147+
shell: bash

.pylintrc

+17-13
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@ extension-pkg-whitelist=
3939
fail-on=
4040

4141
# Specify a score threshold under which the program will exit with error.
42-
fail-under=10
42+
fail-under=0.7
4343

4444
# Interpret the stdin as a python script, whose filename needs to be passed as
4545
# the module_or_package argument.
4646
#from-stdin=
4747

4848
# Files or directories to be skipped. They should be base names, not paths.
49-
ignore=CVS
49+
ignore=CVS,
50+
venv,
51+
.venv,
52+
docs
5053

5154
# Add files or directories matching the regular expressions patterns to the
5255
# ignore-list. The regex matches against paths and can be in Posix or Windows
@@ -72,7 +75,7 @@ ignored-modules=
7275
# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the
7376
# number of processors available to use, and will cap the count on Windows to
7477
# avoid hangs.
75-
jobs=1
78+
jobs=0
7679

7780
# Control the amount of potential inferred values when inferring a single
7881
# object. This can help the performance when dealing with large functions or
@@ -88,10 +91,10 @@ persistent=yes
8891

8992
# Minimum Python version to use for version dependent checks. Will default to
9093
# the version used to run pylint.
91-
py-version=3.11
94+
py-version=3.7
9295

9396
# Discover python modules and packages in the file system subtree.
94-
recursive=no
97+
recursive=yes
9598

9699
# Add paths to the list of the source roots. Supports globbing patterns. The
97100
# source root is an absolute path or a path relative to the current working
@@ -189,6 +192,7 @@ good-names=i,
189192
j,
190193
k,
191194
v,
195+
e,
192196
ex,
193197
Run,
194198
_
@@ -289,16 +293,16 @@ ignored-parents=
289293
max-args=5
290294

291295
# Maximum number of attributes for a class (see R0902).
292-
max-attributes=10
296+
max-attributes=7
293297

294298
# Maximum number of boolean expressions in an if statement (see R0916).
295299
max-bool-expr=5
296300

297301
# Maximum number of branch for function / method body.
298-
max-branches=35
302+
max-branches=12
299303

300304
# Maximum number of locals for function / method body.
301-
max-locals=25
305+
max-locals=15
302306

303307
# Maximum number of parents for a class (see R0901).
304308
max-parents=7
@@ -310,10 +314,10 @@ max-public-methods=20
310314
max-returns=6
311315

312316
# Maximum number of statements in function / method body.
313-
max-statements=80
317+
max-statements=50
314318

315319
# Minimum number of public methods for a class (see R0903).
316-
min-public-methods=1
320+
min-public-methods=2
317321

318322

319323
[EXCEPTIONS]
@@ -362,7 +366,7 @@ allow-any-import-level=
362366
allow-reexport-from-package=no
363367

364368
# Allow wildcard imports from modules that define __all__.
365-
allow-wildcard-with-all=yes
369+
allow-wildcard-with-all=no
366370

367371
# Deprecated modules which should not be used, separated by a comma.
368372
deprecated-modules=
@@ -459,7 +463,7 @@ notes-rgx=
459463
[REFACTORING]
460464

461465
# Maximum number of nested blocks for function / method body
462-
max-nested-blocks=6
466+
max-nested-blocks=5
463467

464468
# Complete name of functions that never returns. When checking for
465469
# inconsistent-return-statements if a never returning function is called then
@@ -499,7 +503,7 @@ score=yes
499503
ignore-comments=yes
500504

501505
# Docstrings are removed from the similarity computation
502-
ignore-docstrings=no
506+
ignore-docstrings=yes
503507

504508
# Imports are removed from the similarity computation
505509
ignore-imports=yes

0 commit comments

Comments
 (0)