Skip to content
This repository was archived by the owner on Jan 4, 2025. It is now read-only.

Commit c20c008

Browse files
authored
internal: support PyPI release (#4)
1 parent 8667c6b commit c20c008

File tree

8 files changed

+172
-6
lines changed

8 files changed

+172
-6
lines changed

.github/workflows/release.yaml

+114-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
name: Release
22

33
on:
4-
workflow_dispatch: {}
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
required: true
8+
description: Version to release
9+
test-repository:
10+
required: true
11+
type: boolean
12+
default: true
13+
description: Upload to Test PyPI repository?
14+
test-package:
15+
required: true
16+
type: boolean
17+
default: true
18+
description: Try installing from Test PyPI repository?
519

620
jobs:
721
Release:
@@ -11,3 +25,102 @@ jobs:
1125
steps:
1226
- name: Checkout
1327
uses: actions/checkout@v3
28+
- name: Install Python
29+
uses: actions/setup-python@v4
30+
with:
31+
python-version: "3.9"
32+
33+
- name: Set version
34+
run: echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
35+
- name: Validate version
36+
run: test "${{ env.VERSION }}"
37+
38+
- name: Override version in setup.py
39+
shell: python
40+
run: |-
41+
FILE = "setup.py"
42+
with open(FILE, "r") as f:
43+
data = f.read()
44+
45+
data = data.replace("$VERSION$", "${{ github.event.inputs.version }}")
46+
with open(FILE, "w") as f:
47+
f.write(data)
48+
49+
- name: Override requirements in setup.py
50+
shell: python
51+
run: |-
52+
requirements = list()
53+
with open("requirements.txt", "r") as f:
54+
for line in f.readlines():
55+
line = line.split("#")[0].strip()
56+
if line:
57+
requirements.append(line)
58+
59+
FILE = "setup.py"
60+
with open(FILE, "r") as f:
61+
data = f.read()
62+
63+
import json
64+
data = data.replace("$REQUIREMENTS$", json.dumps(requirements))
65+
with open(FILE, "w") as f:
66+
f.write(data)
67+
68+
- name: Set PyPI repository/token (production)
69+
if: ${{ github.event.inputs.test-repository == 'false' }}
70+
run: |-
71+
echo "PYPI_REPOSITORY=https://pypi.python.org/simple/" >> $GITHUB_ENV
72+
echo "PYPI_TOKEN=${{ secrets.PYPI_TOKEN }}" >> $GITHUB_ENV
73+
74+
- name: Set PyPI repository/token (test)
75+
if: ${{ github.event.inputs.test-repository == 'true' }}
76+
run: |-
77+
echo "PYPI_REPOSITORY=https://test.pypi.org/legacy/" >> $GITHUB_ENV
78+
echo "PYPI_TOKEN=${{ secrets.PYPI_TEST_TOKEN }}" >> $GITHUB_ENV
79+
80+
- name: Build package
81+
run: python setup.py sdist
82+
83+
- name: Publish package to PyPI
84+
uses: pypa/gh-action-pypi-publish@5fb2f047e26679d7846a8370de1642ff160b9025
85+
with:
86+
repository_url: ${{ env.PYPI_REPOSITORY }}
87+
password: ${{ env.PYPI_TOKEN }}
88+
89+
TestRelease:
90+
name: Test Release
91+
if: ${{ github.event.inputs.test-repository == 'true' && github.event.inputs.test-package == 'true' }}
92+
runs-on: ubuntu-latest
93+
needs:
94+
- Release
95+
96+
steps:
97+
- name: Checkout
98+
uses: actions/checkout@v3
99+
- name: Install Python
100+
uses: actions/setup-python@v4
101+
with:
102+
python-version: "3.9"
103+
104+
- name: Install pnytter requirements from main PyPI repository
105+
run: pip install -r requirements.txt
106+
107+
# TODO allow testing from production index
108+
- name: Install pnytter package
109+
uses: nick-fields/retry@v2
110+
with:
111+
timeout_seconds: 30
112+
max_attempts: 12
113+
retry_wait_seconds: 5
114+
retry_on: error
115+
command: pip install --index-url="https://test.pypi.org/simple/" "pnytter==${{ github.event.inputs.version }}"
116+
- name: Install test requirements
117+
run: pip install -r requirements-test.txt
118+
119+
- name: Move tests directory
120+
run: mv tests /tmp/pnytter-tests
121+
- name: Run tests
122+
working-directory: /tmp/pnytter-tests
123+
run: pytest -sv .
124+
env:
125+
TEST_NITTER_INSTANCES: |-
126+
["https://nitter.pussthecat.org"]

.github/workflows/test.yaml

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@ on:
77
- pnytter/**
88
- tests/**
99
- .github/workflows/test.yaml
10+
- requirements*.txt
1011

1112
jobs:
1213
Test:
13-
name: Test
14+
name: "[Python ${{ matrix.python-version }}] Test"
1415
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
# TODO Try running test for each version on same job without matrix, using virtualenvs
19+
python-version:
20+
- "3.7"
21+
- "3.8"
22+
- "3.9"
23+
- "3.10"
1524

1625
env:
1726
GithubRunnerIP: "172.17.0.1"
@@ -59,7 +68,7 @@ jobs:
5968
- name: Install Python
6069
uses: actions/setup-python@v4
6170
with:
62-
python-version: "3.9"
71+
python-version: ${{ matrix.python-version }}
6372
- name: Install Python requirements
6473
run: pip install -r requirements.txt -r requirements-test.txt
6574

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
.idea/
22
.vscode/
3+
dist/
4+
build/
5+
*.egg-info/
36
*.env
47
*pycache*
58
.pytest_cache

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The features are bound to the development of my [twitterscraper](https://github.
2424

2525
## Requirements
2626

27-
- Python >= 3.6
27+
- Python >= 3.7
2828
- Requirements listed on [requirements.txt](requirements.txt)
2929
- A hosted Nitter instance is recommeded for intensive use, to avoid overloading the public instances
3030

requirements-test.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pytest==7.1.2
2+
pydantic==1.9.1
23
python-dotenv==0.20.0
34
lxml==4.9.1

setup.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import json
2+
from setuptools import setup, find_packages
3+
4+
5+
VERSION = "$VERSION$"
6+
REQUIREMENTS_JSON = """$REQUIREMENTS$"""
7+
8+
9+
with open("README.md", "r") as f:
10+
readme_content = f.read()
11+
12+
13+
setup(
14+
name="pnytter",
15+
license="ISC",
16+
author="David Lorenzo",
17+
author_email="[email protected]",
18+
url="https://github.com/David-Lor/pnytter",
19+
download_url="https://github.com/David-Lor/pnytter/archive/main.zip",
20+
keywords=["twitter", "nitter", "scraper", "scraping"],
21+
install_requires=json.loads(REQUIREMENTS_JSON),
22+
classifiers=[
23+
"Development Status :: 4 - Beta",
24+
"Intended Audience :: Developers",
25+
"Topic :: Software Development :: Libraries",
26+
"License :: OSI Approved :: ISC License (ISCL)",
27+
"Programming Language :: Python :: 3.7",
28+
"Programming Language :: Python :: 3.8",
29+
"Programming Language :: Python :: 3.9",
30+
"Programming Language :: Python :: 3.10"
31+
],
32+
description_file="README.md",
33+
license_files=["LICENSE.md"],
34+
long_description_content_type="text/markdown",
35+
36+
version=VERSION,
37+
long_description=readme_content,
38+
packages=find_packages(),
39+
)

tests/conftest.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
class PnytterTestsSettings(pydantic.BaseSettings):
1010
nitter_instances: Union[List[pydantic.AnyHttpUrl], pydantic.AnyHttpUrl]
11+
beautifulsoup_parser: str = "lxml"
1112

1213
class Config:
1314
env_prefix = "TEST_"
@@ -19,5 +20,5 @@ def pnytter():
1920
settings = PnytterTestsSettings()
2021
return Pnytter(
2122
nitter_instances=settings.nitter_instances,
22-
beautifulsoup_parser="lxml",
23+
beautifulsoup_parser=settings.beautifulsoup_parser,
2324
)

tests/test_pnytter_tweets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from pnytter import TwitterTweet
44

5-
from ._test_pnytter_tweets_data import GetTweetsYearprogress, NonExistingTweetId, GermanyBlockedTweet
5+
from tests._test_pnytter_tweets_data import GetTweetsYearprogress, NonExistingTweetId, GermanyBlockedTweet
66

77

88
@pytest.mark.parametrize("username, filter_from, filter_to, expected_pages, expected_tweets", [

0 commit comments

Comments
 (0)