Skip to content

Commit

Permalink
Refactoring and enhancements for codebase excellence (#97)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mitsuki31 authored Feb 2, 2024
2 parents fc2f2f2 + ee404ab commit c9a2d52
Show file tree
Hide file tree
Showing 41 changed files with 3,807 additions and 2,162 deletions.
138 changes: 59 additions & 79 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Project Tester
name: Test

on:
# Run on push, pull request, and manual trigger
push:
# Only run when the specific files are changed
paths:
- 'src/**/*.java' # Java files
- 'src/**/*.py' # Python files
- '**/*.java' # Java files
- '**/*.py' # Python files

# Unlike push, the workflow always runs on pull requests
pull_request:
Expand All @@ -20,20 +20,34 @@ on:
required: false
type: boolean

# Environment variables definitions
env:
## For Java installation
java-dist: temurin

## For Python installation
arch: x64

## Other environments
debug: ${{ inputs.debug }}
deps: requirements.txt

jobs:
# ::---:: Maven Test ::---:: #
maven-test:
name: Maven Test / ${{ matrix.os }}
name: Maven Test / ${{ matrix.os }} / ${{ matrix.java-ver }}
runs-on: ${{ matrix.os }}-latest

env:
java-ver: 11
java-dist: temurin
DEBUG: ${{ inputs.debug }}
# Maven's debug flag (`-X`)
mvnDebugFlag: ${{ inputs.debug == true && '-X' || '' }}

strategy:
# Set to maximum number of processes to speed up jobs run
max-parallel: 6
matrix:
os: [Ubuntu, Windows]
os: [Ubuntu, Windows, macOS]
java-ver: [11, 17, 20] # JDK 11, 17 & 20

steps:
# Checkout repository
Expand All @@ -46,89 +60,70 @@ jobs:
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
key: ${{ runner.os }}-jdk-${{ matrix.java-ver }}-${{ env.java-dist }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
${{ runner.os }}-maven-
${{ runner.os }}-jdk-${{ matrix.java-ver }}-${{ env.java-dist }}-maven-${{ hashFiles('**/pom.xml') }}
${{ runner.os }}-jdk-${{ matrix.java-ver }}-${{ env.java-dist }}-maven-
# Setup Java
- name: Setup Java / ${{ matrix.os }}
- name: Setup Java / ${{ matrix.os }} / ${{ matrix.java-ver }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.java-ver }}
java-version: ${{ matrix.java-ver }}
distribution: ${{ env.java-dist }}
cache: 'maven'
cache-dependency-path: '**/pom.xml'

# Install deps
- name: Install dependencies
if: ${{ steps.cache-maven.outputs.cache-hit != true && env.DEBUG != true }}
run: mvn install -DskipTests

- name: Install dependencies (Debug)
if: ${{ steps.cache-maven.outputs.cache-hit != true && env.DEBUG == true }}
run: mvn install -DskipTests -X

# Packaging with source files
- name: Package source
if: ${{ env.DEBUG != true }}
run: mvn package -P include-src

- name: Package source (Debug)
if: ${{ env.DEBUG == true }}
run: mvn package -P include-src -X

# Test
- name: Test project
if: ${{ env.DEBUG != true }}
run: mvn test

- name: Test project (Debug)
if: ${{ env.DEBUG == true }}
run: mvn test -X
# Build the project
- name: Build with Maven
run: mvn -B package -P include-src -P lint ${{ env.mvnDebugFlag }}
shell: bash

# Clean up
- name: Clean up the project
run: mvn clean
run: mvn clean ${{ env.mvnDebugFlag }}
shell: bash


# ::---:: Make Test ::---:: #
make-test:
name: Make Test
name: Make Test / Ubuntu / ${{ matrix.py-ver }}
runs-on: ubuntu-latest
continue-on-error: true

env:
MAKE: ${{ inputs.debug == true && 'make -d' || 'make' }}

strategy:
# Set to maximum number of processes to speed up jobs run
max-parallel: 6
matrix:
py-ver: ['3.7', '3.x']

env:
arch: x64
DEPS_FILE: 'requirements.txt'
DEBUG: ${{ inputs.debug }}
py-ver: [3.7, 3.x] # Python 3.7 & latest of version 3

steps:
# Checkout
- name: Checkout repository
uses: actions/checkout@v4

# Setup Python
- name: Setup Python ${{ matrix.py-ver }}
- name: Setup Python / Ubuntu / ${{ matrix.py-ver }}
id: setup-py
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.py-ver }}
architecture: ${{ env.arch }}
cache: 'pip'
cache-dependency-path: '**/${{ env.DEPS_FILE }}'
cache: pip
cache-dependency-path: '**/${{ env.deps }}'

# Install deps
- name: Install dependencies
- name: Install Python dependencies
if: ${{ steps.setup-py.outputs.cache-hit != true }}
run: |
if [ $DEBUG = 'true' ]; then
python -m pip install -r $DEPS_FILE --debug
if [ $debug = 'true' ]; then
python -m pip install -r $(git ls-files **/$deps) --debug
else
python -m pip install -r $DEPS_FILE
python -m pip install -r $(git ls-files **/$deps)
fi
shell: bash

# Sadly, Make cannot tests the project thoroughly due to unavailability
# of necessary packages (e.g "org.junit"), so here it just tests
Expand All @@ -137,31 +132,16 @@ jobs:
# Compile
- name: Compile the project
run: |
[ -d target/classes ] && make clean
make compile VERBOSE=$DEBUG LINT=true
# Package
- name: Packaging the project
run: |
make package VERBOSE=$DEBUG
- name: Packaging the project (with source)
run: |
make package INCLUDE-SRC=true VERBOSE=$DEBUG
[ -d target ] && make clean > /dev/null
$MAKE compile LINT=true VERBOSE=$debug
shell: bash

# Build docs
- name: Build the docs
run: |
# Build docs
# For more information on debugging, we prefer to change it
# to "all" mode.
if [ $DEBUG = 'true' ]; then
make build-docs VERBOSE=all
else
make build-docs
fi
# Build
- name: Build with Make
run: $MAKE package INCLUDE_SRC=true VERBOSE=$debug
shell: bash

# Clean up
- name: Clean up the project
run: |
[ -d target ] && echo "Clean the project" && make clean
run: $MAKE clean VERBOSE=$debug
shell: bash
30 changes: 17 additions & 13 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ extension-pkg-whitelist=
fail-on=

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

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

# Files or directories to be skipped. They should be base names, not paths.
ignore=CVS
ignore=CVS,
venv,
.venv,
docs

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

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

# Minimum Python version to use for version dependent checks. Will default to
# the version used to run pylint.
py-version=3.11
py-version=3.7

# Discover python modules and packages in the file system subtree.
recursive=no
recursive=yes

# Add paths to the list of the source roots. Supports globbing patterns. The
# source root is an absolute path or a path relative to the current working
Expand Down Expand Up @@ -189,6 +192,7 @@ good-names=i,
j,
k,
v,
e,
ex,
Run,
_
Expand Down Expand Up @@ -289,16 +293,16 @@ ignored-parents=
max-args=5

# Maximum number of attributes for a class (see R0902).
max-attributes=10
max-attributes=7

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

# Maximum number of branch for function / method body.
max-branches=35
max-branches=12

# Maximum number of locals for function / method body.
max-locals=25
max-locals=15

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

# Maximum number of statements in function / method body.
max-statements=80
max-statements=50

# Minimum number of public methods for a class (see R0903).
min-public-methods=1
min-public-methods=2


[EXCEPTIONS]
Expand Down Expand Up @@ -362,7 +366,7 @@ allow-any-import-level=
allow-reexport-from-package=no

# Allow wildcard imports from modules that define __all__.
allow-wildcard-with-all=yes
allow-wildcard-with-all=no

# Deprecated modules which should not be used, separated by a comma.
deprecated-modules=
Expand Down Expand Up @@ -459,7 +463,7 @@ notes-rgx=
[REFACTORING]

# Maximum number of nested blocks for function / method body
max-nested-blocks=6
max-nested-blocks=5

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

# Docstrings are removed from the similarity computation
ignore-docstrings=no
ignore-docstrings=yes

# Imports are removed from the similarity computation
ignore-imports=yes
Expand Down
Loading

0 comments on commit c9a2d52

Please sign in to comment.