Skip to content

Commit

Permalink
Convert setup.py to pyproject.toml using hatch build system (cond…
Browse files Browse the repository at this point in the history
…a#12509)

* Convert setup.py to pyproject.toml

* Switch from .version to __version__.py

* Mark conda.auxlib.packaging for deprecation

* Mark conda_check_versions_aligned for deprecation

* Include link to docs in deprecation message

* Create .git_archival

---------

Co-authored-by: Jannis Leidel <[email protected]>
Co-authored-by: Daniel Bast <[email protected]>
  • Loading branch information
3 people authored Apr 3, 2023
1 parent 435d7e4 commit 0a25579
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 112 deletions.
4 changes: 4 additions & 0 deletions .git_archival.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
ref-names: $Format:%D$
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.psm1 text eol=lf
dev/start text eol=lf
*.bat text eol=crlf
.git_archival.txt export-subst
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ MANIFEST
coverage.xml
.tox/
junit.xml
.version
tmpfile.rc
.DS_Store
.coverage*
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ clean:
find . -name \*.py[cod] -delete
find . -name __pycache__ -delete
rm -rf .cache build
rm -f .coverage .coverage.* junit.xml tmpfile.rc conda/.version tempfile.rc coverage.xml
rm -f .coverage .coverage.* junit.xml tmpfile.rc tempfile.rc coverage.xml
rm -rf auxlib bin conda/progressbar
rm -rf conda-build conda_build_test_recipe record.txt
rm -rf .pytest_cache
Expand Down
15 changes: 13 additions & 2 deletions conda/__version__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
from .auxlib.packaging import get_version
"""Placeholder for the actual version code injected by hatch-vcs.
__version__ = get_version(__file__)
The logic here is used during development installs only so keep it simple. Since conda
abides by CEP-8, which outlines using CalVer, our development version is simply:
YY.MM.MICRO.devN+gHASH[.dirty]
"""
try:
from setuptools_scm import get_version

__version__ = get_version(root="..", relative_to=__file__)
except (ImportError, OSError):
# ImportError: setuptools_scm isn't installed
# OSError: git isn't installed
__version__ = "0.0.0.dev0+placeholder"
16 changes: 12 additions & 4 deletions conda/auxlib/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@
'test': auxlib.Tox,
},
)
"""

from collections import namedtuple
from distutils.command.build_py import build_py
from distutils.command.sdist import sdist
Expand All @@ -73,10 +70,21 @@
from os import getenv, listdir, remove
from os.path import abspath, dirname, expanduser, isdir, isfile, join
from re import compile
from conda.auxlib.compat import shlex_split_unicode
from subprocess import CalledProcessError, PIPE, Popen
import sys

from .compat import shlex_split_unicode
from ..deprecations import deprecated

deprecated.module(
"23.9",
"24.3",
addendum=(
"Use a modern build systems instead, see https://packaging.python.org/en/latest/tutorials/"
"packaging-projects#creating-pyproject-toml for more details."
),
)

log = getLogger(__name__)

Response = namedtuple('Response', ['stdout', 'stderr', 'rc'])
Expand Down
7 changes: 7 additions & 0 deletions conda/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

from conda.common.compat import on_win

from ..deprecations import deprecated


def encode_for_env_var(value) -> str:
"""Environment names and values need to be string."""
Expand Down Expand Up @@ -109,6 +111,11 @@ def conda_move_to_front_of_PATH():
os.environ["PATH"] = new_path


@deprecated(
"23.9",
"24.3",
addendum="Unnecessary with transition to hatchling for build system.",
)
def conda_check_versions_aligned():
# Next problem. If we use conda to provide our git or otherwise do not
# have it on PATH and if we also have no .version file then conda is
Expand Down
19 changes: 19 additions & 0 deletions news/12509-hatchling-build-system
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* Switch from `setup.py` to `pyproject.toml` and use [Hatchling](https://pypi.org/project/hatchling/) for our build system. (#12509)

### Bug fixes

* <news item>

### Deprecations

* Mark `conda.auxlib.packaging` for deprecation in 24.3.0. (#12509)

### Docs

* <news item>

### Other

* <news item>
65 changes: 65 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,68 @@
[build-system]
requires = [
"hatchling >=1.12.2",
"hatch-vcs >=0.2.0",
]
build-backend = "hatchling.build"

[project]
name = "conda"
description = "OS-agnostic, system-level binary package manager."
readme = "README.md"
authors = [{name = "Anaconda, Inc.", email = "[email protected]"}]
license = {file = "LICENSE"}
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy"
]
requires-python = ">=3.8"
dependencies = [
"conda-package-handling >=1.3.0",
"menuinst >=1.4.11,<2 ; platform_system=='Windows'",
"packaging",
"pycosat >=0.6.3",
"pyopenssl >=16.2.0",
"requests >=2.18.4,<3",
"ruamel.yaml >=0.11.14,<0.18",
"setuptools >=31.0.1",
"toolz >=0.8.1",
"pluggy >=1.0.0",
"tqdm >=4",
"boltons >=23.0.0",
"jsonpatch >=1.32",
]
dynamic = ["version"]

[project.urls]
documentation = "https://docs.conda.io/projects/conda/en/stable/"
repository = "https://github.com/conda/conda"
changelog = "https://github.com/conda/conda/blob/main/CHANGELOG.md"

[project.scripts]
conda = "conda.cli.main_pip:main"

[tool.hatch.version]
source = "vcs"

[tool.hatch.version.raw-options]
version_scheme = "calver-by-date"
local_scheme = "dirty-tag"

[tool.hatch.build]
include = ["conda", "conda_env"]

[tool.hatch.build.hooks.vcs]
version-file = "conda/__version__.py"

[tool.black]
target-version = ['py38', 'py39', 'py310']

Expand Down
3 changes: 1 addition & 2 deletions recipe/build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash

echo "$PKG_VERSION" > conda/.version
"$PYTHON" setup.py install --single-version-externally-managed --record record.txt
"$PYTHON" -m pip install . -vv
if [[ ! $(uname) =~ MINGW* ]]; then
rm -rf "$SP_DIR/conda/shell/*.exe"
fi
Expand Down
6 changes: 4 additions & 2 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ requirements:
- pluggy >=1.0.0
- tqdm >=4
- boltons >=23.0.0
- hatchling >=1.12.2
- hatch-vcs >=0.2.0
run:
- python
- conda-package-handling >=1.3.0
Expand All @@ -51,7 +53,7 @@ requirements:
- pluggy >=1.0.0
- tqdm >=4
- boltons >=23.0.0
- jsonpatch
- jsonpatch >=1.32
run_constrained:
- conda-build >=3.18.3
- conda-env >=2.6
Expand All @@ -78,7 +80,7 @@ test:
about:
home: https://conda.io
license: BSD-3-Clause
license_file: LICENSE.txt
license_file: LICENSE
summary: OS-agnostic, system-level binary package and environment manager.
description: >
Conda is an open source package management system and environment
Expand Down
89 changes: 0 additions & 89 deletions setup.py

This file was deleted.

2 changes: 0 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
initialize_logging()

from conda.testing import (
conda_check_versions_aligned,
conda_ensure_sys_python_is_base_env_python,
conda_move_to_front_of_PATH,
)

conda_ensure_sys_python_is_base_env_python()
conda_move_to_front_of_PATH()
conda_check_versions_aligned()
19 changes: 10 additions & 9 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# run as 'conda install --file tests/requirements.txt -c conda-forge'
anaconda-client
beautifulsoup4
boto3 # NOTE: we also need the `minio` server, installed manually in CI
boltons >= 23.0.0
boto3 # also need the `minio` server, installed manually in CI
boltons >=23.0.0
chardet
conda
conda-build >=3.23.3
Expand All @@ -20,15 +20,15 @@ filelock
flake8
flask >=2.2
git
jsonpatch
jsonpatch >=1.32
nbformat
packaging
perl
pexpect
pip
pluggy
pluggy >=1.0.0
pkginfo
pycosat
pycosat >=0.6.3
pycrypto
pyflakes
pytest
Expand All @@ -37,8 +37,9 @@ pytest-mock
pytest-rerunfailures
pytest-timeout
pytest-xdist
requests
requests >=2.18.4,<3
responses
ruamel.yaml
toolz
tqdm
ruamel.yaml >=0.11.14,<0.18
setuptools_scm # needed for devenv version detection
toolz >=0.8.1
tqdm >=4

0 comments on commit 0a25579

Please sign in to comment.