Skip to content

Commit db5813e

Browse files
committed
Remove references to setup.py
1 parent 00d55ce commit db5813e

File tree

6 files changed

+46
-99
lines changed

6 files changed

+46
-99
lines changed

CONTRIBUTING.rst

+1-10
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,7 @@ This will perform the following actions:
218218

219219
2. Bump the current version to the next release candidate, ``X.Y.Z.dev(N+1)``
220220

221-
After this is done, the new pre-release can be installed by including the ``dev`` section in the
222-
dependency specification, either in ``setup.py``::
223-
224-
install_requires = [
225-
...
226-
'sdmetrics>=X.Y.Z.dev',
227-
...
228-
]
229-
230-
or in command line::
221+
After this is done, the new pre-release can be installed in command line::
231222

232223
pip install 'sdmetrics>=X.Y.Z.dev'
233224

Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ coverage: ## check code coverage quickly with the default Python
126126

127127
.PHONY: dist
128128
dist: clean ## builds source and wheel package
129-
python setup.py sdist
130-
python setup.py bdist_wheel
129+
python -m build --wheel --sdist
131130
ls -l dist
132131

133132
.PHONY: publish-confirm

pyproject.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ classifiers = [
1515
'Programming Language :: Python :: 3.10',
1616
'Programming Language :: Python :: 3.11',
1717
]
18-
requires-python = "'>=3.8,<3.12"
18+
requires-python = ">=3.8,<3.12"
1919
keywords = ['sdmetrics', 'sdmetrics', 'SDMetrics']
2020
dependencies = [
2121
"numpy>=1.20.0,<2;python_version<'3.10'",
@@ -107,3 +107,6 @@ dev = [
107107
'coverage>=4.5.1,<6',
108108
'tox>=2.9.1,<4',
109109
]
110+
111+
[tool.setuptools]
112+
packages.find.include = ['sdmetrics*']

setup.cfg

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ current_version = 0.13.1.dev0
33
commit = True
44
tag = True
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>[a-z]+)(?P<candidate>\d+))?
6-
serialize =
6+
serialize =
77
{major}.{minor}.{patch}.{release}{candidate}
88
{major}.{minor}.{patch}
99

1010
[bumpversion:part:release]
1111
optional_value = release
1212
first_value = dev
13-
values =
13+
values =
1414
dev
1515
release
1616

1717
[bumpversion:part:candidate]
1818

19-
[bumpversion:file:setup.py]
19+
[bumpversion:file:pyproject.toml]
2020
search = version='{current_version}'
2121
replace = version='{new_version}'
2222

@@ -57,6 +57,3 @@ use_parentheses = True
5757
[aliases]
5858
test = pytest
5959

60-
[tool:pytest]
61-
collect_ignore = ['setup.py']
62-

setup.py

-37
This file was deleted.

tasks.py

+37-43
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import inspect
33
import operator
44
import os
5-
import re
6-
import pkg_resources
7-
import platform
5+
import toml
6+
from packaging.requirements import Requirement
7+
from packaging.version import Version
88
import shutil
99
import stat
1010
from pathlib import Path
@@ -38,51 +38,45 @@ def integration(c):
3838
c.run('python -m pytest ./tests/integration --reruns 5 --disable-warnings')
3939

4040

41-
def _validate_python_version(line):
42-
is_valid = True
43-
for python_version_match in re.finditer(r"python_version(<=?|>=?|==)\'(\d\.?)+\'", line):
44-
python_version = python_version_match.group(0)
45-
comparison = re.search(r'(>=?|<=?|==)', python_version).group(0)
46-
version_number = python_version.split(comparison)[-1].replace("'", "")
47-
comparison_function = COMPARISONS[comparison]
48-
is_valid = is_valid and comparison_function(
49-
pkg_resources.parse_version(platform.python_version()),
50-
pkg_resources.parse_version(version_number),
51-
)
41+
def _get_minimum_versions(dependencies, python_version):
42+
min_versions = {}
43+
for dependency in dependencies:
44+
if '@' in dependency:
45+
name, url = dependency.split(' @ ')
46+
min_versions[name] = f'{name} @ {url}'
47+
continue
5248

53-
return is_valid
49+
req = Requirement(dependency)
50+
if ';' in dependency:
51+
marker = req.marker
52+
if marker and not marker.evaluate({'python_version': python_version}):
53+
continue # Skip this dependency if the marker does not apply to the current Python version
54+
55+
if req.name not in min_versions:
56+
min_version = next((spec.version for spec in req.specifier if spec.operator in ('>=', '==')), None)
57+
if min_version:
58+
min_versions[req.name] = f'{req.name}=={min_version}'
59+
60+
elif '@' not in min_versions[req.name]:
61+
existing_version = Version(min_versions[req.name].split('==')[1])
62+
new_version = next((spec.version for spec in req.specifier if spec.operator in ('>=', '==')), existing_version)
63+
if new_version > existing_version:
64+
min_versions[req.name] = f'{req.name}=={new_version}' # Change when a valid newer version is found
65+
66+
return list(min_versions.values())
5467

5568

5669
@task
5770
def install_minimum(c):
58-
with open('setup.py', 'r') as setup_py:
59-
lines = setup_py.read().splitlines()
60-
61-
versions = []
62-
started = False
63-
for line in lines:
64-
if started:
65-
if line == ']':
66-
break
67-
68-
line = line.strip()
69-
if _validate_python_version(line):
70-
requirement = re.match(r'[^>]*', line).group(0)
71-
requirement = re.sub(r"""['",]""", '', requirement)
72-
version = re.search(r'>=?(\d\.?)+', line).group(0)
73-
if version:
74-
version = re.sub(r'>=?', '==', version)
75-
version = re.sub(r"""['",]""", '', version)
76-
requirement += version
77-
78-
versions.append(requirement)
79-
80-
elif (line.startswith('install_requires = [') or
81-
line.startswith('pomegranate_requires = [') or
82-
line.startswith('torch_requires = [')):
83-
started = True
84-
85-
c.run(f'python -m pip install {" ".join(versions)}')
71+
with open('pyproject.toml', 'r', encoding='utf-8') as pyproject_file:
72+
pyproject_data = toml.load(pyproject_file)
73+
74+
dependencies = pyproject_data.get('project', {}).get('dependencies', [])
75+
python_version = '.'.join(map(str, sys.version_info[:2]))
76+
minimum_versions = _get_minimum_versions(dependencies, python_version)
77+
78+
if minimum_versions:
79+
c.run(f'python -m pip install {" ".join(minimum_versions)}')
8680

8781

8882
@task

0 commit comments

Comments
 (0)