Skip to content

Commit e70647c

Browse files
committed
Fix setup.py references
1 parent cc6ba84 commit e70647c

File tree

4 files changed

+46
-61
lines changed

4 files changed

+46
-61
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

setup.cfg

+3-5
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,4 @@ use_parentheses = True
5757
[aliases]
5858
test = pytest
5959

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

tasks.py

+41-44
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
@@ -20,7 +20,7 @@
2020

2121

2222
if not hasattr(inspect, 'getargspec'):
23-
inspect.getargspec = inspect.getfullargspec
23+
inspect.getargspec = inspect.getfullargspec
2424

2525

2626
@task
@@ -38,51 +38,48 @@ 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(
57+
(spec.version for spec in req.specifier if spec.operator in ('>=', '==')), None)
58+
if min_version:
59+
min_versions[req.name] = f'{req.name}=={min_version}'
60+
61+
elif '@' not in min_versions[req.name]:
62+
existing_version = Version(min_versions[req.name].split('==')[1])
63+
new_version = next(
64+
(spec.version for spec in req.specifier if spec.operator in ('>=', '==')), existing_version)
65+
if new_version > existing_version:
66+
# Change when a valid newer version is found
67+
min_versions[req.name] = f'{req.name}=={new_version}'
68+
69+
return list(min_versions.values())
5470

5571

5672
@task
5773
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)}')
74+
with open('pyproject.toml', 'r', encoding='utf-8') as pyproject_file:
75+
pyproject_data = toml.load(pyproject_file)
76+
77+
dependencies = pyproject_data.get('project', {}).get('dependencies', [])
78+
python_version = '.'.join(map(str, sys.version_info[:2]))
79+
minimum_versions = _get_minimum_versions(dependencies, python_version)
80+
81+
if minimum_versions:
82+
c.run(f'python -m pip install {" ".join(minimum_versions)}')
8683

8784

8885
@task

0 commit comments

Comments
 (0)