Skip to content

Commit

Permalink
Update sphinx build with setup.py. Don't evaluate default argumentscl…
Browse files Browse the repository at this point in the history
…oses #175
  • Loading branch information
kuzmoyev committed May 7, 2024
1 parent 5413530 commit 001ae21
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ build
dist
.eggs
gcsa.egg-info
docs/html

example.py
coverage.xml
Expand Down
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,5 @@
'css/custom.css',
'css/colors.css',
]

autodoc_preserve_defaults = True
67 changes: 45 additions & 22 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
#!/usr/bin/env python3
import subprocess

from setuptools import setup, find_packages, Command
from shutil import rmtree
import os
import sys

try:
from sphinx.setup_command import BuildDoc
except ImportError:
class BuildDoc(Command):
user_options = []

def initialize_options(self) -> None:
pass

def finalize_options(self) -> None:
pass

def run(self):
raise

here = os.path.abspath(os.path.dirname(__file__))

VERSION = '2.2.0'
Expand Down Expand Up @@ -66,6 +52,49 @@ def run(self):
sys.exit()


class BuildDoc(Command):
user_options = []

def initialize_options(self) -> None:
pass

def finalize_options(self) -> None:
pass

def run(self):
output_path = 'docs/html'
changed_files = []
cmd = [
'sphinx-build',
'docs/source', output_path,
'--builder', 'html',
'--define', f'version={VERSION}',
'--verbose'
]
with subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
bufsize=1,
universal_newlines=True
) as p:
for line in p.stdout:
print(line, end='')
if line.startswith('reading sources... ['):
file_name = line.rsplit(maxsplit=1)[1]
if file_name:
changed_files.append(file_name + '.html')

index_path = os.path.join(os.getcwd(), output_path, 'index.html')
print('\nIndex:')
print(f'file://{index_path}')

if changed_files:
print('Update pages:')
for cf in changed_files:
f_path = os.path.join(os.getcwd(), output_path, cf)
print(cf, f'file://{f_path}')


with open('README.rst') as f:
long_description = ''.join(f.readlines())

Expand Down Expand Up @@ -132,11 +161,5 @@ def run(self):
cmdclass={
'upload': UploadCommand,
'docs': BuildDoc,
},
command_options={
'docs': {
'version': ('setup.py', VERSION),
'build_dir': ('setup.py', 'docs/build')
}
},
}
)

0 comments on commit 001ae21

Please sign in to comment.