Skip to content

Commit c723fc1

Browse files
Balandatfacebook-github-bot
authored andcommitted
Allow conda build to use the setuptools_scm generated version number (#554)
Summary: Unfortunately `conda build`'s `load_setup_py_data` does not properly resolve the version number from `setuptools_scm`. The workaround implemented here is to export this version number to an env variable that we can then substitute in to the jinja template of the `meta.yaml` file. This PR adds a simple shell script to make that easier, now the conda build process just amounts to calling `/build_conda.sh` from the `.conda/` directory and the version number gets automatically added. This also required some changes to `setup.py` to make sure the relative paths are properly resolved. Pull Request resolved: #554 Reviewed By: sdaulton Differential Revision: D23713807 Pulled By: Balandat fbshipit-source-id: fbd70166dde57f4f10e21dafdc57a1b5e19a9701
1 parent b8879a3 commit c723fc1

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

.conda/build_conda.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
# Copyright (c) Facebook, Inc. and its affiliates.
3+
#
4+
# This source code is licensed under the MIT license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
BOTORCH_VERSION="$(python ../setup.py --version)"
8+
export BOTORCH_VERSION
9+
10+
conda build .

.conda/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
package:
44
name: {{ data.get("name")|lower }}
5-
version: {{ data.get("version") }}
5+
version: {{ data.get("version", environ["BOTORCH_VERSION"]) }}
66

77
source:
88
path: ..

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[tool.setuptools_scm]
2+
13
[build-system]
24
requires = ["setuptools>=34.4", "wheel", "setuptools_scm"]
35
build-backend = "setuptools.build_meta"

setup.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# This source code is licensed under the MIT license found in the
55
# LICENSE file in the root directory of this source tree.
66

7+
import os
78
import sys
89

910
from setuptools import find_packages, setup
@@ -32,8 +33,10 @@
3233

3334
TUTORIALS_REQUIRES = ["jupyter", "matplotlib", "cma", "torchvision"]
3435

36+
root_dir = os.path.dirname(__file__)
37+
3538
# read in README.md as the long description
36-
with open("README.md", "r") as fh:
39+
with open(os.path.join(root_dir, "README.md"), "r") as fh:
3740
long_description = fh.read()
3841

3942
setup(
@@ -60,7 +63,11 @@
6063
long_description_content_type="text/markdown",
6164
python_requires=">=3.7",
6265
setup_requires=["setuptools_scm"],
63-
use_scm_version={"write_to": "botorch/version.py"},
66+
use_scm_version={
67+
"root": ".",
68+
"relative_to": __file__,
69+
"write_to": os.path.join(root_dir, "botorch", "version.py"),
70+
},
6471
install_requires=["torch>=1.6", "gpytorch>=1.2", "scipy"],
6572
packages=find_packages(),
6673
extras_require={

0 commit comments

Comments
 (0)