Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[py-tx] Migrate setup.py to pyproject.toml for modern packaging #1746

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/python-threatexchange-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python3 -m pip install -e .[all]
python3 -m pip install -e .[dev]
Dcallies marked this conversation as resolved.
Show resolved Hide resolved
- name: Check code format
run: |
black --check .
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[test]"
python3 -m pip install -e .[dev]
- name: Test with pytest
run: |
py.test
76 changes: 76 additions & 0 deletions python-threatexchange/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[build-system]
requires = ["hatchling", "hatch-fancy-pypi-readme"]
build-backend = "hatchling.build"

[project]
name = "threatexchange"
dynamic = ["version"]
description = "Python Library for Signal Exchange"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code currently loads a long description (shown on the pypi) from DESCRIPTION.rst and README.md, will we need that for this to retain behavior with pypi?

Copy link
Contributor Author

@b8zhong b8zhong Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 9; readme = "README.md" should work

in the original setup.py though, DESCRIPTION.rst wasn't used and was just the description that shows up rn... so I thought to keep the description that was there. I think it only shows up on pypi package index - so up to you which one to use.

Screenshot 2025-02-10 at 10 54 00 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up using the rst one... as that was probably the intention

readme = "README.md"
license = { text = "BSD" }
authors = [
{ name = "Facebook", email = "[email protected]" },
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3.8",
]
keywords = ["facebook", "threatexchange", "ncmec", "stopncii", "pdq"]
requires-python = ">=3.8"
dependencies = [
"python-Levenshtein",
"requests",
"urllib3", # For allow_methods
"python-dateutil",
"types-python-dateutil",
"dacite",
"Pillow", # pdq
"pdqhash", # pdq
"faiss-cpu", # faiss
"numpy", # faiss
"packaging", # fix ModuleNotFoundError in faiss/loader.py
"vpdq",
# Extension dependencies
"py-tlsh",
"pdfminer.six",
"pytesseract",
Dcallies marked this conversation as resolved.
Show resolved Hide resolved
]
urls = {Homepage = "https://www.github.com/facebook/ThreatExchange"}

[project.optional-dependencies]
dev = [
"pytest",
"black",
"mypy",
"types-python-dateutil",
"types-requests",
]
package = ["wheel"]

[project.scripts]
threatexchange = "threatexchange.cli.main:main"
tx = "threatexchange.cli.main:main"

[tool.hatch.version]
path = "version.txt"
pattern = "^(?P<version>[\\d.]+)$"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocking: I don't think this will correctly capture our version strings, which are in \d+.\d+.\d+ form.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, changed to "^(?P<version>\\d+\\.\\d+\\.\\d+)$"


[tool.hatch.build.targets.wheel]
packages = ["threatexchange"]
include = ["threatexchange/py.typed"]
exclude = ["tests*"]

[tool.hatch.build.targets.sdist]
exclude = [
"tests*",
]

[tool.hatch.metadata]
allow-direct-references = true

[tool.black]
line-length = 88
target-version = ["py38"]
include = '\.pyi?$'
79 changes: 0 additions & 79 deletions python-threatexchange/setup.py

This file was deleted.

Loading