-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
4,148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include README.md | ||
include LICENSE | ||
include requirements.txt | ||
include sample_package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# __init__.py | ||
|
||
from .depster import convert_package_lock_to_csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import pandas as pd | ||
import requests | ||
import warnings | ||
|
||
def convert_package_lock_to_csv(input_file, output_file="dependencies.csv"): | ||
""" | ||
Converts package-lock.json to CSV with detailed dependency information. | ||
Args: | ||
input_file (str): Path to the package-lock.json file. | ||
output_file (str): Path to save the CSV file (default: dependencies.csv). | ||
""" | ||
warnings.filterwarnings('ignore') #suppress warnings | ||
|
||
with open(input_file) as package_lock_file: | ||
df = pd.read_json(package_lock_file) | ||
|
||
#change column names | ||
df = df.rename(columns={'name':'Project','version':'Current Version','dependencies':'dict'}) | ||
df.index.name = "Packages" | ||
#add a few empties | ||
df['Latest Version'] = None | ||
df['Integrity'] = None | ||
df['Requires'] = None | ||
df['Dependencies'] = None | ||
df['hasDependencies'] = False | ||
|
||
|
||
# make and fill new columns | ||
## since the dict column contains type dicts we can use the key/value pairs for easy data manipulation | ||
for index,row in df.iterrows(): | ||
df['Current Version'][index] = row['dict'].get('version') | ||
if row['dict'].get('integrity'): | ||
df['Integrity'][index] = row['dict'].get('integrity') | ||
if row['dict'].get('requires'): | ||
tempList = [key + ': ' +value for key,value in row['dict'].get('requires').items()].copy() ## turn dict into list | ||
df['Requires'][index] = tempList | ||
df['hasDependencies'][index] = True | ||
if row['dict'].get('dependencies'): | ||
tempList = [key + ': ' +row['dict'].get('dependencies')[key]['version'] for key in row['dict'].get('dependencies').keys()] | ||
df['Dependencies'][index] = tempList | ||
df['hasDependencies'][index] = True | ||
|
||
#drop columns | ||
df.drop(labels={'dict','lockfileVersion'},axis=1,inplace=True) | ||
|
||
# in order to populate the 'Newest Version' column, we'll need to do some querys | ||
## https://registry.npmjs.org/:package will suffice | ||
### we'll also be making a LOT of requests | ||
#### response.json() turns the response into a dict for us to parse | ||
|
||
header = {'Accept' : 'application/vnd.npm.install-v1+json'} ##gets an abbreviated response | ||
|
||
for index, _ in df.iterrows(): | ||
try: | ||
response = requests.get('https://registry.npmjs.org/'+index,headers=header).json() | ||
df['Latest Version'][index] = response['dist-tags']['latest'] | ||
except Exception as e: | ||
print(f"Warning: Could not fetch version for package '{index}': {e}") | ||
|
||
|
||
df.to_csv(output_file) | ||
print(f"Conversion complete. CSV saved to {output_file}") | ||
|
||
def main(): | ||
""" | ||
Entry point for the Depster CLI tool. | ||
""" | ||
import argparse | ||
parser = argparse.ArgumentParser(description="Depster: Convert package-lock.json to CSV.") | ||
parser.add_argument("input_file", help="Path to the package-lock.json file.") | ||
parser.add_argument("-o", "--output", default="dependencies.csv", help="Path to the output CSV file.") | ||
args = parser.parse_args() | ||
|
||
convert_package_lock_to_csv(args.input_file, args.output) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Metadata-Version: 2.1 | ||
Name: depster | ||
Version: 1.0.0 | ||
Summary: A tool create a detailed CSV analyzing your project's dependencies | ||
Home-page: https://github.com/shbenzer/depster | ||
Author: Simon H. Benzer | ||
Author-email: [email protected] | ||
Classifier: Programming Language :: Python :: 3 | ||
Classifier: License :: OSI Approved :: MIT License | ||
Classifier: Operating System :: OS Independent | ||
Requires-Python: >=3.6 | ||
Description-Content-Type: text/markdown | ||
License-File: LICENSE | ||
Requires-Dist: pandas | ||
Requires-Dist: requests | ||
|
||
# depster | ||
An Easy-To-Use Tool for Creating Detailed a Detailed Dependency Spreadsheet for Projects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
LICENSE | ||
MANIFEST.in | ||
README.md | ||
pyproject.toml | ||
requirements.txt | ||
sample_package-lock.json | ||
setup.py | ||
depster/__init__.py | ||
depster/depster.py | ||
depster.egg-info/PKG-INFO | ||
depster.egg-info/SOURCES.txt | ||
depster.egg-info/dependency_links.txt | ||
depster.egg-info/entry_points.txt | ||
depster.egg-info/requires.txt | ||
depster.egg-info/top_level.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[console_scripts] | ||
depster = depster.depster:main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pandas | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
depster |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# __init__.py | ||
|
||
from .depster import convert_package_lock_to_csv |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import pandas as pd | ||
import requests | ||
import warnings | ||
|
||
def convert_package_lock_to_csv(input_file, output_file="dependencies.csv"): | ||
""" | ||
Converts package-lock.json to CSV with detailed dependency information. | ||
Args: | ||
input_file (str): Path to the package-lock.json file. | ||
output_file (str): Path to save the CSV file (default: dependencies.csv). | ||
""" | ||
warnings.filterwarnings('ignore') #suppress warnings | ||
|
||
with open(input_file) as package_lock_file: | ||
df = pd.read_json(package_lock_file) | ||
|
||
#change column names | ||
df = df.rename(columns={'name':'Project','version':'Current Version','dependencies':'dict'}) | ||
df.index.name = "Packages" | ||
#add a few empties | ||
df['Latest Version'] = None | ||
df['Integrity'] = None | ||
df['Requires'] = None | ||
df['Dependencies'] = None | ||
df['hasDependencies'] = False | ||
|
||
|
||
# make and fill new columns | ||
## since the dict column contains type dicts we can use the key/value pairs for easy data manipulation | ||
for index,row in df.iterrows(): | ||
df['Current Version'][index] = row['dict'].get('version') | ||
if row['dict'].get('integrity'): | ||
df['Integrity'][index] = row['dict'].get('integrity') | ||
if row['dict'].get('requires'): | ||
tempList = [key + ': ' +value for key,value in row['dict'].get('requires').items()].copy() ## turn dict into list | ||
df['Requires'][index] = tempList | ||
df['hasDependencies'][index] = True | ||
if row['dict'].get('dependencies'): | ||
tempList = [key + ': ' +row['dict'].get('dependencies')[key]['version'] for key in row['dict'].get('dependencies').keys()] | ||
df['Dependencies'][index] = tempList | ||
df['hasDependencies'][index] = True | ||
|
||
#drop columns | ||
df.drop(labels={'dict','lockfileVersion'},axis=1,inplace=True) | ||
|
||
# in order to populate the 'Newest Version' column, we'll need to do some querys | ||
## https://registry.npmjs.org/:package will suffice | ||
### we'll also be making a LOT of requests | ||
#### response.json() turns the response into a dict for us to parse | ||
|
||
header = {'Accept' : 'application/vnd.npm.install-v1+json'} ##gets an abbreviated response | ||
|
||
for index, _ in df.iterrows(): | ||
try: | ||
response = requests.get('https://registry.npmjs.org/'+index,headers=header).json() | ||
df['Latest Version'][index] = response['dist-tags']['latest'] | ||
except Exception as e: | ||
print(f"Warning: Could not fetch version for package '{index}': {e}") | ||
|
||
|
||
df.to_csv(output_file) | ||
print(f"Conversion complete. CSV saved to {output_file}") | ||
|
||
def main(): | ||
""" | ||
Entry point for the Depster CLI tool. | ||
""" | ||
import argparse | ||
parser = argparse.ArgumentParser(description="Depster: Convert package-lock.json to CSV.") | ||
parser.add_argument("input_file", help="Path to the package-lock.json file.") | ||
parser.add_argument("-o", "--output", default="dependencies.csv", help="Path to the output CSV file.") | ||
args = parser.parse_args() | ||
|
||
convert_package_lock_to_csv(args.input_file, args.output) | ||
|
||
if __name__ == "__main__": | ||
main() |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["setuptools", "wheel"] | ||
build-backend = "setuptools.build_meta" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pandas>=1.0.0 | ||
requests>=2.0.0 |
Oops, something went wrong.