Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Streamline setup.py file reading
This is partly a refactoring, reducing logic duplication and
slightly decreasing overall length of the code that reads values
from files. However, it does make two small behavioral changes:

- In addition to the VERSION file for which this was already the
  case, requirements files and the readme are also taken relative
  to the directory that contains the setup.py file, rather than
  relative to the current directory if different. Supporting
  reading the readme and dependencies realtive to a different
  directory doesn't seem intended, and could lead to confusion in
  some cases.

- The VERSION file is now read entirely and whitespace stripped,
  rather than reading just the first line. The VERSION file should
  always contain exactly one line, and this logic is simpler.

This changes code for the reading of metadata only. It does not
make any changes to the version stamping code.
  • Loading branch information
EliahKagan committed Mar 13, 2024
commit 26dccd70713b2be6cb0af6892fd05703f17cda3e
20 changes: 9 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@

import os
import sys
from pathlib import Path
from typing import Sequence

from setuptools import setup, find_packages
from setuptools.command.build_py import build_py as _build_py
from setuptools.command.sdist import sdist as _sdist


with open(os.path.join(os.path.dirname(__file__), "VERSION"), encoding="utf-8") as ver_file:
VERSION = ver_file.readline().strip()
def _read_content(path: str) -> str:
return (Path(__file__).parent / path).read_text(encoding="utf-8")

with open("requirements.txt", encoding="utf-8") as reqs_file:
requirements = reqs_file.read().splitlines()

with open("test-requirements.txt", encoding="utf-8") as reqs_file:
test_requirements = reqs_file.read().splitlines()

with open("README.md", encoding="utf-8") as rm_file:
long_description = rm_file.read()
version = _read_content("VERSION").strip()
requirements = _read_content("requirements.txt").splitlines()
test_requirements = _read_content("test-requirements.txt").splitlines()
long_description = _read_content("README.md")


class build_py(_build_py):
Expand Down Expand Up @@ -50,7 +48,7 @@ def _stamp_version(filename: str) -> None:
with open(filename) as f:
for line in f:
if "__version__ =" in line:
line = line.replace('"git"', "'%s'" % VERSION)
line = line.replace('"git"', "'%s'" % version)
found = True
out.append(line)
except OSError:
Expand All @@ -66,7 +64,7 @@ def _stamp_version(filename: str) -> None:
setup(
name="GitPython",
cmdclass={"build_py": build_py, "sdist": sdist},
version=VERSION,
version=version,
description="GitPython is a Python library used to interact with Git repositories",
author="Sebastian Thiel, Michael Trier",
author_email="byronimo@gmail.com, mtrier@gmail.com",
Expand Down