Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(version): comply with pep 440 for dev version str #1854

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ message: If you use this software, please cite both the article from preferred-c
and the software itself.
type: software
title: FloPy
version: 3.4.0+
version: 3.dev4
date-released: '2023-06-29'
doi: 10.5066/F7BK19FH
abstract: A Python package to create, run, and post-process MODFLOW-based models.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<img src="https://raw.githubusercontent.com/modflowpy/flopy/master/examples/images/flopy3.png" alt="flopy3" style="width:50;height:20">

### Version 3.4.0+ (preliminary)
### Version 3.dev4 (preliminary)
[![flopy continuous integration](https://github.com/modflowpy/flopy/actions/workflows/commit.yml/badge.svg?branch=develop)](https://github.com/modflowpy/flopy/actions/workflows/commit.yml)
[![Read the Docs](https://github.com/modflowpy/flopy/actions/workflows/rtd.yml/badge.svg?branch=develop)](https://github.com/modflowpy/flopy/actions/workflows/rtd.yml)

Expand Down Expand Up @@ -142,7 +142,7 @@ How to Cite

##### ***Software/Code citation for FloPy:***

[Bakker, Mark, Post, Vincent, Hughes, J. D., Langevin, C. D., White, J. T., Leaf, A. T., Paulinski, S. R., Bellino, J. C., Morway, E. D., Toews, M. W., Larsen, J. D., Fienen, M. N., Starn, J. J., Brakenhoff, D. A., and Bonelli, W. P., 2023, FloPy v3.4.0+ (preliminary): U.S. Geological Survey Software Release, 29 June 2023, https://doi.org/10.5066/F7BK19FH](https://doi.org/10.5066/F7BK19FH)
[Bakker, Mark, Post, Vincent, Hughes, J. D., Langevin, C. D., White, J. T., Leaf, A. T., Paulinski, S. R., Bellino, J. C., Morway, E. D., Toews, M. W., Larsen, J. D., Fienen, M. N., Starn, J. J., Brakenhoff, D. A., and Bonelli, W. P., 2023, FloPy v3.dev4 (preliminary): U.S. Geological Survey Software Release, 29 June 2023, https://doi.org/10.5066/F7BK19FH](https://doi.org/10.5066/F7BK19FH)


Additional FloPy Related Publications
Expand Down
8 changes: 3 additions & 5 deletions autotest/test_flopy_module.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import re
from packaging.version import Version
from pathlib import Path

import numpy as np
Expand All @@ -9,11 +10,8 @@

def test_import_and_version_string():
import flopy

# matches any 1-3 component, dot-separated version string
# https://stackoverflow.com/a/82205/6514033
pattern = r"^(\d+\.)?(\d+\.)?(\*|\d+)$"
assert re.match(pattern, flopy.__version__)
# an error is raised if the version string can't be parsed
Version(flopy.__version__)


def test_modflow():
Expand Down
2 changes: 1 addition & 1 deletion code.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"downloadURL": "https://code.usgs.gov/usgs/modflow/flopy/archive/master.zip",
"vcs": "git",
"laborHours": -1,
"version": "3.4.0+",
"version": "3.dev4",
"date": {
"metadataLastUpdated": "2023-06-29"
},
Expand Down
2 changes: 1 addition & 1 deletion docs/PyPI_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ How to Cite

*Software/Code citation for FloPy:*

[Bakker, Mark, Post, Vincent, Hughes, J. D., Langevin, C. D., White, J. T., Leaf, A. T., Paulinski, S. R., Bellino, J. C., Morway, E. D., Toews, M. W., Larsen, J. D., Fienen, M. N., Starn, J. J., Brakenhoff, D. A., and Bonelli, W. P., 2023, FloPy v3.4.0+ (preliminary): U.S. Geological Survey Software Release, 29 June 2023, https://doi.org/10.5066/F7BK19FH](https://doi.org/10.5066/F7BK19FH)
[Bakker, Mark, Post, Vincent, Hughes, J. D., Langevin, C. D., White, J. T., Leaf, A. T., Paulinski, S. R., Bellino, J. C., Morway, E. D., Toews, M. W., Larsen, J. D., Fienen, M. N., Starn, J. J., Brakenhoff, D. A., and Bonelli, W. P., 2023, FloPy v3.dev4 (preliminary): U.S. Geological Survey Software Release, 29 June 2023, https://doi.org/10.5066/F7BK19FH](https://doi.org/10.5066/F7BK19FH)


Disclaimer
Expand Down
13 changes: 2 additions & 11 deletions flopy/version.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
# flopy version file automatically created using update_version.py on June 29, 2023 04:31:09

# created on...June 29, 2023 04:31:09

major = 3
minor = 4
micro = 0
label = "+"
__version__ = "{:d}.{:d}.{:d}".format(major, minor, micro)
if label:
__version__ += "{}{}".format(__version__, label)
# flopy version file automatically created using update_version.py on June 29, 2023 01:00:54
__version__ = "3.dev4"
65 changes: 10 additions & 55 deletions scripts/update_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import yaml
from filelock import FileLock
from packaging.version import Version, parse

_project_name = "flopy"
_project_root_path = Path(__file__).parent.parent
Expand Down Expand Up @@ -59,42 +60,8 @@ def split_nonnumeric(s):
return [s[: match.start()], s[match.start() :]] if match else s


class Version(NamedTuple):
"""Semantic version number, optionally with a short label.
The label may contain numbers but must not begin with a number."""

major: int = 0
minor: int = 0
patch: int = 0
label: Optional[str] = None

def __repr__(self):
s = f"{self.major}.{self.minor}.{self.patch}"
if self.label is not None and self.label != "":
s += self.label
return s

@classmethod
def from_string(cls, version: str) -> "Version":
t = version.split(".")
assert len(t) > 2
vmajor = int(t[0])
vminor = int(t[1])
tt = split_nonnumeric(t[2])
vpatch = int(tt[0])
vlabel = tt[1] if len(tt) > 1 else None
return cls(major=vmajor, minor=vminor, patch=vpatch, label=vlabel)

@classmethod
def from_file(cls, path: PathLike) -> "Version":
path = Path(path).expanduser().absolute()
lines = [line.rstrip("\n") for line in open(Path(path), "r")]
assert len(lines) == 1
return Version.from_string(lines[0])


_initial_version = Version(0, 0, 1)
_current_version = Version.from_file(_version_txt_path)
_initial_version = Version("0.0.1")
_current_version = Version(_version_txt_path.read_text().strip())


def get_disclaimer(approved: bool = False):
Expand All @@ -113,21 +80,7 @@ def update_version_py(timestamp: datetime, version: Version):
f"# {_project_name} version file automatically created using "
f"{Path(__file__).name} on {timestamp:%B %d, %Y %H:%M:%S}\n\n"
)
f.write(
"# created on..." + f"{timestamp.strftime('%B %d, %Y %H:%M:%S')}\n"
)
f.write("\n")
f.write(f"major = {version.major}\n")
f.write(f"minor = {version.minor}\n")
f.write(f"micro = {version.patch}\n")
f.write(
"label = "
+ (("'" + version.label + "'") if version.label else "''")
+ "\n"
)
f.write("__version__ = '{:d}.{:d}.{:d}'.format(major, minor, micro)\n")
f.write("if label:\n")
f.write("\t__version__ += '{}{}'.format(__version__, label)")
f.write(f"__version__ = '{version}'\n")
f.close()
print(f"Updated {_version_py_path} to version {version}")

Expand Down Expand Up @@ -317,11 +270,11 @@ def update_version(
lock_path = Path(_version_txt_path.name + ".lock")
try:
lock = FileLock(lock_path)
previous = Version.from_file(_version_txt_path)
previous = Version(_version_txt_path.read_text().strip())
version = (
version
if version
else Version(previous.major, previous.minor, previous.patch)
else Version(previous.major, previous.minor, previous.micro)
)

with lock:
Expand Down Expand Up @@ -375,11 +328,13 @@ def update_version(
args = parser.parse_args()

if args.get:
print(Version.from_file(_project_root_path / "version.txt"))
print(
Version((_project_root_path / "version.txt").read_text().strip())
)
else:
update_version(
timestamp=datetime.now(),
version=Version.from_string(args.version)
version=Version(args.version)
if args.version
else _current_version,
approved=args.approve,
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.4.0+
3.dev4
Loading