MilesCranmer commited on
Commit
b53ca97
1 Parent(s): 811ca37

Permit versioning without git repo

Browse files
Files changed (3) hide show
  1. Dockerfile +4 -4
  2. pyproject.toml +1 -4
  3. setup.py +29 -1
Dockerfile CHANGED
@@ -13,20 +13,20 @@ COPY --from=jl /usr/local/julia /usr/local/julia
13
  ENV PATH="/usr/local/julia/bin:${PATH}"
14
 
15
  # Install IPython and other useful libraries:
16
- RUN pip install ipython matplotlib
17
 
18
  WORKDIR /pysr
19
 
20
  # Caches install (https://stackoverflow.com/questions/25305788/how-to-avoid-reinstalling-packages-when-building-docker-image-for-python-project)
21
  ADD ./requirements.txt /pysr/requirements.txt
22
- RUN pip3 install -r /pysr/requirements.txt
23
 
24
  # Install PySR:
25
  # We do a minimal copy so it doesn't need to rerun at every file change:
26
  ADD ./pyproject.toml /pysr/pyproject.toml
27
  ADD ./setup.py /pysr/setup.py
28
- ADD ./pysr/ /pysr/pysr/
29
- RUN pip3 install .
30
 
31
  # Install Julia pre-requisites:
32
  RUN python3 -c 'import pysr'
 
13
  ENV PATH="/usr/local/julia/bin:${PATH}"
14
 
15
  # Install IPython and other useful libraries:
16
+ RUN pip install --no-cache-dir ipython matplotlib
17
 
18
  WORKDIR /pysr
19
 
20
  # Caches install (https://stackoverflow.com/questions/25305788/how-to-avoid-reinstalling-packages-when-building-docker-image-for-python-project)
21
  ADD ./requirements.txt /pysr/requirements.txt
22
+ RUN pip3 install --no-cache-dir -r /pysr/requirements.txt
23
 
24
  # Install PySR:
25
  # We do a minimal copy so it doesn't need to rerun at every file change:
26
  ADD ./pyproject.toml /pysr/pyproject.toml
27
  ADD ./setup.py /pysr/setup.py
28
+ ADD ./pysr /pysr/pysr
29
+ RUN pip3 install --no-cache-dir -e .
30
 
31
  # Install Julia pre-requisites:
32
  RUN python3 -c 'import pysr'
pyproject.toml CHANGED
@@ -1,5 +1,5 @@
1
  [build-system]
2
- requires = ["setuptools", "setuptools_scm"]
3
  build-backend = "setuptools.build_meta"
4
 
5
  [project]
@@ -27,8 +27,5 @@ package-data = {pysr = ["../datasets/*"]}
27
  [tool.setuptools.dynamic]
28
  dependencies = {file = "requirements.txt"}
29
 
30
- [tool.setuptools_scm]
31
- write_to = "pysr/version.py"
32
-
33
  [tool.isort]
34
  profile = "black"
 
1
  [build-system]
2
+ requires = ["setuptools"]
3
  build-backend = "setuptools.build_meta"
4
 
5
  [project]
 
27
  [tool.setuptools.dynamic]
28
  dependencies = {file = "requirements.txt"}
29
 
 
 
 
30
  [tool.isort]
31
  profile = "black"
setup.py CHANGED
@@ -1,4 +1,32 @@
 
 
1
  from setuptools import setup
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  # Build options are managed in pyproject.toml
4
- setup()
 
1
+ import os
2
+
3
  from setuptools import setup
4
 
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
+
31
  # Build options are managed in pyproject.toml
32
+ setup(**kwargs)