Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit26dccd7

Browse files
committed
Streamline setup.py file reading
This is partly a refactoring, reducing logic duplication andslightly decreasing overall length of the code that reads valuesfrom 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 notmake any changes to the version stamping code.
1 parent1b43166 commit26dccd7

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

‎setup.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,22 @@
22

33
importos
44
importsys
5+
frompathlibimportPath
56
fromtypingimportSequence
67

78
fromsetuptoolsimportsetup,find_packages
89
fromsetuptools.command.build_pyimportbuild_pyas_build_py
910
fromsetuptools.command.sdistimportsdistas_sdist
1011

1112

12-
withopen(os.path.join(os.path.dirname(__file__),"VERSION"),encoding="utf-8")asver_file:
13-
VERSION=ver_file.readline().strip()
13+
def_read_content(path:str)->str:
14+
return (Path(__file__).parent/path).read_text(encoding="utf-8")
1415

15-
withopen("requirements.txt",encoding="utf-8")asreqs_file:
16-
requirements=reqs_file.read().splitlines()
1716

18-
withopen("test-requirements.txt",encoding="utf-8")asreqs_file:
19-
test_requirements=reqs_file.read().splitlines()
20-
21-
withopen("README.md",encoding="utf-8")asrm_file:
22-
long_description=rm_file.read()
17+
version=_read_content("VERSION").strip()
18+
requirements=_read_content("requirements.txt").splitlines()
19+
test_requirements=_read_content("test-requirements.txt").splitlines()
20+
long_description=_read_content("README.md")
2321

2422

2523
classbuild_py(_build_py):
@@ -50,7 +48,7 @@ def _stamp_version(filename: str) -> None:
5048
withopen(filename)asf:
5149
forlineinf:
5250
if"__version__ ="inline:
53-
line=line.replace('"git"',"'%s'"%VERSION)
51+
line=line.replace('"git"',"'%s'"%version)
5452
found=True
5553
out.append(line)
5654
exceptOSError:
@@ -66,7 +64,7 @@ def _stamp_version(filename: str) -> None:
6664
setup(
6765
name="GitPython",
6866
cmdclass={"build_py":build_py,"sdist":sdist},
69-
version=VERSION,
67+
version=version,
7068
description="GitPython is a Python library used to interact with Git repositories",
7169
author="Sebastian Thiel, Michael Trier",
7270
author_email="byronimo@gmail.com, mtrier@gmail.com",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp