Skip to content

Commit b53ca97

Browse files
committed
Permit versioning without git repo
1 parent 811ca37 commit b53ca97

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ COPY --from=jl /usr/local/julia /usr/local/julia
1313
ENV PATH="/usr/local/julia/bin:${PATH}"
1414

1515
# Install IPython and other useful libraries:
16-
RUN pip install ipython matplotlib
16+
RUN pip install --no-cache-dir ipython matplotlib
1717

1818
WORKDIR /pysr
1919

2020
# Caches install (https://stackoverflow.com/questions/25305788/how-to-avoid-reinstalling-packages-when-building-docker-image-for-python-project)
2121
ADD ./requirements.txt /pysr/requirements.txt
22-
RUN pip3 install -r /pysr/requirements.txt
22+
RUN pip3 install --no-cache-dir -r /pysr/requirements.txt
2323

2424
# Install PySR:
2525
# We do a minimal copy so it doesn't need to rerun at every file change:
2626
ADD ./pyproject.toml /pysr/pyproject.toml
2727
ADD ./setup.py /pysr/setup.py
28-
ADD ./pysr/ /pysr/pysr/
29-
RUN pip3 install .
28+
ADD ./pysr /pysr/pysr
29+
RUN pip3 install --no-cache-dir -e .
3030

3131
# Install Julia pre-requisites:
3232
RUN python3 -c 'import pysr'

pyproject.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools", "setuptools_scm"]
2+
requires = ["setuptools"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
@@ -27,8 +27,5 @@ package-data = {pysr = ["../datasets/*"]}
2727
[tool.setuptools.dynamic]
2828
dependencies = {file = "requirements.txt"}
2929

30-
[tool.setuptools_scm]
31-
write_to = "pysr/version.py"
32-
3330
[tool.isort]
3431
profile = "black"

setup.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
1+
import os
2+
13
from setuptools import setup
24

5+
if os.path.exists(".git"):
6+
kwargs = {
7+
"use_scm_version": {
8+
"write_to": "pysr/version.py",
9+
},
10+
"setup_requires": ["setuptools", "setuptools_scm"],
11+
}
12+
else:
13+
# Read from pyproject.toml directly
14+
import re
15+
16+
with open(os.path.join(os.path.dirname(__file__), "pyproject.toml")) as f:
17+
data = f.read()
18+
# Find the version
19+
version = re.search(r'version = "(.*)"', data).group(1)
20+
21+
# Write the version to version.py
22+
with open(os.path.join(os.path.dirname(__file__), "pysr", "version.py"), "w") as f:
23+
f.write(f'__version__ = "{version}"')
24+
25+
kwargs = {
26+
"use_scm_version": False,
27+
"version": version,
28+
}
29+
30+
331
# Build options are managed in pyproject.toml
4-
setup()
32+
setup(**kwargs)

0 commit comments

Comments
 (0)