Skip to content

Commit

Permalink
Use flit
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Apr 17, 2022
1 parent 22846c2 commit 2091cc2
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 83 deletions.
33 changes: 0 additions & 33 deletions MANIFEST.in

This file was deleted.

37 changes: 23 additions & 14 deletions pyproject.toml
@@ -1,6 +1,6 @@
[build-system]
requires = ["setuptools>=62", "wheel"]
build-backend = "setuptools.build_meta"
requires = ["flit_core>=3.7"]
build-backend = "flit_core.buildapi"

# project metadata
[project]
Expand Down Expand Up @@ -108,16 +108,25 @@ sphinx-autogen = "sphinx.ext.autosummary.generate:main"
[project.entry-points."distutils.commands"]
build_sphinx = 'sphinx.setup_command:BuildDoc'

[tool.setuptools]
zip-safe = false
platforms = ["any"]
package-data = {"sphinx" = ["py.typed"]}
include-package-data = true
license-files = ["LICENSE"]
[tool.flit.module]
name = "sphinx"

[tool.setuptools.packages.find]
where = ["."]
include = ['sphinx*']

[tool.setuptools.dynamic]
version.attr = "sphinx.__released__" # sphinx.__version__ breaks PEP 440 rules
[tool.flit.sdist]
include = [
"LICENSE",
"AUTHORS",
"CHANGES",
# Documentation
"doc/",
"CODE_OF_CONDUCT", # used as an include
"EXAMPLES", # used as an include
# Tests
"tests/",
"tox.ini",
# Utilities
"utils/",
"babel.cfg",
]
exclude = [
"doc/_build",
]
4 changes: 0 additions & 4 deletions setup.cfg
@@ -1,7 +1,3 @@
[egg_info]
tag_build = .dev
tag_date = true

[flake8]
max-line-length = 95
ignore = E116,E241,E251,E741,W504,I101
Expand Down
34 changes: 17 additions & 17 deletions sphinx/__init__.py
Expand Up @@ -17,8 +17,8 @@
warnings.filterwarnings('ignore', "'U' mode is deprecated",
DeprecationWarning, module='docutils.io')

__version__ = '5.0.0+'
__released__ = '5.0.0' # used when Sphinx builds its own docs
__version__ = '5.0.0'
__display_version__ = __version__ # used for command line version

#: Version info for better programmatic use.
#:
Expand All @@ -32,22 +32,22 @@

package_dir = path.abspath(path.dirname(__file__))

__display_version__ = __version__ # used for command line version
if __version__.endswith('+'):
_in_development = True
if _in_development:
# Only import subprocess if needed
import subprocess

# try to find out the commit hash if checked out from git, and append
# it to __version__
__display_version__ = __version__
__version__ = __version__[:-1] # remove '+' for PEP-440 version spec.
try:
ret = subprocess.run(['git', 'show', '-s', '--pretty=format:%h'],
cwd=package_dir,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding='ascii')
if ret.stdout:
__display_version__ += '/' + ret.stdout.strip()
except subprocess.SubprocessError:
pass
ret = subprocess.run(
['git', 'show', '-s', '--pretty=format:%h'],
cwd=package_dir,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding='ascii'
).stdout
if ret:
__display_version__ += '+/' + ret.strip()
del ret
finally:
del subprocess
del _in_development
1 change: 1 addition & 0 deletions tox.ini
@@ -1,6 +1,7 @@
[tox]
minversion = 2.4.0
envlist = docs,flake8,mypy,twine,coverage,py{36,37,38,39,310},du{14,15,16,17}
isolated_build = True

[testenv]
usedevelop = True
Expand Down
34 changes: 19 additions & 15 deletions utils/bump_version.py
Expand Up @@ -23,19 +23,23 @@ def stringify_version(version_info, in_develop=True):

def bump_version(path, version_info, in_develop=True):
version = stringify_version(version_info, in_develop)
release = version
if in_develop:
version += '+'

with open(path, 'r+') as f:
body = f.read()
body = re.sub(r"(?<=__version__ = ')[^']+", version, body)
body = re.sub(r"(?<=__released__ = ')[^']+", release, body)
body = re.sub(r"(?<=version_info = )\(.*\)", str(version_info), body)
with open(path, 'r', encoding='utf-8') as f:
lines = f.read().splitlines()

f.seek(0)
f.truncate(0)
f.write(body)
for i, line in enumerate(lines):
if line.startswith('__version__ = '):
lines[i] = f"__version__ = '{version}'"
continue
if line.startswith('version_info = '):
lines[i] = f'version_info = {version_info}'
continue
if line.startswith('_in_development = '):
lines[i] = f'_in_development = {in_develop}'
continue

with open(path, 'w', encoding='utf-8') as f:
f.write('\n'.join(lines) + '\n')


def parse_version(version):
Expand Down Expand Up @@ -88,7 +92,7 @@ def __init__(self, path):
self.fetch_version()

def fetch_version(self):
with open(self.path) as f:
with open(self.path, encoding='utf-8') as f:
version = f.readline().strip()
matched = re.search(r'^Release (.*) \((.*)\)$', version)
if matched is None:
Expand All @@ -105,7 +109,7 @@ def finalize_release_date(self):
release_date = datetime.now().strftime('%b %d, %Y')
heading = 'Release %s (released %s)' % (self.version, release_date)

with open(self.path, 'r+') as f:
with open(self.path, 'r+', encoding='utf-8') as f:
f.readline() # skip first two lines
f.readline()
body = f.read()
Expand All @@ -126,12 +130,12 @@ def add_release(self, version_info):
version_info[4] or '')
heading = 'Release %s (in development)' % version

with open(os.path.join(script_dir, 'CHANGES_template')) as f:
with open(os.path.join(script_dir, 'CHANGES_template'), encoding='utf-8') as f:
f.readline() # skip first two lines
f.readline()
tmpl = f.read()

with open(self.path, 'r+') as f:
with open(self.path, 'r+', encoding='utf-8') as f:
body = f.read()

f.seek(0)
Expand Down

0 comments on commit 2091cc2

Please sign in to comment.