Skip to content

Commit 1bc8562

Browse files
authored
Merge pull request #93 from trailofbits/modernize-pyproject-toml
Modernize project packaging: migrate to pyproject.toml
2 parents 8ead08e + 858fcf6 commit 1bc8562

File tree

9 files changed

+142
-183
lines changed

9 files changed

+142
-183
lines changed

.github/workflows/check_version.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/publish_docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ jobs:
2323
env:
2424
# The use of ::set-env here is safe!
2525
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
26-
- name: Set up Python 3.8
26+
- name: Set up Python 3.12
2727
uses: actions/setup-python@v5
2828
with:
29-
python-version: 3.8
29+
python-version: 3.12
3030
- name: Install dependencies
3131
run: |
3232
cd graphtage

.github/workflows/pythonpackage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
strategy:
1818
matrix:
19-
python-version: [3.8, 3.9, "3.10", "3.11"]
19+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
2020

2121
steps:
2222
- uses: actions/checkout@v4

.gitignore

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
__pycache__
2-
.cache
1+
__pycache__/
2+
.cache/
33
.python_history
44
*.pyc
5+
*.pyo
6+
*.pyd
7+
.Python
58
build/
69
dist/
7-
graphtage.egg-info
10+
*.egg-info/
11+
.eggs/
12+
.ruff_cache/
13+
.pytest_cache/
14+
.mypy_cache/
15+
.coverage
16+
htmlcov/
17+
.tox/
18+
.venv/
19+
venv/
20+
ENV/
21+
env/

MANIFEST.in

Lines changed: 0 additions & 2 deletions
This file was deleted.

graphtage/expressions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
obj.__name__: obj for obj in (
4949
str, bool, int, bytes, float, bytearray, dict, set, frozenset,
5050
enumerate, zip, map, filter, any, all, chr, ord, abs, ascii, bin, bool, complex, hash, hex, oct, min, max, id,
51-
iter, len, list, slice, sorted, sum, tuple, round
51+
iter, len, list, slice, sorted, sum, tuple, round, pow, divmod, repr, isinstance, issubclass, range, reversed
5252
)
5353
}
5454

graphtage/version.py

Lines changed: 5 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,14 @@
11
"""A module that centralizes the version information for Graphtage.
22
33
Changing the version here not only affects the version printed with the ``--version`` command line option, but it also
4-
automatically updates the version used in ``setup.py`` and rendered in the documentation.
5-
6-
Attributes:
7-
DEV_BUILD (bool): Sets whether this build is a development build.
8-
This should only be set to :const:`True` to coincide with a release. It should *always* be :const:`True` before
9-
deploying to PyPI.
10-
11-
If :const:`False`, the git branch will be included in :attr:`graphtage.version.__version__`.
12-
13-
__version__ (Tuple[Union[int, str], ...]): The version of Graphtage. This tuple can contain any sequence of ints and
14-
strings. Typically this will be three ints: major/minor/revision number. However, it can contain additional
15-
ints and strings. If :attr:`graphtage.version.DEV_BUILD`, then `("git", git_branch())` will be appended to the
16-
version.
17-
18-
VERSION_STRING (str): A rendered string containing the version of Graphtage. Each element of
19-
:attr:`graphtage.version.__version__` is appended to the string, delimited by a "." if the element is an ``int``
20-
or a "-" if the element is a string.
21-
4+
automatically updates the version used in the build system and rendered in the documentation.
225
"""
236

24-
import os
25-
import subprocess
26-
from typing import Optional, Tuple, Union
27-
28-
29-
def git_branch() -> Optional[str]:
30-
"""Returns the git branch for the codebase, or :const:`None` if it could not be determined.
31-
32-
The git branch is determined by running
33-
34-
.. code-block:: console
35-
36-
$ git symbolic-ref -q HEAD
37-
38-
"""
39-
try:
40-
branch = subprocess.check_output(
41-
['git', 'symbolic-ref', '-q', 'HEAD'],
42-
cwd=os.path.dirname(os.path.realpath(__file__)),
43-
stderr=subprocess.DEVNULL
44-
)
45-
branch = branch.decode('utf-8').strip().split('/')[-1]
46-
return branch
47-
except Exception:
48-
return None
49-
50-
51-
DEV_BUILD = False
52-
"""Sets whether this build is a development build.
53-
54-
This should only be set to :const:`False` to coincide with a release. It should *always* be :const:`False` before
55-
deploying to PyPI.
56-
57-
If :const:`True`, the git branch will be included in the version string.
58-
59-
"""
60-
61-
62-
__version__: Tuple[Union[int, str], ...] = (0, 3, 1)
63-
64-
if DEV_BUILD:
65-
branch_name = git_branch()
66-
if branch_name is None:
67-
__version__ = __version__ + ('git',)
68-
else:
69-
__version__ = __version__ + ('git', branch_name)
70-
71-
VERSION_STRING = ''
7+
__version__ = "0.3.1"
8+
VERSION_STRING = __version__
729

73-
for element in __version__:
74-
if isinstance(element, int):
75-
if VERSION_STRING:
76-
VERSION_STRING += f'.{element}'
77-
else:
78-
VERSION_STRING = str(element)
79-
else:
80-
if VERSION_STRING:
81-
VERSION_STRING += f'-{element!s}'
82-
else:
83-
VERSION_STRING += str(element)
10+
# For backwards compatibility with code that expects the tuple format
11+
__version_tuple__ = tuple(int(x) if x.isdigit() else x for x in __version__.split('.'))
8412

8513

8614
if __name__ == '__main__':

pyproject.toml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
[build-system]
2+
requires = ["hatchling>=1.21.0", "hatch-vcs>=0.4.0"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "graphtage"
7+
description = "A utility to diff tree-like files such as JSON and XML."
8+
readme = "README.md"
9+
requires-python = ">=3.8"
10+
license = {text = "LGPL-3.0-or-later"}
11+
authors = [
12+
{name = "Trail of Bits"},
13+
]
14+
classifiers = [
15+
"Development Status :: 4 - Beta",
16+
"Environment :: Console",
17+
"Intended Audience :: Science/Research",
18+
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)",
19+
"Programming Language :: Python :: 3 :: Only",
20+
"Programming Language :: Python :: 3.8",
21+
"Programming Language :: Python :: 3.9",
22+
"Programming Language :: Python :: 3.10",
23+
"Programming Language :: Python :: 3.11",
24+
"Programming Language :: Python :: 3.12",
25+
"Programming Language :: Python :: 3.13",
26+
"Topic :: Utilities",
27+
]
28+
dependencies = [
29+
"colorama",
30+
"fickling>=0.1.3",
31+
"intervaltree",
32+
"json5==0.9.5",
33+
"numpy>=1.19.4",
34+
"PyYAML",
35+
"scipy>=1.4.0",
36+
"tqdm",
37+
"typing_extensions>=3.7.4.3",
38+
]
39+
dynamic = ["version"]
40+
41+
[project.optional-dependencies]
42+
dev = [
43+
"pytest>=7.0.0",
44+
"ruff>=0.1.0",
45+
"sphinx>=5.0.0",
46+
"sphinx_rtd_theme==3.0.2",
47+
"twine>=4.0.0",
48+
]
49+
50+
[project.scripts]
51+
graphtage = "graphtage.__main__:main"
52+
53+
[project.urls]
54+
Homepage = "https://github.com/trailofbits/graphtage"
55+
Documentation = "https://trailofbits.github.io/graphtage"
56+
Issues = "https://github.com/trailofbits/graphtage/issues"
57+
Source = "https://github.com/trailofbits/graphtage"
58+
59+
[tool.hatch.version]
60+
path = "graphtage/version.py"
61+
62+
[tool.hatch.build]
63+
include = [
64+
"graphtage/**/*.py",
65+
"LICENSE",
66+
"README.md",
67+
]
68+
69+
[tool.hatch.build.targets.sdist]
70+
include = [
71+
"graphtage/**/*.py",
72+
"test/**/*.py",
73+
"LICENSE",
74+
"README.md",
75+
"pyproject.toml",
76+
]
77+
78+
[tool.hatch.build.targets.wheel]
79+
packages = ["graphtage"]
80+
81+
[tool.ruff]
82+
target-version = "py38"
83+
line-length = 120
84+
select = [
85+
"E", # pycodestyle errors
86+
"W", # pycodestyle warnings
87+
"F", # pyflakes
88+
"I", # isort
89+
"UP", # pyupgrade
90+
"B", # flake8-bugbear
91+
"C4", # flake8-comprehensions
92+
"SIM", # flake8-simplify
93+
"TID", # flake8-tidy-imports
94+
"RUF", # Ruff-specific rules
95+
]
96+
ignore = [
97+
"E501", # line too long (handled by formatter)
98+
"B008", # do not perform function calls in argument defaults
99+
"B904", # raise without from inside except
100+
"SIM108", # use ternary operator instead of if-else block
101+
]
102+
103+
[tool.ruff.per-file-ignores]
104+
"test/**/*.py" = [
105+
"F401", # unused imports in tests
106+
"F841", # unused variables in tests
107+
]
108+
109+
[tool.ruff.isort]
110+
known-first-party = ["graphtage"]
111+
112+
[tool.pytest.ini_options]
113+
testpaths = ["test"]
114+
python_files = "test_*.py"
115+
python_classes = "Test*"
116+
python_functions = "test_*"

setup.py

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)