Skip to content

Commit c7ad98a

Browse files
authored
Merge pull request #8 from jftuga/pypi-prep
prepare for PiPY deployment
2 parents 26c0fa7 + 3aa2e42 commit c7ad98a

File tree

9 files changed

+138
-21
lines changed

9 files changed

+138
-21
lines changed

Makefile

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Configuration:
2+
# Only set these if they have not been defined via command-line
3+
# such as: make VENV_NAME=my_custom_venv
4+
VENV_NAME ?= venv
5+
PYTHON ?= python3
6+
PYPIRC = $(HOME)/.pypirc
7+
8+
# Extract PROJECT_NAME from setup.py using helper script
9+
PROJECT_NAME := $(shell $(PYTHON) get_project_name.py)
10+
11+
# Default target
12+
.DEFAULT_GOAL := test-publish
13+
14+
# exclude special targets that start with a dot (like .PHONY)
15+
# exclude pattern rules that use % (like %.o: %.c)
16+
show-make-targets:
17+
@grep -E '^[^.%].*[^ ]:' Makefile | cut -d: -f1 | grep -i '^[a-z]'
18+
19+
# Show the project name found in setup.py
20+
show-project-name:
21+
@echo $(PROJECT_NAME)
22+
23+
# Check for ~/.pypirc
24+
check-pypirc:
25+
@if [ ! -f $(PYPIRC) ]; then \
26+
echo "Error: $(PYPIRC) not found. Please create it with your PyPI credentials."; \
27+
exit 1; \
28+
fi
29+
30+
# Create and configure virtual environment
31+
$(VENV_NAME):
32+
$(PYTHON) -m venv $(VENV_NAME)
33+
./$(VENV_NAME)/bin/pip install --upgrade pip
34+
./$(VENV_NAME)/bin/pip install setuptools wheel twine
35+
36+
# Build distribution
37+
build: $(VENV_NAME)
38+
./$(VENV_NAME)/bin/python setup.py sdist bdist_wheel
39+
40+
# Clean build artifacts and virtual environment
41+
clean:
42+
rm -rf build/
43+
rm -rf dist/
44+
rm -rf *.egg-info/
45+
rm -rf $(VENV_NAME)/
46+
rm -rf __pycache__/
47+
rm -rf test-install-venv/
48+
rm -f *.whl.metadata .??*~
49+
find . -type d -name "__pycache__" -exec rm -r "{}" +
50+
find . -type f -name "*.pyc" -delete
51+
command pip cache purge
52+
53+
# Test PyPI targets
54+
test-publish: clean check-pypirc $(VENV_NAME) build
55+
./$(VENV_NAME)/bin/twine upload --verbose --repository testpypi dist/*
56+
57+
test-install: clean
58+
$(PYTHON) -m venv test-install-venv
59+
./test-install-venv/bin/pip install --force-reinstall --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ $(PROJECT_NAME)
60+
61+
# Production PyPI targets
62+
prod-publish: clean check-pypirc $(VENV_NAME) build
63+
@echo "Are you sure you want to publish to production PyPI? [y/N] " && read ans && [ $${ans:-N} = y ]
64+
./$(VENV_NAME)/bin/twine --verbose upload dist/*
65+
66+
prod-install: clean
67+
$(PYTHON) -m venv prod-install-venv
68+
./prod-install-venv/bin/pip install --force-reinstall $(PROJECT_NAME)
69+
70+
# Declare targets that don't create a file of the same name
71+
.PHONY: show-make-targets show-project-name check-pypirc build clean test-publish test-install prod-publish prod-install

Pipfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ ruff = "*"
99

1010
[packages]
1111
chardet = ">=5.2.0"
12-
spacy = ">=3.8.3"
13-
torch = ">=2.5.1"
12+
spacy = ">=3.8.3,<4.0.0"
13+
torch = ">=2.5.1,<3.0.0"
1414
veryprettytable = {git = "https://github.com/andrewspiers/VeryPrettyTable.git"}
1515

1616
[requires]

Pipfile.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ A Python module that removes personally identifiable information (PII) from text
1515
## Installation
1616

1717
```bash
18+
pip install text-deidentification
19+
20+
# or...
21+
1822
pip install git+https://github.com/jftuga/deidentification.git
1923
```
2024

2125
### Requirements
2226

23-
- Python 3.7 or higher
24-
- spaCy
27+
- Python 3.10 or higher
2528
- spaCy's `en_core_web_trf` model (or another compatible model)
2629

2730
Download the required spaCy model:

deidentification/deidentification_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pgmName = "deidentification"
22
pgmUrl = "https://github.com/jftuga/deidentification"
3-
pgmVersion = "1.2.0"
3+
pgmVersion = "1.2.1"
44

55
GENDER_PRONOUNS = {
66
"he": "HE/SHE",

deidentification/deidentify.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,35 +85,35 @@ def main() -> int:
8585
parser = argparse.ArgumentParser(
8686
description="De-identify personally identifiable information in text files"
8787
)
88-
88+
8989
parser.add_argument(
9090
"input_file",
9191
help="text file to deidentify (use '-' for STDIN)",
9292
metavar="input_file"
9393
)
94-
94+
9595
parser.add_argument(
9696
"-r",
9797
"--replacement",
9898
default="PERSON",
9999
help="a word/phrase to replace identified names with (default: PERSON)",
100100
metavar="REPLACEMENT"
101101
)
102-
102+
103103
parser.add_argument(
104104
"-o",
105105
"--output",
106106
help="output file (if not specified, prints to STDOUT)",
107107
metavar="OUTPUT_FILE"
108108
)
109-
109+
110110
parser.add_argument(
111111
"-H",
112112
"--html",
113113
action="store_true",
114114
help="output in HTML format"
115115
)
116-
116+
117117
parser.add_argument(
118118
"-v",
119119
"--version",

get_project_name.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python3
2+
"""Extract project name from setup.py."""
3+
4+
import ast
5+
import sys
6+
from pathlib import Path
7+
8+
def get_project_name(setup_path='setup.py', default='myproject'):
9+
"""Extract the project name from setup.py using AST parsing."""
10+
try:
11+
setup_content = Path(setup_path).read_text()
12+
module = ast.parse(setup_content, mode='exec')
13+
14+
# Look for setup() call and find 'name' keyword argument
15+
for node in module.body:
16+
if (isinstance(node, ast.Expr) and
17+
isinstance(node.value, ast.Call) and
18+
isinstance(node.value.func, ast.Name) and
19+
node.value.func.id == 'setup'):
20+
21+
for keyword in node.value.keywords:
22+
if keyword.arg == 'name':
23+
if isinstance(keyword.value, ast.Constant):
24+
return keyword.value.value
25+
elif isinstance(keyword.value, ast.Name):
26+
# If name is a variable, try to find its definition
27+
name_id = keyword.value.id
28+
for prior_node in module.body:
29+
if (isinstance(prior_node, ast.Assign) and
30+
len(prior_node.targets) == 1 and
31+
isinstance(prior_node.targets[0], ast.Name) and
32+
prior_node.targets[0].id == name_id and
33+
isinstance(prior_node.value, ast.Constant)):
34+
return prior_node.value.value
35+
36+
return default
37+
38+
except (FileNotFoundError, SyntaxError, AttributeError):
39+
return default
40+
41+
if __name__ == '__main__':
42+
print(get_project_name())

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
chardet~=5.2.0
22
veryprettytable~=0.8.1
3-
spacy~=3.8.3
4-
torch~=2.5.1
3+
spacy~=3.8.3,<4.0.0
4+
torch~=2.5.1,<3.0.0
5+
en_core_web_trf @ https://github.com/explosion/spacy-models/releases/download/en_core_web_trf-3.8.0/en_core_web_trf-3.8.0-py3-none-any.whl

setup.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
long_description = fh.read()
1212

1313
setup(
14-
name="deidentification",
14+
name="text-deidentification",
1515
version=pgmVersion,
1616
author="John Taylor",
1717
author_email="",
@@ -21,24 +21,24 @@
2121
url="https://github.com/jftuga/deidentification",
2222
packages=find_packages(),
2323
classifiers=[
24-
"Development Status :: 4 - Beta",
24+
"Development Status :: 5 - Production/Stable",
2525
"Intended Audience :: Developers",
26+
"Intended Audience :: Healthcare Industry",
27+
"Intended Audience :: Legal Industry",
2628
"License :: OSI Approved :: MIT License",
29+
"Natural Language :: English",
2730
"Operating System :: OS Independent",
2831
"Programming Language :: Python :: 3",
29-
"Programming Language :: Python :: 3.7",
30-
"Programming Language :: Python :: 3.8",
31-
"Programming Language :: Python :: 3.9",
3232
"Programming Language :: Python :: 3.10",
3333
"Programming Language :: Python :: 3.11",
3434
"Programming Language :: Python :: 3.12",
3535
"Topic :: Text Processing",
3636
"Topic :: Security",
3737
],
38-
python_requires=">=3.7",
38+
python_requires=">=3.10",
3939
install_requires=[
40-
"spacy>=3.0.0",
41-
"torch>=2.5.1",
40+
"spacy>=3.8.3,<4.0.0",
41+
"torch>=2.5.1,<3.0.0",
4242
"chardet>=5.2.0",
4343
"veryprettytable>=0.8.1",
4444
],

0 commit comments

Comments
 (0)