Skip to content

Commit 58c546f

Browse files
authored
make consistent (#4)
Updated to be inline with other extractor tools we are building.
1 parent d791a0b commit 58c546f

File tree

7 files changed

+56
-56
lines changed

7 files changed

+56
-56
lines changed

CITATION.cff

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ message: If you use this software, please cite it using these metadata.
33
title: PyPi Extractor
44
abstract: Extract package information for a given user in PyPi.
55
type: software
6-
version: 0.1.0
6+
version: 0.1.1
77
date-released: 2024-06-11
88
repository-code: https://github.com/DevelopersToolbox/pypi-extractor-package
99
keywords:

README.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ pip install wolfsoftware.pypi-extractor
6666
Here's a basic example of how to use the PyPI Extractor:
6767

6868
```python
69-
from wolfsoftware.pypi_extractor import PyPIPackageInfo
69+
from wolfsoftware.pypi_extractor import PyPiExtractor
7070

7171
# Initialize without username
72-
pypi_info = PyPIPackageInfo()
72+
pypi_info = PyPiExtractor()
7373

7474
# Set username later
7575
pypi_info.set_username("your_pypi_username")
@@ -78,7 +78,7 @@ pypi_info.set_username("your_pypi_username")
7878
try:
7979
packages_details = pypi_info.get_all_packages_details()
8080
print(packages_details)
81-
except PyPIPackageInfoError as e:
81+
except PyPiExtractorError as e:
8282
print(f"An error occurred: {e.message}")
8383
```
8484

@@ -87,7 +87,7 @@ except PyPIPackageInfoError as e:
8787
You can also set the username during initialization:
8888

8989
```python
90-
pypi_info = PyPIPackageInfo("your_pypi_username")
90+
pypi_info = PyPiExtractor("your_pypi_username")
9191
```
9292

9393
### Retrieving User Packages
@@ -112,33 +112,33 @@ print(package_details)
112112

113113
### Classes
114114

115-
#### `PyPIPackageInfo`
115+
#### `PyPiExtractor`
116116

117117
A class to fetch and process package details for a given PyPI user.
118118

119119
##### `__init__(self, username: str)`
120120

121-
- Initializes the `PyPIPackageInfo` with a username.
121+
- Initializes the `PyPiExtractor` with a username.
122122
- Parameters:
123123
- `username` (str): The PyPI username.
124124
- Raises:
125-
- `PyPIPackageInfoError`: If the username is not provided.
125+
- `PyPiExtractorError`: If the username is not provided.
126126

127127
##### `set_username(self, username: str)`
128128

129129
- Sets the PyPI username.
130130
- Parameters:
131131
- `username` (str): The PyPI username.
132132
- Raises:
133-
- `PyPIPackageInfoError`: If the username is not provided.
133+
- `PyPiExtractorError`: If the username is not provided.
134134

135135
##### `get_user_packages(self) -> list`
136136

137137
- Fetches the list of packages for the given PyPI user.
138138
- Returns:
139139
- `list`: A list of dictionaries containing package names and summaries.
140140
- Raises:
141-
- `PyPIPackageInfoError`: If there is an error fetching or parsing the user profile.
141+
- `PyPiExtractorError`: If there is an error fetching or parsing the user profile.
142142

143143
##### `get_package_details(self, package_name: str) -> dict`
144144

@@ -148,19 +148,19 @@ A class to fetch and process package details for a given PyPI user.
148148
- Returns:
149149
- `dict`: A dictionary containing detailed information about the package.
150150
- Raises:
151-
- `PyPIPackageInfoError`: If there is an error fetching or parsing the package details.
151+
- `PyPiExtractorError`: If there is an error fetching or parsing the package details.
152152

153153
##### `get_all_packages_details(self) -> list`
154154

155155
- Fetches detailed information for all packages of the given PyPI user.
156156
- Returns:
157157
- `list`: A list of dictionaries containing detailed information about each package.
158158
- Raises:
159-
- `PyPIPackageInfoError`: If there is an error fetching or processing the package details.
159+
- `PyPiExtractorError`: If there is an error fetching or processing the package details.
160160

161-
#### `PyPIPackageInfoError`
161+
#### `PyPiExtractorError`
162162

163-
Custom exception class for `PyPIPackageInfo` errors.
163+
Custom exception class for `PyPiExtractor` errors.
164164

165165
<br />
166166
<p align="right"><a href="https://wolfsoftware.com/"><img src="https://img.shields.io/badge/Created%20by%20Wolf%20on%20behalf%20of%20Wolf%20Software-blue?style=for-the-badge" /></a></p>

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name='wolfsoftware.pypi-extractor',
15-
version='0.1.0',
15+
version='0.1.1',
1616
author='Wolf Software',
1717
author_email='[email protected]',
1818
description='Extract package information for a given user in PyPi.',

tests/test_pypi_extractor.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import pytest
1111

12-
from wolfsoftware.pypi_extractor import PyPIPackageInfo, PyPIPackageInfoError # pylint: disable=unused-import
12+
from wolfsoftware.pypi_extractor import PyPiExtractor, PyPiExtractorError # pylint: disable=unused-import, no-name-in-module
1313
from .testconf import ( # noqa: F401 pylint: disable=unused-import
1414
mock_get_user_packages_success,
1515
mock_get_user_packages_error,
@@ -45,23 +45,23 @@ def test_init_with_empty_username() -> None:
4545
does not raise an error, and that attempting to fetch packages without setting a username
4646
raises a PyPIPackageInfoError.
4747
"""
48-
pypi_info = PyPIPackageInfo()
48+
pypi_info = PyPiExtractor()
4949

50-
with pytest.raises(PyPIPackageInfoError, match="Username must be set before fetching packages"):
50+
with pytest.raises(PyPiExtractorError, match="Username must be set before fetching packages"):
5151
pypi_info.get_user_packages()
5252

53-
with pytest.raises(PyPIPackageInfoError, match="Username must be set before fetching package details"):
53+
with pytest.raises(PyPiExtractorError, match="Username must be set before fetching package details"):
5454
pypi_info.get_all_packages_details()
5555

5656

5757
def test_set_username() -> None:
5858
"""
5959
Test setting the username after initialization.
6060
61-
This test verifies that the username can be set after initializing the PyPIPackageInfo class,
61+
This test verifies that the username can be set after initializing the PyPiExtractor class,
6262
and that it functions correctly with the set username.
6363
"""
64-
pypi_info = PyPIPackageInfo()
64+
pypi_info = PyPiExtractor()
6565
pypi_info.set_username("testuser")
6666
assert pypi_info.username == "testuser" # nosec: B101
6767

@@ -70,11 +70,11 @@ def test_set_username_with_invalid_value() -> None:
7070
"""
7171
Test setting the username with an invalid value.
7272
73-
This test verifies that setting the username to an empty string raises a PyPIPackageInfoError.
73+
This test verifies that setting the username to an empty string raises a PyPiExtractorError.
7474
"""
75-
pypi_info = PyPIPackageInfo()
75+
pypi_info = PyPiExtractor()
7676

77-
with pytest.raises(PyPIPackageInfoError, match="Username must be provided"):
77+
with pytest.raises(PyPiExtractorError, match="Username must be provided"):
7878
pypi_info.set_username("")
7979

8080

@@ -86,7 +86,7 @@ def test_get_user_packages_success(mock_get_user_packages_success) -> None: # n
8686
to return a successful response and verifies that the get_user_packages method returns
8787
the expected list of packages.
8888
"""
89-
pypi_info = PyPIPackageInfo("testuser")
89+
pypi_info = PyPiExtractor("testuser")
9090
packages: List = pypi_info.get_user_packages()
9191

9292
assert len(packages) == 2 # nosec: B101
@@ -101,11 +101,11 @@ def test_get_user_packages_error(mock_get_user_packages_error) -> None: # noqa:
101101
Test get_user_packages method when there is an error.
102102
103103
This test uses the mock_get_user_packages_error fixture to mock requests.get method
104-
to raise an exception and verifies that the get_user_packages method raises a PyPIPackageInfoError.
104+
to raise an exception and verifies that the get_user_packages method raises a PyPiExtractorError.
105105
"""
106-
pypi_info = PyPIPackageInfo("testuser")
106+
pypi_info = PyPiExtractor("testuser")
107107

108-
with pytest.raises(PyPIPackageInfoError, match="Error fetching user profile: Request error"):
108+
with pytest.raises(PyPiExtractorError, match="Error fetching user profile: Request error"):
109109
pypi_info.get_user_packages()
110110

111111

@@ -117,7 +117,7 @@ def test_get_package_details_success(mock_get_package_details_success) -> None:
117117
to return a successful response and verifies that the get_package_details method returns
118118
the expected package details.
119119
"""
120-
pypi_info = PyPIPackageInfo("testuser")
120+
pypi_info = PyPiExtractor("testuser")
121121
details: Dict[str, Any] = pypi_info.get_package_details("Package1")
122122

123123
assert details['name'] == "Package1" # nosec: B101
@@ -141,11 +141,11 @@ def test_get_package_details_error(mock_get_package_details_error) -> None: # n
141141
Test get_package_details method when there is an error.
142142
143143
This test uses the mock_get_package_details_error fixture to mock requests.get method
144-
to raise an exception and verifies that the get_package_details method raises a PyPIPackageInfoError.
144+
to raise an exception and verifies that the get_package_details method raises a PyPiExtractorError.
145145
"""
146-
pypi_info = PyPIPackageInfo("testuser")
146+
pypi_info = PyPiExtractor("testuser")
147147

148-
with pytest.raises(PyPIPackageInfoError, match="Error fetching package details: Request error"):
148+
with pytest.raises(PyPiExtractorError, match="Error fetching package details: Request error"):
149149
pypi_info.get_package_details("Package1")
150150

151151

@@ -157,7 +157,7 @@ def test_get_all_packages_details_success(mock_get_all_packages_details_success)
157157
to return a successful response for both user packages and package details, and verifies that
158158
the get_all_packages_details method returns the expected list of detailed package information.
159159
"""
160-
pypi_info = PyPIPackageInfo("testuser")
160+
pypi_info = PyPiExtractor("testuser")
161161
details: List = pypi_info.get_all_packages_details()
162162

163163
assert len(details) == 2 # nosec: B101

wolfsoftware/pypi_extractor/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
import importlib.metadata
1010

11-
from .exceptions import PyPIPackageInfoError
12-
from .pypi import PyPIPackageInfo
11+
from .exceptions import PyPiExtractorError
12+
from .pypi import PyPiExtractor
1313

1414
try:
1515
__version__: str = importlib.metadata.version('pypi_extractor')
1616
except importlib.metadata.PackageNotFoundError:
1717
__version__ = 'unknown'
1818

1919
__all__: list[str] = [
20-
'PyPIPackageInfoError',
21-
'PyPIPackageInfo'
20+
'PyPiExtractorError',
21+
'PyPiExtractor'
2222
]

wolfsoftware/pypi_extractor/exceptions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
2-
This module defines custom exceptions for the PyPI package info retriever.
2+
This module defines custom exceptions for the PyPI Extractor package.
33
44
Classes:
5-
- PyPIPackageInfoError: A custom exception class for errors in the PyPIPackageInfo class.
5+
- PyPiExtractorError: A custom exception class for errors in the PyPiExtractor class.
66
"""
77

88

9-
class PyPIPackageInfoError(Exception):
9+
class PyPiExtractorError(Exception):
1010
"""
1111
Custom exception class for PyPIPackageInfo errors.
1212

wolfsoftware/pypi_extractor/pypi.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
"""
2-
This module defines the PyPIPackageInfo class for fetching and processing package details from PyPI.
2+
This module defines the PyPiExtractor class for fetching and processing package details from PyPI.
33
44
Classes:
5-
- PyPIPackageInfo: A class to fetch and process package details for a given PyPI user.
5+
- PyPiExtractor: A class to fetch and process package details for a given PyPI user.
66
"""
77
from typing import Any, Dict, List, Optional
88

99
import json
1010
import requests
1111
from bs4 import BeautifulSoup
1212

13-
from .exceptions import PyPIPackageInfoError
13+
from .exceptions import PyPiExtractorError
1414

1515

16-
class PyPIPackageInfo:
16+
class PyPiExtractor:
1717
"""
1818
A class to fetch and process package details for a given PyPI user.
1919
@@ -41,7 +41,7 @@ def set_username(self, username: str) -> None:
4141
PyPIPackageInfoError: If the username is not provided.
4242
"""
4343
if not username:
44-
raise PyPIPackageInfoError("Username must be provided")
44+
raise PyPiExtractorError("Username must be provided")
4545
self.username = username
4646

4747
def get_user_packages(self) -> List[Dict[str, str]]:
@@ -55,14 +55,14 @@ def get_user_packages(self) -> List[Dict[str, str]]:
5555
PyPIPackageInfoError: If the username is not set or if there is an error fetching or parsing the user profile.
5656
"""
5757
if not self.username:
58-
raise PyPIPackageInfoError("Username must be set before fetching packages")
58+
raise PyPiExtractorError("Username must be set before fetching packages")
5959

6060
profile_url: str = "https://pypi.org/user/" + self.username + "/"
6161
try:
6262
response: requests.Response = requests.get(profile_url, timeout=10)
6363
response.raise_for_status()
6464
except requests.RequestException as e:
65-
raise PyPIPackageInfoError(f"Error fetching user profile: {e}") from e
65+
raise PyPiExtractorError(f"Error fetching user profile: {e}") from e
6666

6767
soup = BeautifulSoup(response.text, 'html.parser')
6868
packages: List[Dict[str, str]] = []
@@ -72,7 +72,7 @@ def get_user_packages(self) -> List[Dict[str, str]]:
7272
summary: str = project.find('p', class_='package-snippet__description').text.strip()
7373
packages.append({'name': package_name, 'summary': summary})
7474
except AttributeError as e:
75-
raise PyPIPackageInfoError(f"Error parsing package details: {e}") from e
75+
raise PyPiExtractorError(f"Error parsing package details: {e}") from e
7676

7777
return packages
7878

@@ -94,12 +94,12 @@ def get_package_details(self, package_name: str) -> Dict[str, Any]:
9494
response: requests.Response = requests.get(url, timeout=10)
9595
response.raise_for_status()
9696
except requests.RequestException as e:
97-
raise PyPIPackageInfoError(f"Error fetching package details: {e}") from e
97+
raise PyPiExtractorError(f"Error fetching package details: {e}") from e
9898

9999
try:
100100
package_data: Any = response.json()
101101
except json.JSONDecodeError as e:
102-
raise PyPIPackageInfoError(f"Error decoding JSON response: {e}") from e
102+
raise PyPiExtractorError(f"Error decoding JSON response: {e}") from e
103103

104104
info: Any = package_data.get('info', {})
105105
current_version: str = info.get('version')
@@ -149,21 +149,21 @@ def get_all_packages_details(self) -> List[Dict[str, Any]]:
149149
PyPIPackageInfoError: If there is an error fetching or processing the package details.
150150
"""
151151
if not self.username:
152-
raise PyPIPackageInfoError("Username must be set before fetching package details")
152+
raise PyPiExtractorError("Username must be set before fetching package details")
153153

154154
try:
155155
packages: List[Dict[str, str]] = self.get_user_packages()
156-
except PyPIPackageInfoError as e:
157-
raise PyPIPackageInfoError(f"Failed to get user packages: {e}") from e
156+
except PyPiExtractorError as e:
157+
raise PyPiExtractorError(f"Failed to get user packages: {e}") from e
158158

159159
if not packages:
160-
raise PyPIPackageInfoError(f"No packages found for user/organization '{self.username}'")
160+
raise PyPiExtractorError(f"No packages found for user/organization '{self.username}'")
161161

162162
detailed_packages: List[Dict[str, Any]] = []
163163
for package in packages:
164164
try:
165165
details: Dict[str, Any] = self.get_package_details(package['name'])
166166
detailed_packages.append(details)
167-
except PyPIPackageInfoError as e:
168-
raise PyPIPackageInfoError(f"Failed to get details for package '{package['name']}': {e}") from e
167+
except PyPiExtractorError as e:
168+
raise PyPiExtractorError(f"Failed to get details for package '{package['name']}': {e}") from e
169169
return detailed_packages

0 commit comments

Comments
 (0)