Skip to content

Commit 728bdad

Browse files
Refactor setup.py: Improve long description and requirements loading; add version fetching utility
1 parent d87940d commit 728bdad

File tree

2 files changed

+69
-40
lines changed

2 files changed

+69
-40
lines changed

fetch_and_bump_version.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import requests
2+
3+
def get_incremented_version(package_name: str) -> str:
4+
5+
try:
6+
url = f"https://pypi.org/pypi/{package_name}/json"
7+
response = requests.get(url)
8+
response.raise_for_status()
9+
data = response.json()
10+
11+
latest_version = data['info']['version']
12+
version_parts = latest_version.split('.')
13+
14+
# Convert last part to int and increment
15+
version_parts[-1] = str(int(version_parts[-1]) + 1)
16+
17+
incremented_version = '.'.join(version_parts)
18+
return incremented_version
19+
except requests.exceptions.RequestException as e:
20+
print(f"Failed to fetch version for package '{package_name}': {e}")
21+
except Exception as e:
22+
print(f"Error processing version: {e}")
23+
24+
return "0.0.1"

setup.py

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,67 @@
11
from setuptools import setup, find_packages
2+
from fetch_and_bump_version import get_incremented_version
3+
import os
24

3-
# Read the long description from README.md
4-
try:
5-
with open("README.md", "r", encoding="utf-8") as fh:
6-
long_description = fh.read()
7-
except FileNotFoundError:
8-
long_description = (
9-
"A simple command-line tool to count lines in files by extension. "
10-
"See the documentation for more details."
11-
)
5+
# ---------------------- Package Metadata ---------------------- #
126

13-
# Read the list of requirements from requirements.txt
14-
try:
15-
with open("requirements.txt", "r", encoding="utf-8") as fh:
16-
requirements = fh.read().splitlines()
17-
except FileNotFoundError:
18-
requirements = ["tabulate==0.9.0"]
7+
PACKAGE_NAME = "extliner"
8+
AUTHOR = "Deepak Raj"
9+
AUTHOR_EMAIL = "[email protected]"
10+
DESCRIPTION = "A simple command-line tool to count lines in files by extension."
11+
PYTHON_REQUIRES = ">=3.6"
12+
GITHUB_USER = "codeperfectplus"
13+
GITHUB_URL = f"https://github.com/{GITHUB_USER}/{PACKAGE_NAME}"
14+
DOCS_URL = f"https://{PACKAGE_NAME}.readthedocs.io/en/latest/"
15+
16+
# ---------------------- Utility Functions ---------------------- #
17+
18+
def load_file_content(file_path):
19+
"""Read and return the contents of a file if it exists."""
20+
if os.path.exists(file_path):
21+
with open(file_path, encoding="utf-8") as f:
22+
return f.read().strip()
23+
return ""
24+
25+
def load_requirements(file_path):
26+
"""Parse requirements from a file."""
27+
content = load_file_content(file_path)
28+
return content.splitlines() if content else []
29+
30+
# ---------------------- Setup Execution ---------------------- #
1931

2032
setup(
21-
name="extliner",
22-
version="0.0.1",
23-
author="Deepak Raj",
24-
author_email="[email protected]",
25-
description=(
26-
"A simple command-line tool to count lines in files by extension, "
27-
),
28-
long_description=long_description,
33+
name=PACKAGE_NAME,
34+
version=get_incremented_version(PACKAGE_NAME),
35+
author=AUTHOR,
36+
author_email=AUTHOR_EMAIL,
37+
description=DESCRIPTION,
38+
long_description=load_file_content("README.md"),
2939
long_description_content_type="text/markdown",
30-
url="https://github.com/codeperfectplus/extliner",
40+
url=GITHUB_URL,
3141
packages=find_packages(),
3242
include_package_data=True,
33-
install_requires=requirements,
34-
python_requires=">=3.6",
43+
install_requires=load_requirements("requirements.txt"),
44+
python_requires=PYTHON_REQUIRES,
3545
classifiers=[
3646
"Development Status :: 5 - Production/Stable",
3747
"Programming Language :: Python :: 3",
3848
"Operating System :: OS Independent",
39-
"Intended Audience :: Developers"
49+
"Intended Audience :: Developers",
50+
"License :: OSI Approved :: MIT License"
4051
],
4152
project_urls={
42-
"Documentation": "https://extliner.readthedocs.io/en/latest/",
43-
"Source": "https://github.com/codeperfectplus/extliner",
44-
"Tracker": "https://github.com/codeperfectplus/extliner/issues"
53+
"Documentation": DOCS_URL,
54+
"Source": GITHUB_URL,
55+
"Tracker": f"{GITHUB_URL}/issues",
4556
},
4657
entry_points={
4758
"console_scripts": [
48-
"extliner=extliner.cli:main", # Update path if needed
59+
f"{PACKAGE_NAME}={PACKAGE_NAME}.cli:main",
4960
],
5061
},
5162
keywords=[
52-
"line count",
53-
"file analysis",
54-
"command line tool",
55-
"file extension",
56-
"python",
57-
"CLI",
58-
"file processing",
59-
63+
"line count", "file analysis", "command line tool",
64+
"file extension", "python", "CLI", "file processing",
6065
],
6166
license="MIT",
62-
)
67+
)

0 commit comments

Comments
 (0)