Skip to content

Conversation

@javidahmed64592
Copy link
Owner

@javidahmed64592 javidahmed64592 commented Nov 30, 2025

This pull request refactors the configuration and logging setup for the Python template server, centralizing constants, moving logging setup to its own module, and simplifying configuration loading. It also updates related modules to use the new structure and improves code clarity by removing unused properties and parameters.

Configuration and Logging Refactor:

  • Moved all configuration and path constants (such as ROOT_DIR, CONFIG_DIR, LOG_DIR, etc.) into python_template_server/constants.py, making them accessible throughout the codebase. ([python_template_server/constants.pyR3-L19](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-6aafcdb899cb6f32a24c647a60e3684570362c33a5cb8defd81d0a5fde7e8203R3-L19))
  • Extracted logging setup into a new module python_template_server/logging_setup.py, removing logging configuration from config.py and enabling consistent logging initialization across modules. ([python_template_server/logging_setup.pyR1-R50](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-2a2a395008e0a4989bf47c6c718aedfbcb51092980d48eadea12f354fe077e7aR1-R50))
  • Updated all modules to import and call setup_logging() from the new logging setup module, ensuring logging is initialized before any logger usage. ([[1]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-1a98048e39ba4137b669c4f93e1349189a2efe3b816d5740e1b60e98cb364037L10-L16), [[2]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-70cfaa5cac5328039faa54a2c028498b480c8bca19724b7854ed6714675cc0f9L14-R18), [[3]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-fc053d43591ac007c7812f0590d7bfab3123bf19b39f520309b52e1c79b3243aR19-R64))

Configuration Loading Simplification:

  • Removed the config.py module and integrated configuration loading directly into the abstract base class TemplateServer via a new load_config method, which loads and validates the config file using centralized constants. ([[1]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-cde0e1bbc865d1b493bfe2fd6bc655319aa2091718577624dfe97fe472ddb94cL1-L112), [[2]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-fc053d43591ac007c7812f0590d7bfab3123bf19b39f520309b52e1c79b3243aR77-R106))
  • Refactored ExampleServer in main.py to use the new configuration loading approach, eliminating the need to pass a config object on initialization. ([[1]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-94db1ccf6dddf805df9b761447b19a02f4ee37174d18e30bf644bf2faf61495eL3-R22), [[2]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-94db1ccf6dddf805df9b761447b19a02f4ee37174d18e30bf644bf2faf61495eL28-R34))

Code Cleanup and Consistency:

  • Updated usage of environment and config file paths in authentication_handler.py to use new constants, improving reliability and reducing hardcoded paths. ([python_template_server/authentication_handler.pyL42-R52](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-1a98048e39ba4137b669c4f93e1349189a2efe3b816d5740e1b60e98cb364037L42-R52))
  • Removed unused properties and imports from models.py to streamline the configuration models and eliminate unnecessary code. ([[1]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-7bd9896d9e20648c190059b324cad22cac285ffd06e86f8fbb6247cf3e629ba6L9-L10), [[2]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-7bd9896d9e20648c190059b324cad22cac285ffd06e86f8fbb6247cf3e629ba6L29-L33))
  • Updated all logging statements in template_server.py to use the centralized logger instead of instance loggers, ensuring consistent logging output. ([[1]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-fc053d43591ac007c7812f0590d7bfab3123bf19b39f520309b52e1c79b3243aL78-R116), [[2]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-fc053d43591ac007c7812f0590d7bfab3123bf19b39f520309b52e1c79b3243aL87-R134), [[3]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-fc053d43591ac007c7812f0590d7bfab3123bf19b39f520309b52e1c79b3243aL106-R144), [[4]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-fc053d43591ac007c7812f0590d7bfab3123bf19b39f520309b52e1c79b3243aL116-R154), [[5]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-fc053d43591ac007c7812f0590d7bfab3123bf19b39f520309b52e1c79b3243aL141-R179), [[6]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-fc053d43591ac007c7812f0590d7bfab3123bf19b39f520309b52e1c79b3243aL153-R191), [[7]](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-fc053d43591ac007c7812f0590d7bfab3123bf19b39f520309b52e1c79b3243aL196-R234))

Dockerfile Update:

  • Removed references to the config file in the Docker startup script, since configuration is now loaded internally, simplifying container initialization. ([DockerfileL54-R63](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557L54-R63))

Certificate Generation Update:

  • Changed certificate generation to use the new configuration loading via ExampleServer().config, removing dependency on command-line argument parsing. ([python_template_server/certificate_handler.pyL139-R141](https://github.com/javidahmed64592/python-template-server/pull/3/files#diff-70cfaa5cac5328039faa54a2c028498b480c8bca19724b7854ed6714675cc0f9L139-R141))

@javidahmed64592 javidahmed64592 merged commit 88a9310 into main Nov 30, 2025
7 checks passed
@javidahmed64592 javidahmed64592 deleted the update-server branch November 30, 2025 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants