Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
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
1 change: 1 addition & 0 deletions release/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ sh_binary(

# Dependencies to run PIP package creation.
"MANIFEST.in",
"README.md",
"setup.py",

# Dependencies that the PIP package will import.
Expand Down
1 change: 1 addition & 0 deletions release/build_pip_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ main() {

# Copy over files necessary to run setup.py
cp "${EXPORT_DIR}/release/setup.py" "${TMPDIR}"
cp "${EXPORT_DIR}/release/README.md" "${TMPDIR}"
Comment thread
mhucka marked this conversation as resolved.
Outdated
cp "${EXPORT_DIR}/release/MANIFEST.in" "${TMPDIR}"
mkdir "${TMPDIR}/tensorflow_quantum"
cp -r -v "${EXPORT_DIR}/tensorflow_quantum/"* "${TMPDIR}/tensorflow_quantum/"
Expand Down
39 changes: 32 additions & 7 deletions release/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,24 @@
from setuptools.dist import Distribution


def read_version():
"""Return the package version from tensorflow_quantum/__init__.py."""
def possible_paths_from_setup_dir(*relative_parts):
"""Return candidate paths for files accessed from setup.py."""

# Need to account for 2 situations: when setup.py is copied to a build
# directory, and when setup.py is in a 'release/' subdirectory.
here = Path(__file__).resolve().parent
possible_paths = [
here / "tensorflow_quantum" / "__init__.py",
here.parent / "tensorflow_quantum" / "__init__.py",
return [
here.joinpath(*relative_parts),
here.parent.joinpath(*relative_parts),
]


def read_version():
"""Return the package version from tensorflow_quantum/__init__.py."""

possible_paths = possible_paths_from_setup_dir("tensorflow_quantum",
"__init__.py")

for init_path in possible_paths:
if init_path.is_file():
content = init_path.read_text(encoding="utf-8")
Expand All @@ -61,7 +68,25 @@ def read_version():

CUR_VERSION = read_version()

DOCLINES = __doc__.split("\n")

def read_readme():
"""Return the project README contents for PyPI."""

possible_paths = possible_paths_from_setup_dir("README.md")
image_src_pattern = re.compile(
r'(?P<prefix>src=")(?![a-z]+://|#|/)(?P<path>[^"]+)')
image_base_url = ("https://raw.githubusercontent.com/tensorflow/quantum/"
"master/")
Comment thread
mhucka marked this conversation as resolved.
Outdated

for readme_path in possible_paths:
Comment thread
mhucka marked this conversation as resolved.
Outdated
if readme_path.is_file():
content = readme_path.read_text(encoding="utf-8")
return image_src_pattern.sub(
lambda match: f'{match.group("prefix")}{image_base_url}'
f'{match.group("path")}', content)

raise RuntimeError("Could not find README.md. Checked:\n" +
"\n".join(f" - {p}" for p in possible_paths))


class InstallPlatlib(install):
Expand Down Expand Up @@ -121,7 +146,7 @@ def has_ext_modules(self):
name=PROJECT_NAME,
version=BUILD_VERSION,
description="Library for hybrid quantum-classical machine learning.",
long_description="\n".join(DOCLINES[2:]),
long_description=read_readme(),
long_description_content_type="text/markdown",
author="The TensorFlow Quantum Authors",
author_email="tensorflow-quantum-team@google.com",
Expand Down
Loading