Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Move .gdlintrc and update CodeStyleWorkflow.yml #30

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions .github/workflows/.gdlintrc → .gdlintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class-definitions-order:
- tools
- classnames
- extends
- docstrings
- signals
- enums
- consts
Expand All @@ -10,31 +11,35 @@ class-definitions-order:
- prvvars
- onreadypubvars
- onreadyprvvars
- staticvars
- others
class-load-variable-name: (([A-Z][a-z0-9]*)+|_?[a-z][a-z0-9]*(_[a-z0-9]+)*)
class-name: ([A-Z][a-z0-9]*)+
class-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
comparison-with-itself: null
constant-name: '[A-Z][A-Z0-9]*(_[A-Z0-9]+)*'
constant-name: _?[A-Z][A-Z0-9]*(_[A-Z0-9]+)*
duplicated-load: null
enum-element-name: '[A-Z][A-Z0-9]*(_[A-Z0-9]+)*'
enum-name: ([A-Z][a-z0-9]*)+
enum-name: ([A-Z][_a-z0-9]*)+
excluded_directories: !!set
.git: null
expression-not-assigned: null
function-argument-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
function-arguments-number: 10
function-load-variable-name: ([A-Z][a-z0-9]*)+
function-name: (_on_([A-Z][a-z0-9]*)+(_[a-z0-9]+)*|_?[a-z][a-z0-9]*(_[a-z0-9]+)*)
function-preload-variable-name: ([A-Z][a-z0-9]*)+
function-variable-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*'
load-constant-name: (([A-Z][a-z0-9]*)+|[A-Z][A-Z0-9]*(_[A-Z0-9]+)*)
load-constant-name: (([A-Z][a-z0-9]*)+|_?[A-Z][A-Z0-9]*(_[A-Z0-9]+)*)
loop-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
max-file-lines: 1000
max-line-length: 150
max-public-methods: 50
mixed-tabs-and-spaces: null
max-returns: 6
mixed-tabs-and-spaces: false
no-elif-return: null
no-else-return: null
private-method-call: null
signal-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*'
sub-class-name: _?([A-Z][a-z0-9]*)+
tab-characters: 1
trailing-whitespace: null
unnecessary-pass: null
unused-argument: null
disable: [class-definitions-order, max-file-lines, max-line-length, max-public-methods]
disable: [class-definitions-order, max-file-lines, max-line-length, max-public-methods, no-else-return]
66 changes: 14 additions & 52 deletions .github/workflows/CodeStyleWorkflow.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,22 @@
name: Code style workflow

# Events but only for the master branch
on:
workflow_dispatch:
push:
branches: [ master ]
branches: ["master"]
pull_request:
branches: [ master ]

branches: ["master"]
jobs:
format:
# The type of runner that the job will run on
static-checks:
name: 'Static checks'
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install gdtoolkit
- name: Format with gdformat
run: |
gdformat --line-length=150 logger.gd
- name: Commit changes from formatting
uses: stefanzweifel/git-auto-commit-action@v4.1.2
with:
commit_message: Apply formatting changes
branch: ${{ github.head_ref }}

lint:
needs: [format]
- uses: actions/checkout@v3
- uses: Scony/godot-gdscript-toolkit@master
- run: echo "# Lint result" >> result
- run: gdlint logger.gd plugin.gd &>> result
continue-on-error: true
- run: echo "# Can files be formatted" >> result
- run: gdformat --check logger.gd plugin.gd &>> result
continue-on-error: true
- run: cat ./result >> $GITHUB_STEP_SUMMARY

# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install gdtoolkit
- name: Lint the code with gdlint
run: |
cp './.github/workflows/.gdlintrc' '.'
gdlint logger.gd
echo "Done!"
70 changes: 47 additions & 23 deletions logger.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ExternalSink:
"""Flush the buffer, i.e. write its contents to the target external sink."""
print("[ERROR] [logger] Using method which has to be overriden in your custom sink")

func write(output, level):
func write(_output, _level):
"""Write the string at the end of the sink (append mode), following
the queue mode."""
print("[ERROR] [logger] Using method which has to be overriden in your custom sink")
Expand Down Expand Up @@ -328,7 +328,9 @@ const ERROR_MESSAGES = {
var default_output_level = INFO
# TODO: Find (or implement in Godot) a more clever way to achieve that

var default_output_strategies = [STRATEGY_PRINT, STRATEGY_PRINT, STRATEGY_PRINT, STRATEGY_PRINT, STRATEGY_PRINT]
var default_output_strategies = [
STRATEGY_PRINT, STRATEGY_PRINT, STRATEGY_PRINT, STRATEGY_PRINT, STRATEGY_PRINT
]
var default_logfile_path = "user://%s.log" % ProjectSettings.get_setting("application/config/name") # TODO @File
var default_configfile_path = "user://%s.cfg" % PLUGIN_NAME

Expand Down Expand Up @@ -416,7 +418,12 @@ func error(message, module = default_module_name, error_code = -1):
# -----------------


func add_module(name, output_level = default_output_level, output_strategies = default_output_strategies, logfile = null):
func add_module(
name,
output_level = default_output_level,
output_strategies = default_output_strategies,
logfile = null
):
"""Add a new module with the given parameter or (by default) the
default ones.
Returns a reference to the instanced module."""
Expand All @@ -436,7 +443,6 @@ func get_module(module = default_module_name):
add_module(module)
return modules[module]


func get_modules():
"""Retrieve the dictionary containing all modules."""
return modules
Expand Down Expand Up @@ -487,7 +493,10 @@ func add_logfile(logfile_path = default_logfile_path):
func get_external_sink(_external_sink_name):
"""Retrieve the first given external sink if it exists, otherwise returns null."""
if not external_sinks.has(_external_sink_name):
warn("The requested external sink pointing to '%s' does not exist." % _external_sink_name, PLUGIN_NAME)
warn(
"The requested external sink pointing to '%s' does not exist." % _external_sink_name,
PLUGIN_NAME
)
return null
else:
return external_sinks[_external_sink_name]
Expand Down Expand Up @@ -584,7 +593,8 @@ func get_formatted_datetime():
func format(template, level, module, message, error_code = -1):
var output = template
output = output.replace(FORMAT_IDS.level, LEVELS[level])
output = output.replace(FORMAT_IDS.module, module)
if(module!=null):
output = output.replace(FORMAT_IDS.module, module)
output = output.replace(FORMAT_IDS.message, str(message))
output = output.replace(FORMAT_IDS.time, get_formatted_datetime())

Expand All @@ -605,7 +615,7 @@ func set_output_format(new_format):
"""
for key in FORMAT_IDS:
if new_format.find(FORMAT_IDS[key]) == -1:
error("Invalid output string format. It lacks the '%s' identifier." % FORMAT_IDS[key], PLUGIN_NAME)
error("Invalid output string format. It lacks the '%s' identifier." % FORMAT_IDS[key], PLUGIN_NAME)
return
output_format = new_format
info("Successfully changed the output format to '%s'." % output_format, PLUGIN_NAME)
Expand Down Expand Up @@ -689,7 +699,7 @@ func clear_memory():
# Configuration loading/saving
# ----------------------------

const config_fields := {
const CONFIG_FIELDS := {
default_output_level = "default_output_level",
default_output_strategies = "default_output_strategies",
default_logfile_path = "default_logfile_path",
Expand All @@ -708,26 +718,26 @@ func save_config(configfile = default_configfile_path):
var config = ConfigFile.new()

# Store default config
config.set_value(PLUGIN_NAME, config_fields.default_output_level, default_output_level)
config.set_value(PLUGIN_NAME, config_fields.default_output_strategies, default_output_strategies)
config.set_value(PLUGIN_NAME, config_fields.default_logfile_path, default_logfile_path)
config.set_value(PLUGIN_NAME, config_fields.max_memory_size, max_memory_size)
config.set_value(PLUGIN_NAME, CONFIG_FIELDS.default_output_level, default_output_level)
config.set_value(PLUGIN_NAME, CONFIG_FIELDS.default_output_strategies, default_output_strategies)
config.set_value(PLUGIN_NAME, CONFIG_FIELDS.default_logfile_path, default_logfile_path)
config.set_value(PLUGIN_NAME, CONFIG_FIELDS.max_memory_size, max_memory_size)

# External sink config
var external_sinks_arr = []
var sorted_keys = external_sinks.keys()
sorted_keys.sort() # Sadly doesn't return the array, so we need to split it
for external_sink in sorted_keys:
external_sinks_arr.append(external_sinks[external_sink].get_config())
config.set_value(PLUGIN_NAME, config_fields.external_sinks, external_sinks_arr)
config.set_value(PLUGIN_NAME, CONFIG_FIELDS.external_sinks, external_sinks_arr)

# Modules config
var modules_arr = []
sorted_keys = modules.keys()
sorted_keys.sort()
for module in sorted_keys:
modules_arr.append(modules[module].get_config())
config.set_value(PLUGIN_NAME, config_fields.modules, modules_arr)
config.set_value(PLUGIN_NAME, CONFIG_FIELDS.modules, modules_arr)

# Save and return the corresponding error code
var err = config.save(configfile)
Expand All @@ -745,37 +755,51 @@ func load_config(configfile = default_configfile_path):
Returns an error code (OK or some ERR_*)."""
# Look for the file
if not FileAccess.file_exists(configfile):
warn("Could not load the config in '%s', the file does not exist." % configfile, PLUGIN_NAME)
warn(
"Could not load the config in '%s', the file does not exist." % configfile, PLUGIN_NAME
)
return ERR_FILE_NOT_FOUND

# Load its contents
var config = ConfigFile.new()
var err = config.load(configfile)
if err:
warn("Could not load the config in '%s'; exited with error %d." % [configfile, err], PLUGIN_NAME)
warn(
"Could not load the config in '%s'; exited with error %d." % [configfile, err],
PLUGIN_NAME
)
return err

# Load default config
default_output_level = config.get_value(PLUGIN_NAME, config_fields.default_output_level, default_output_level)
default_output_strategies = config.get_value(PLUGIN_NAME, config_fields.default_output_strategies, default_output_strategies)
default_logfile_path = config.get_value(PLUGIN_NAME, config_fields.default_logfile_path, default_logfile_path)
max_memory_size = config.get_value(PLUGIN_NAME, config_fields.max_memory_size, max_memory_size)
default_output_level = config.get_value(
PLUGIN_NAME, CONFIG_FIELDS.default_output_level, default_output_level
)
default_output_strategies = config.get_value(
PLUGIN_NAME, CONFIG_FIELDS.default_output_strategies, default_output_strategies
)
default_logfile_path = config.get_value(
PLUGIN_NAME, CONFIG_FIELDS.default_logfile_path, default_logfile_path
)
max_memory_size = config.get_value(PLUGIN_NAME, CONFIG_FIELDS.max_memory_size, max_memory_size)

# Load external config and initialize them
flush_buffers()
external_sinks = {}
add_logfile(default_logfile_path)
for logfile_cfg in config.get_value(PLUGIN_NAME, config_fields.external_sinks, []):
for logfile_cfg in config.get_value(PLUGIN_NAME, CONFIG_FIELDS.external_sinks, []):
var logfile = Logfile.new(logfile_cfg["path"], logfile_cfg["queue_mode"])
external_sinks[logfile_cfg["path"]] = logfile

# Load modules config and initialize them
modules = {}
add_module(PLUGIN_NAME)
add_module(default_module_name)
for module_cfg in config.get_value(PLUGIN_NAME, config_fields.modules, []):
for module_cfg in config.get_value(PLUGIN_NAME, CONFIG_FIELDS.modules, []):
var module = Module.new(
module_cfg["name"], module_cfg["output_level"], module_cfg["output_strategies"], get_external_sink(module_cfg["external_sink"]["path"])
module_cfg["name"],
module_cfg["output_level"],
module_cfg["output_strategies"],
get_external_sink(module_cfg["external_sink"]["path"])
)
modules[module_cfg["name"]] = module

Expand Down