├── .github
└── workflows
│ └── ci.yml
├── .gitignore
├── README.md
├── github2pypi
├── __init__.py
├── replace_url.py
└── test_replace_url.py
├── pyproject.toml
├── setup.cfg
└── setup.py
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: ci
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | pull_request:
8 |
9 | jobs:
10 | lint:
11 | runs-on: ubuntu-latest
12 | strategy:
13 | matrix:
14 | python-version: [3.9]
15 | steps:
16 | - uses: actions/checkout@v2
17 | - name: Set up Python ${{ matrix.python-version }}
18 | uses: actions/setup-python@v2
19 | with:
20 | python-version: ${{ matrix.python-version }}
21 | - name: Flake8
22 | run: |
23 | pip install hacking==4.1.0
24 | flake8 .
25 | - name: Black
26 | run: |
27 | pip install black==22.1.0
28 | black --diff --check .
29 |
30 | build:
31 | runs-on: ubuntu-latest
32 | strategy:
33 | matrix:
34 | python-version: [2.7, 3.6, 3.7, 3.8, 3.9]
35 | steps:
36 | - uses: actions/checkout@v2
37 | - name: Set up Python ${{ matrix.python-version }}
38 | uses: actions/setup-python@v2
39 | with:
40 | python-version: ${{ matrix.python-version }}
41 | - name: Test
42 | run: |
43 | pip install pytest
44 | pytest -vsx .
45 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | __pycache__/
2 | *.pyc
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | github2pypi
3 |
4 |
5 |
6 | Utils to release Python repository on GitHub to PyPi
7 |
8 |
9 |
10 |

11 |
12 |
13 |
14 | ## Usage
15 |
16 | ### 1. Install `github2pypi`.
17 |
18 | ```bash
19 | pip install github2pypi
20 | ```
21 |
22 |
23 | ### 2. Edit `setup.py`.
24 |
25 | ```python
26 | import github2pypi
27 |
28 | ...
29 | with open('README.md') as f:
30 | # e.g.,  ->
31 | # 
32 | long_description = github2pypi.replace_url(
33 | slug='wkentaro/imgviz', content=f.read(), branch="main"
34 | )
35 |
36 | setup(
37 | ...
38 | long_description=long_description,
39 | long_description_content_type='text/markdown',
40 | )
41 | ```
42 |
43 |
44 | ## Examples
45 |
46 | - https://github.com/wkentaro/labelme
47 | - https://github.com/wkentaro/imgviz
48 |
--------------------------------------------------------------------------------
/github2pypi/__init__.py:
--------------------------------------------------------------------------------
1 | # flake8: noqa
2 |
3 | from .replace_url import replace_url
4 |
--------------------------------------------------------------------------------
/github2pypi/replace_url.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 |
4 | def replace_url(slug, content, branch):
5 | def repl(match):
6 | if not match:
7 | return
8 |
9 | url = match.group(1)
10 | if url.startswith("http"):
11 | return match.group(0)
12 |
13 | url_new = "https://github.com/{slug}/blob/{branch}/{url}".format(
14 | slug=slug, branch=branch, url=url
15 | )
16 | if re.match(r".*[\.jpg|\.png|\.gif]$", url_new):
17 | url_new += "?raw=true"
18 |
19 | start0, end0 = match.regs[0]
20 | start, end = match.regs[1]
21 | start -= start0
22 | end -= start0
23 |
24 | res = match.group(0)
25 | res = res[:start] + url_new + res[end:]
26 | return res
27 |
28 | lines = []
29 | for line in content.splitlines():
30 | patterns = [
31 | r"!\[.*?\]\((.*?)\)",
32 | r'',
33 | r"\[.*?\]\((.*?)\)",
34 | r'',
35 | ]
36 | for pattern in patterns:
37 | line = re.sub(pattern, repl, line)
38 | lines.append(line)
39 | return "\n".join(lines)
40 |
--------------------------------------------------------------------------------
/github2pypi/test_replace_url.py:
--------------------------------------------------------------------------------
1 | from github2pypi.replace_url import replace_url
2 |
3 |
4 | def test_replace_test():
5 | slug = "wkentaro/imgviz"
6 | content = ""
7 | content = replace_url(slug, content, branch="main")
8 |
9 | assert (
10 | content
11 | == "" # NOQA
12 | )
13 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [tool.black]
2 | line-length = 79
3 | exclude = '''
4 | (
5 | ^/\..*
6 | )
7 | '''
8 |
--------------------------------------------------------------------------------
/setup.cfg:
--------------------------------------------------------------------------------
1 | [metadata]
2 | name = github2pypi
3 | version = 1.0.0
4 | author = Kentaro Wada
5 | author_email = www.kentaro.wada@gmail.com
6 | url = https://github.com/wkentaro/github2pypi
7 | description = Utils to release Python project from GitHub to PyPi.
8 | long_description = file: README.md
9 | long_description_content_type = text/markdown
10 | license = MIT
11 | # license_file = LICENSE
12 | platform = any
13 | keywords = "GitHub Release"
14 | classifiers =
15 | Development Status :: 3 - Alpha
16 | Intended Audience :: Developers
17 | License :: OSI Approved :: MIT License
18 | Operating System :: OS Independent
19 | Programming Language :: Python
20 | Programming Language :: Python :: 3.4
21 | Programming Language :: Python :: 3.5
22 | Programming Language :: Python :: 3.6
23 | Programming Language :: Python :: 3.7
24 | Programming Language :: Python :: 3.8
25 | Topic :: Software Development :: Libraries :: Python Modules
26 | project_urls =
27 | Bug Tracker = https://github.com/wkentaro/github2pypi/issues
28 |
29 | [options]
30 | zip_safe = false
31 | include_package_data = true
32 | python_requires = >= 2.7, != 3.0.*, != 3.1.*, != 3.2.*
33 | packages = github2pypi
34 | test_suite = tests
35 | setup_requires =
36 | setuptools
37 | # setuptools >=30.3.0 # minimal version for `setup.cfg`
38 | # setuptools >=38.3.0 # version with most `setup.cfg` bugfixes
39 | # setuptools >=46.4.0 # let's you use attr: to extract version from a module
40 | install_requires =
41 | tests_require =
42 | pytest
43 |
44 | [options.package_data]
45 | github2pypi = py.typed, *.pyi
46 |
47 | [bdist_wheel]
48 | universal = true
49 |
50 | [sdist]
51 | formats = zip, gztar
52 |
53 | [flake8]
54 | max-line-length = 79
55 | doctests = True
56 | exclude = .git, .eggs, __pycache__, tests/, docs/, build/, dist/
57 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | import setuptools
2 |
3 |
4 | if __name__ == "__main__":
5 | setuptools.setup()
6 |
--------------------------------------------------------------------------------