oilprops 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,200 @@
1
+ """Resolve the next semantic release version for GitHub Actions PyPI publishing."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import os
7
+ import re
8
+ import subprocess
9
+ import sys
10
+ import urllib.error
11
+ import urllib.request
12
+ from typing import Optional, Sequence, Tuple
13
+
14
+ SEMVER_RE = re.compile(r"^v?(\d+)\.(\d+)\.(\d+)$")
15
+ PUBLISH_DIRECTIVE_RE = re.compile(r"\[publish(?::(patch|minor|major))?\]", re.IGNORECASE)
16
+ INITIAL_VERSION: Tuple[int, int, int] = (0, 1, 0)
17
+
18
+
19
+ def parse_publish_directive(commit_message: str) -> Optional[str]:
20
+ """Return 'patch', 'minor', or 'major' if commit_message requests publishing, else None."""
21
+ match = PUBLISH_DIRECTIVE_RE.search(commit_message or "")
22
+ if not match:
23
+ return None
24
+ return (match.group(1) or "patch").lower()
25
+
26
+
27
+ def parse_semver(raw: str) -> Optional[Tuple[int, int, int]]:
28
+ """Parse a strict X.Y.Z or vX.Y.Z version string."""
29
+ match = SEMVER_RE.match(raw.strip())
30
+ if not match:
31
+ return None
32
+ return int(match.group(1)), int(match.group(2)), int(match.group(3))
33
+
34
+
35
+ def format_semver(parts: Tuple[int, int, int]) -> str:
36
+ """Format (major, minor, patch) tuple as X.Y.Z."""
37
+ return f"{parts[0]}.{parts[1]}.{parts[2]}"
38
+
39
+
40
+ def bump_semver(parts: Tuple[int, int, int], bump: str) -> Tuple[int, int, int]:
41
+ """Increment major, minor, or patch component."""
42
+ major, minor, patch = parts
43
+ if bump == "major":
44
+ return (major + 1, 0, 0)
45
+ if bump == "minor":
46
+ return (major, minor + 1, 0)
47
+ if bump == "patch":
48
+ return (major, minor, patch + 1)
49
+ raise ValueError(f"Unsupported bump level: {bump!r}")
50
+
51
+
52
+ def fetch_pypi_versions(package_name: str = "oilprops") -> list[Tuple[int, int, int]]:
53
+ """Query PyPI JSON API for already-published X.Y.Z versions."""
54
+ url = f"https://pypi.org/pypi/{package_name}/json"
55
+ try:
56
+ with urllib.request.urlopen(url, timeout=15) as resp:
57
+ data = json.loads(resp.read().decode("utf-8"))
58
+ except urllib.error.HTTPError as exc:
59
+ if exc.code == 404:
60
+ return []
61
+ raise
62
+ versions: list[Tuple[int, int, int]] = []
63
+ for key in data.get("releases", {}):
64
+ parsed = parse_semver(key)
65
+ if parsed is not None:
66
+ versions.append(parsed)
67
+ return sorted(versions)
68
+
69
+
70
+ def git_tags() -> list[Tuple[int, int, int]]:
71
+ """Return all semver git tags present in the repository."""
72
+ out = subprocess.check_output(["git", "tag", "-l"], text=True)
73
+ tags: list[Tuple[int, int, int]] = []
74
+ for line in out.splitlines():
75
+ parsed = parse_semver(line)
76
+ if parsed is not None:
77
+ tags.append(parsed)
78
+ return sorted(tags)
79
+
80
+
81
+ def head_exact_tag() -> Optional[Tuple[int, int, int]]:
82
+ """Return the semver tag pointing exactly at HEAD, if any."""
83
+ out = subprocess.check_output(["git", "tag", "--points-at", "HEAD"], text=True)
84
+ candidates = [parse_semver(line) for line in out.splitlines()]
85
+ valid = [c for c in candidates if c is not None]
86
+ return max(valid) if valid else None
87
+
88
+
89
+ def resolve_release(
90
+ *,
91
+ event_name: str,
92
+ ref_type: str,
93
+ ref_name: str,
94
+ commit_message: str = "",
95
+ bump_input: str = "patch",
96
+ explicit_version: str = "",
97
+ published_versions: Sequence[Tuple[int, int, int]],
98
+ repo_tags: Sequence[Tuple[int, int, int]],
99
+ head_tag: Optional[Tuple[int, int, int]],
100
+ ) -> dict[str, str]:
101
+ """
102
+ Determine version, tag, whether a new tag must be created, and whether to publish.
103
+ Branch pushes require '[publish]' (or '[publish:patch|minor|major]') in commit_message.
104
+ """
105
+ published_set = set(published_versions)
106
+
107
+ if event_name == "workflow_dispatch" and explicit_version.strip():
108
+ target = parse_semver(explicit_version)
109
+ if target is None:
110
+ raise ValueError(
111
+ f"Invalid explicit version {explicit_version!r}; expected X.Y.Z"
112
+ )
113
+ needs_tag = target not in set(repo_tags)
114
+ elif ref_type == "tag":
115
+ target = parse_semver(ref_name)
116
+ if target is None:
117
+ return {
118
+ "version": "",
119
+ "tag": "",
120
+ "needs_tag": "false",
121
+ "should_publish": "false",
122
+ "reason": f"Tag {ref_name!r} is not strict vX.Y.Z semver",
123
+ }
124
+ needs_tag = False
125
+ elif event_name == "push":
126
+ directive = parse_publish_directive(commit_message)
127
+ if directive is None:
128
+ return {
129
+ "version": "",
130
+ "tag": "",
131
+ "needs_tag": "false",
132
+ "should_publish": "false",
133
+ "reason": "Commit message does not contain [publish]; skipping release",
134
+ }
135
+ if head_tag is not None:
136
+ target = head_tag
137
+ needs_tag = False
138
+ else:
139
+ all_known = list(published_versions) + list(repo_tags)
140
+ target = INITIAL_VERSION if not all_known else bump_semver(max(all_known), directive)
141
+ needs_tag = target not in set(repo_tags)
142
+ else:
143
+ all_known = list(published_versions) + list(repo_tags)
144
+ if not all_known:
145
+ target = INITIAL_VERSION
146
+ else:
147
+ target = bump_semver(max(all_known), bump_input or "patch")
148
+ needs_tag = target not in set(repo_tags)
149
+
150
+ version_str = format_semver(target)
151
+ if target in published_set:
152
+ return {
153
+ "version": version_str,
154
+ "tag": f"v{version_str}",
155
+ "needs_tag": "false",
156
+ "should_publish": "false",
157
+ "reason": f"Version {version_str} is already published on PyPI",
158
+ }
159
+
160
+ return {
161
+ "version": version_str,
162
+ "tag": f"v{version_str}",
163
+ "needs_tag": "true" if needs_tag else "false",
164
+ "should_publish": "true",
165
+ "reason": f"Ready to publish {version_str}",
166
+ }
167
+
168
+
169
+ def main() -> int:
170
+ commit_msg = os.environ.get("COMMIT_MESSAGE", "")
171
+ if not commit_msg:
172
+ try:
173
+ commit_msg = subprocess.check_output(
174
+ ["git", "log", "-1", "--pretty=%B"], text=True
175
+ )
176
+ except Exception:
177
+ commit_msg = ""
178
+
179
+ result = resolve_release(
180
+ event_name=os.environ.get("GITHUB_EVENT_NAME", "push"),
181
+ ref_type=os.environ.get("GITHUB_REF_TYPE", "branch"),
182
+ ref_name=os.environ.get("GITHUB_REF_NAME", "main"),
183
+ commit_message=commit_msg,
184
+ bump_input=os.environ.get("INPUT_BUMP", "patch"),
185
+ explicit_version=os.environ.get("INPUT_VERSION", ""),
186
+ published_versions=fetch_pypi_versions("oilprops"),
187
+ repo_tags=git_tags(),
188
+ head_tag=head_exact_tag(),
189
+ )
190
+ print(json.dumps(result, indent=2))
191
+ output_path = os.environ.get("GITHUB_OUTPUT")
192
+ if output_path:
193
+ with open(output_path, "a", encoding="utf-8") as fh:
194
+ for k, v in result.items():
195
+ fh.write(f"{k}={v}\n")
196
+ return 0
197
+
198
+
199
+ if __name__ == "__main__":
200
+ sys.exit(main())
@@ -0,0 +1,63 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: ["main", "master"]
6
+ pull_request:
7
+ branches: ["main", "master"]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ${{ matrix.os }}
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ os: [ubuntu-latest, windows-latest]
16
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
17
+
18
+ steps:
19
+ - name: Checkout repository
20
+ uses: actions/checkout@v4
21
+ with:
22
+ fetch-depth: 0
23
+
24
+ - name: Set up Python ${{ matrix.python-version }}
25
+ uses: actions/setup-python@v5
26
+ with:
27
+ python-version: ${{ matrix.python-version }}
28
+
29
+ - name: Install package and test dependencies
30
+ run: |
31
+ python -m pip install --upgrade pip
32
+ python -m pip install -e ".[dev]"
33
+
34
+ - name: Run pytest
35
+ run: pytest -v
36
+
37
+ build:
38
+ runs-on: ubuntu-latest
39
+ needs: test
40
+ steps:
41
+ - name: Checkout repository
42
+ uses: actions/checkout@v4
43
+ with:
44
+ fetch-depth: 0
45
+
46
+ - name: Set up Python 3.10
47
+ uses: actions/setup-python@v5
48
+ with:
49
+ python-version: "3.10"
50
+
51
+ - name: Build universal wheel and sdist
52
+ run: |
53
+ python -m pip install --upgrade pip
54
+ python -m pip install build
55
+ python -m build
56
+
57
+ - name: Verify universal wheel filename and clean import
58
+ shell: bash
59
+ run: |
60
+ ls -la dist/
61
+ test -f dist/oilprops-*-py3-none-any.whl
62
+ python -m pip install --force-reinstall dist/oilprops-*-py3-none-any.whl
63
+ python -c "import oilprops; print(oilprops.__version__, oilprops.list_presets())"
@@ -0,0 +1,108 @@
1
+ name: Auto Version & Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ branches: ["main", "master"]
6
+ tags: ["v*"]
7
+ workflow_dispatch:
8
+ inputs:
9
+ bump:
10
+ description: "Version increment when publishing manually"
11
+ type: choice
12
+ default: "patch"
13
+ options: ["patch", "minor", "major"]
14
+ version:
15
+ description: "Optional explicit X.Y.Z version override (leaves empty for auto-bump)"
16
+ type: string
17
+ default: ""
18
+
19
+ concurrency:
20
+ group: pypi-publish
21
+ cancel-in-progress: false
22
+
23
+ jobs:
24
+ test:
25
+ if: >-
26
+ github.event_name == 'workflow_dispatch' ||
27
+ startsWith(github.ref, 'refs/tags/v') ||
28
+ contains(github.event.head_commit.message, '[publish]') ||
29
+ contains(github.event.head_commit.message, '[publish:')
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - name: Checkout repository
33
+ uses: actions/checkout@v4
34
+ with:
35
+ fetch-depth: 0
36
+
37
+ - name: Set up Python 3.10
38
+ uses: actions/setup-python@v5
39
+ with:
40
+ python-version: "3.10"
41
+
42
+ - name: Install and run pytest
43
+ run: |
44
+ python -m pip install --upgrade pip
45
+ python -m pip install -e ".[dev]"
46
+ pytest -v
47
+
48
+ publish:
49
+ needs: test
50
+ if: >-
51
+ github.event_name == 'workflow_dispatch' ||
52
+ startsWith(github.ref, 'refs/tags/v') ||
53
+ contains(github.event.head_commit.message, '[publish]') ||
54
+ contains(github.event.head_commit.message, '[publish:')
55
+ runs-on: ubuntu-latest
56
+ environment:
57
+ name: pypi
58
+ url: https://pypi.org/p/oilprops
59
+ permissions:
60
+ id-token: write
61
+ contents: write
62
+
63
+ steps:
64
+ - name: Checkout repository
65
+ uses: actions/checkout@v4
66
+ with:
67
+ fetch-depth: 0
68
+
69
+ - name: Set up Python 3.10
70
+ uses: actions/setup-python@v5
71
+ with:
72
+ python-version: "3.10"
73
+
74
+ - name: Resolve next release version
75
+ id: ver
76
+ env:
77
+ INPUT_BUMP: ${{ github.event.inputs.bump || 'patch' }}
78
+ INPUT_VERSION: ${{ github.event.inputs.version || '' }}
79
+ COMMIT_MESSAGE: ${{ github.event.head_commit.message || '' }}
80
+ run: python .github/scripts/resolve_version.py
81
+
82
+ - name: Tag release commit in GitHub
83
+ if: steps.ver.outputs.should_publish == 'true' && steps.ver.outputs.needs_tag == 'true'
84
+ run: |
85
+ git config user.name "github-actions[bot]"
86
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
87
+ git tag -a "${{ steps.ver.outputs.tag }}" -m "Release ${{ steps.ver.outputs.tag }}"
88
+ git push origin "${{ steps.ver.outputs.tag }}"
89
+
90
+ - name: Build universal wheel and sdist
91
+ if: steps.ver.outputs.should_publish == 'true'
92
+ env:
93
+ SETUPTOOLS_SCM_PRETEND_VERSION: ${{ steps.ver.outputs.version }}
94
+ run: |
95
+ python -m pip install --upgrade pip
96
+ python -m pip install build twine setuptools-scm
97
+ python -m build
98
+ twine check dist/*
99
+
100
+ - name: Verify built wheel version and import
101
+ if: steps.ver.outputs.should_publish == 'true'
102
+ run: |
103
+ python -m pip install --force-reinstall dist/oilprops-*-py3-none-any.whl
104
+ python -c "import oilprops; assert oilprops.__version__ == '${{ steps.ver.outputs.version }}', oilprops.__version__; print('Verified wheel version:', oilprops.__version__)"
105
+
106
+ - name: Publish to PyPI via Trusted Publishing
107
+ if: steps.ver.outputs.should_publish == 'true'
108
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,31 @@
1
+ # Virtual environments
2
+ venv/
3
+ .venv/
4
+ env/
5
+ temp/
6
+
7
+ # Generated dynamic version file
8
+ src/oilprops/_version.py
9
+
10
+ # Build & packaging
11
+ build/
12
+ dist/
13
+ *.egg-info/
14
+ src/*.egg-info/
15
+ .eggs/
16
+
17
+ # Python caches
18
+ __pycache__/
19
+ *.py[cod]
20
+ *$py.class
21
+
22
+ # Test & QA artifacts
23
+ .pytest_cache/
24
+ .coverage
25
+ htmlcov/
26
+ .mypy_cache/
27
+ .ruff_cache/
28
+
29
+ # IDE
30
+ .vscode/
31
+ .idea/
@@ -0,0 +1,68 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use OilProps in your work, please cite it using the metadata below."
3
+ title: "OilProps: Universal Petroleum Oil Thermophysical and PVT Property Library in Python"
4
+ type: software
5
+ version: "0.1.0"
6
+ date-released: "2026-11-26"
7
+ license: MIT
8
+ repository-code: "https://github.com/WarLord0401/oilprops"
9
+ url: "https://github.com/WarLord0401/oilprops"
10
+ authors:
11
+ - name: "Kanishk Teotia"
12
+ keywords:
13
+ - petroleum
14
+ - fuel-oil
15
+ - thermodynamics
16
+ - viscosity
17
+ - astm-d341
18
+ - iso-91-1
19
+ - compressibility
20
+ - hydrocarbons
21
+ references:
22
+ - type: software
23
+ title: "Thermo: Chemical properties component of Chemical Engineering Design Library (ChEDL)"
24
+ authors:
25
+ - family-names: Bell
26
+ given-names: Caleb
27
+ - name: "Contributors"
28
+ repository-code: "https://github.com/CalebBell/thermo"
29
+ license: MIT
30
+ - type: software
31
+ title: "Chemicals: Chemical properties component of Chemical Engineering Design Library (ChEDL)"
32
+ authors:
33
+ - family-names: Bell
34
+ given-names: Caleb
35
+ - family-names: Cortes-Pena
36
+ given-names: "Yoel Rene"
37
+ - name: "Contributors"
38
+ repository-code: "https://github.com/CalebBell/chemicals"
39
+ license: MIT
40
+ - type: article
41
+ title: "A modified corresponding states method for predicting hydrocarbon properties"
42
+ authors:
43
+ - family-names: Kesler
44
+ given-names: "M. G."
45
+ - family-names: Lee
46
+ given-names: "B. I."
47
+ journal: "Hydrocarbon Processing"
48
+ year: 1976
49
+ volume: 55
50
+ issue: 3
51
+ start: 153
52
+ end: 158
53
+ - type: article
54
+ title: "An improved correlation for densities of compressed liquids and liquid mixtures"
55
+ authors:
56
+ - family-names: Thomson
57
+ given-names: "G. H."
58
+ - family-names: Brobst
59
+ given-names: "K. R."
60
+ - family-names: Hankinson
61
+ given-names: "R. W."
62
+ journal: "AIChE Journal"
63
+ year: 1982
64
+ volume: 28
65
+ issue: 4
66
+ start: 671
67
+ end: 676
68
+ doi: "10.1002/aic.690280420"
oilprops-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kanishk Teotia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.