| .vscode | ||
| dependencyanalyzer | ||
| doc | ||
| .gitignore | ||
| dependencyanalyzer.spec | ||
| README.md | ||
| requirements.txt | ||
Dependency Analyzer
Un'applicazione GUI per analizzare le dipendenze di progetti Python, generare requirements.txt, scaricare pacchetti offline e confrontare ambienti.
Dependency Analyzer (Italiano)
Introduzione
Dependency Analyzer è uno strumento desktop (con interfaccia grafica costruita usando Tkinter) che semplifica la gestione delle dipendenze per progetti Python. Analizza staticamente il codice sorgente per identificare i moduli importati, distinguendo tra librerie standard e pacchetti esterni.
L'obiettivo è fornire un modo semplice per:
- Ottenere un elenco chiaro delle dipendenze esterne di un progetto.
- Generare un file
requirements.txtdettagliato e informativo. - Preparare i pacchetti per una distribuzione offline.
- Confrontare le dipendenze richieste con l'ambiente di sviluppo corrente.
Caratteristiche Principali
- Interfaccia Grafica Semplice: Basata su Tkinter per un utilizzo intuitivo.
- Selezione Cartella Flessibile: Analizza l'intera cartella selezionata o una sottocartella specifica se segue la convenzione
nomeprogetto_minuscolo/. - Analisi Statica (AST): Esamina i file
.pyper trovare le istruzioniimportsenza eseguire il codice. - Generazione
requirements.txtDettagliata:- Include la versione Python dell'ambiente di analisi.
- Elenca i moduli standard utilizzati con i file sorgente di riferimento.
- Elenca le dipendenze esterne con:
- Nome pacchetto PyPI corretto (es.
Pillowdaimport PIL). - Versione rilevata nell'ambiente di analisi (se disponibile).
- File sorgente in cui è stato trovato l'import.
- Nome pacchetto PyPI corretto (es.
- Download Pacchetti Offline: Scarica le dipendenze esterne e le loro dipendenze nella sottocartella
_req_packages. - Script di Installazione: Genera
install_packages.bat/.shin_req_packagesper una facile installazione offline su altre macchine (con controllopipintegrato e percorsi relativi). - Confronto Ambiente: Mostra una tabella che confronta le dipendenze richieste con i pacchetti attualmente installati.
- Aggiornamento Ambiente (Opzionale): Permette di installare/aggiornare pacchetti selezionati direttamente nell'ambiente corrente (Usare con cautela, preferibilmente in ambienti virtuali!).
- Logging in Tempo Reale: Visualizza i log delle operazioni direttamente nell'interfaccia grafica.
Prerequisiti
- Python 3: Raccomandato Python 3.7+
- Pip: Deve essere installato e accessibile.
- (Opzionale ma Consigliato):
pip install packaging(per un confronto delle versioni più accurato).
Installazione / Setup
- Clona o scarica questo repository.
- Assicurati che la struttura sia:
<qualche_cartella>/ └── dependencyanalyzer/ ├── __init__.py ├── __main__.py ├── core.py └── gui.py - Non è richiesta un'installazione separata tramite
pipper lo strumento stesso, viene eseguito come modulo.
Utilizzo
- Apri un terminale o prompt dei comandi.
- Naviga (
cd) nella cartella che contiene la directorydependencyanalyzer. - Esegui lo strumento usando il flag
-mdi Python:
(Se hai rinominato la cartellapython -m dependencyanalyzerdependencyanalyzer, usa quel nome nel comando). - L'interfaccia grafica apparirà. Segui i passaggi numerati:
- 1. Select Repository Folder: Scegli la cartella del progetto Python da analizzare.
- 2. Analyze Project & Generate requirements.txt: Avvia l'analisi e la creazione del file.
- 3. External Dependencies Found: Visualizza le dipendenze esterne trovate.
- 4. Download / Create Installers: Scarica i pacchetti o genera gli script per l'offline.
- 5. System Package Comparison: Confronta con l'ambiente locale ed eventualmente aggiorna (con cautela).
- Log Messages: Monitora l'output e i progressi.
Come Funziona (Breve Panoramica Tecnica)
- Utilizza il modulo
astper creare un Abstract Syntax Tree del codice Python e trovare nodiImporteImportFrom. - Usa
sysconfig,importlib.util.find_spece una lista predefinita per distinguere i moduli standard da quelli esterni. - Applica una mappatura (es.
PIL->Pillow) per usare i nomi corretti dei pacchetti PyPI. - Utilizza
importlib.metadata.versionper rilevare le versioni installate. - Invoca
piptramitesubprocessper le operazioni di download, elenco e aggiornamento. - Usa
tkinter.ttkper la GUI eloggingper mostrare i messaggi nell'interfaccia.
Limitazioni Note
- Non rileva import dinamici (
importlib.import_module). - Non gestisce dipendenze non-Python.
- L'identificazione dei moduli interni si basa su convenzioni di base e potrebbe non essere perfetta per strutture di progetto molto complesse.
- Le versioni nel
requirements.txtriflettono l'ambiente di analisi; non risolve attivamente i vincoli dasetup.pyopyproject.tomldurante la generazione iniziale.
Dependency Analyzer (English)
Introduction
Dependency Analyzer is a desktop application (with a GUI built using Tkinter) that simplifies dependency management for Python projects. It statically analyzes source code to identify imported modules, distinguishing between standard libraries and external packages.
The goal is to provide an easy way to:
- Get a clear list of a project's external dependencies.
- Generate a detailed and informative
requirements.txtfile. - Prepare packages for offline distribution.
- Compare required dependencies against the current development environment.
Key Features
- Simple Graphical Interface: Based on Tkinter for intuitive use.
- Flexible Folder Selection: Analyzes the entire selected folder or a specific subfolder if it follows the
projectname_lowercase/convention. - Static Analysis (AST): Examines
.pyfiles to findimportstatements without executing code. - Detailed
requirements.txtGeneration:- Includes the Python version of the analysis environment.
- Lists used standard library modules with referencing source files.
- Lists external dependencies with:
- Correct PyPI package name (e.g.,
Pillowfromimport PIL). - Detected version in the analysis environment (if available).
- Source files where the import was found.
- Correct PyPI package name (e.g.,
- Offline Package Download: Downloads external dependencies and their dependencies into the
_req_packagessubfolder. - Installation Script Generation: Creates
install_packages.bat/.shin_req_packagesfor easy offline installation on other machines (with built-inpipcheck and relative paths). - Environment Comparison: Shows a table comparing required dependencies against currently installed packages.
- Environment Update (Optional): Allows installing/updating selected packages directly in the current environment (Use with caution, preferably in virtual environments!).
- Real-time Logging: Displays operation logs directly in the GUI.
Prerequisites
- Python 3: Python 3.7+ recommended.
- Pip: Must be installed and accessible.
- (Optional but Recommended):
pip install packaging(for more accurate version comparison).
Installation / Setup
- Clone or download this repository.
- Ensure the structure is:
<some_folder>/ └── dependencyanalyzer/ ├── __init__.py ├── __main__.py ├── core.py └── gui.py - No separate
pip installfor the tool itself is required; it runs as a module.
Usage
- Open a terminal or command prompt.
- Navigate (
cd) to the directory containing thedependencyanalyzerdirectory. - Run the tool using Python's
-mflag:
(If you renamed thepython -m dependencyanalyzerdependencyanalyzerfolder, use that name in the command). - The GUI will appear. Follow the numbered steps:
- 1. Select Repository Folder: Choose the Python project folder to analyze.
- 2. Analyze Project & Generate requirements.txt: Start the analysis and file creation.
- 3. External Dependencies Found: View the detected external dependencies.
- 4. Download / Create Installers: Download packages or generate scripts for offline use.
- 5. System Package Comparison: Compare with the local environment and optionally update (carefully).
- Log Messages: Monitor output and progress.
How it Works (Brief Technical Overview)
- Uses the
astmodule to build an Abstract Syntax Tree of Python code and findImportandImportFromnodes. - Uses
sysconfig,importlib.util.find_spec, and a predefined list to distinguish standard modules from external ones. - Applies mappings (e.g.,
PIL->Pillow) to use correct PyPI package names. - Uses
importlib.metadata.versionto detect installed versions. - Invokes
pipviasubprocessfor download, list, and update operations. - Uses
tkinter.ttkfor the GUI and theloggingmodule to display messages in the interface.
Known Limitations
- Does not detect dynamic imports (
importlib.import_module). - Does not handle non-Python dependencies.
- Internal module identification relies on basic conventions and might not be perfect for highly complex project structures.
- Versions in
requirements.txtreflect the analysis environment; it doesn't actively resolve constraints fromsetup.pyorpyproject.tomlduring initial generation.