Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shbenzer committed Jan 8, 2025
1 parent 11a745f commit 45f53ed
Show file tree
Hide file tree
Showing 20 changed files with 4,148 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions MANIFEST.in
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
3 changes: 3 additions & 0 deletions build/lib/depster/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# __init__.py

from .depster import convert_package_lock_to_csv
78 changes: 78 additions & 0 deletions build/lib/depster/depster.py
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()
18 changes: 18 additions & 0 deletions depster.egg-info/PKG-INFO
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
15 changes: 15 additions & 0 deletions depster.egg-info/SOURCES.txt
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
1 change: 1 addition & 0 deletions depster.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions depster.egg-info/entry_points.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[console_scripts]
depster = depster.depster:main
2 changes: 2 additions & 0 deletions depster.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pandas
requests
1 change: 1 addition & 0 deletions depster.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
depster
3 changes: 3 additions & 0 deletions depster/__init__.py
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 added depster/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added depster/__pycache__/depster.cpython-39.pyc
Binary file not shown.
78 changes: 78 additions & 0 deletions depster/depster.py
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 added dist/depster-1.0.0-py3-none-any.whl
Binary file not shown.
Binary file added dist/depster-1.0.0.tar.gz
Binary file not shown.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pandas>=1.0.0
requests>=2.0.0
Loading

0 comments on commit 45f53ed

Please sign in to comment.