Assigned repository: SETAPESU26/L5_23_bike_share_stations
Student fork: dshivasaivarun-lgtm/L5_23_bike_share_stations
Main file: bike_share_stations.py
This project demonstrates static code analysis and code improvement using Pylint, Bandit, and Flake8.
The program simulates a small bike-share station manager. It supports:
The original program contained several code-quality, security, correctness, and formatting issues. These were documented, corrected, and verified by rerunning the static analysis tools.
Clone the repository:
git clone https://github.com/dshivasaivarun-lgtm/L5_23_bike_share_stations.git
cd L5_23_bike_share_stations
Create and activate a virtual environment:
python -m venv venv
.\venv\Scripts\Activate.ps1
Install the static analysis tools:
python -m pip install --upgrade pip
python -m pip install pylint bandit flake8
Verify the installations:
python -m pylint --version
python -m bandit --version
python -m flake8 --version
Execute the Python script:
python .\bike_share_stations.py
The program prints the results of its demonstration, including bike-rental outcomes, a generated PIN, the full stations, and bike availability.
The PIN is randomly generated and can differ between executions.
Run each tool against the Python file and save the original reports before making changes.
python -m pylint .\bike_share_stations.py > pylint_before.txt 2>&1
python -m bandit .\bike_share_stations.py > bandit_before.txt 2>&1
python -m flake8 .\bike_share_stations.py > flake8_before.txt 2>&1
After applying fixes, generate the final reports:
python -m pylint .\bike_share_stations.py > pylint_after.txt 2>&1
python -m bandit .\bike_share_stations.py > bandit_after.txt 2>&1
python -m flake8 .\bike_share_stations.py > flake8_after.txt 2>&1
An empty flake8_after.txt indicates that Flake8 reported no violations.
The original static analysis reports identified the following problems:
random module for security-sensitive PIN generation.None.The fixes included parameterized SQL queries, the secrets module, safer list initialization, improved error handling, consistent return values, better documentation, and formatting corrections.
See issues.md for the detailed issue table and reflection.md for the lab reflection.
| Tool | Original Result | Final Result |
|---|---|---|
| Pylint | 3.89/10 | 10.00/10 |
| Bandit | 3 findings: 1 medium and 2 low | No issues identified |
| Flake8 | 10 reported violations | No violations reported |
These results were obtained by running the tools against the original and updated versions of bike_share_stations.py.
The project contains the following submission files:
| File | Purpose |
|---|---|
bike_share_stations.py |
Updated Python source code |
issues.md |
Issue table documenting findings and fixes |
reflection.md |
Reflection on static analysis and code improvements |
pylint_before.txt |
Original Pylint report |
pylint_after.txt |
Final Pylint report |
bandit_before.txt |
Original Bandit report |
bandit_after.txt |
Final Bandit report |
flake8_before.txt |
Original Flake8 report |
flake8_after.txt |
Final Flake8 report |
The lab changes were recorded in three commits:
6085165 — Improve Python code quality and fix bugs7e4ca3c — Document security findings and remediation9c424e0 — Add analysis reports and lab reflectionThe commits were pushed to the student's personal GitHub fork.
This lab demonstrates how static code analysis can improve the quality, security, and maintainability of Python software. Pylint, Bandit, and Flake8 provide complementary checks that help developers identify problems and verify that corrective changes have been applied.