-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
README: Update, better usage, relative links
In README.md: - bring the Usage part up-to-date, with some better formatting - add a small demonstration in Usage - move Documentation to its own Section, so it can be found more easily - remove statement about "interfaces can break anytime", the interface should be mostly stable now - add another link to the documentation after Usage - give more details in the introduction to the Example - add a section Example Heatmaps, which shows example heatmaps for various supported attribution methods for VGG16 and ResNet50 produced by feed_forward.py - add a sub-section about the documentation in Contributing with notes about building - make absolute github links relative, such that they can point to their respective revision. They were previously absolute links for display on PyPI, which cannot correctly disply relative files. - add badge for tests - fix inconsistent capitalizations - fix Pytest link pointing to Pylint New images: - add two images to show heatmaps for VGG16 and ResNet50 In setup.py - define a function to fetch the long description for PyPI, which replaces relative links with absolute ones on github. This fixes the previous problem with relative links on PyPI, and will also display and reference files for the correct release, instead of always for master. - due to `python -m build` by default copying all files for the sdist, and then building the wheel in the same folder in an isolated environment, the revison would not be correct within the wheel. The sdist however creates a PKG-INFO file, which will contain the long_description with the absolute links, which will be used if the git version cannot be used. The fallback is to use master, as done previously.
- Loading branch information
Showing
4 changed files
with
145 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,42 @@ | ||
#!/usr/bin/env python3 | ||
import re | ||
from setuptools import setup, find_packages | ||
from subprocess import run, CalledProcessError | ||
|
||
|
||
with open('README.md', 'r', encoding='utf-8') as fd: | ||
long_description = fd.read() | ||
def get_long_description(project_path): | ||
'''Fetch the README contents and replace relative links with absolute ones | ||
pointing to github for correct behaviour on PyPI. | ||
''' | ||
try: | ||
revision = run( | ||
['git', 'describe', '--tags'], | ||
capture_output=True, | ||
check=True, | ||
text=True | ||
).stdout[:-1] | ||
except CalledProcessError: | ||
try: | ||
with open('PKG-INFO', 'r') as fd: | ||
body = fd.read().partition('\n\n')[2] | ||
if body: | ||
return body | ||
except FileNotFoundError: | ||
revision = 'master' | ||
|
||
with open('README.md', 'r', encoding='utf-8') as fd: | ||
long_description = fd.read() | ||
|
||
link_root = { | ||
'': f'https://github.com/{project_path}/blob', | ||
'!': f'https://raw.githubusercontent.com/{project_path}', | ||
} | ||
|
||
def replace(mobj): | ||
return f'{mobj[1]}[{mobj[2]}]({link_root[mobj[1]]}/{revision}/{mobj[3]})' | ||
|
||
link_rexp = re.compile(r'(!?)\[([^\]]*)\]\((?!https?://|/)([^\)]+)\)') | ||
return link_rexp.sub(replace, long_description) | ||
|
||
|
||
setup( | ||
|
@@ -12,7 +45,7 @@ | |
author='chrstphr', | ||
author_email='[email protected]', | ||
description='Attribution of Neural Networks using PyTorch', | ||
long_description=long_description, | ||
long_description=get_long_description('chr5tphr/zennit'), | ||
long_description_content_type='text/markdown', | ||
url='https://github.com/chr5tphr/zennit', | ||
packages=find_packages(include=['zennit*']), | ||
|
Binary file not shown.
Binary file not shown.