Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #411 from dephell/improve-links
Browse files Browse the repository at this point in the history
Simplify links putting for old formats
  • Loading branch information
orsinium committed Mar 19, 2020
2 parents af3f3ac + 0887ed2 commit 58d022b
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 43 deletions.
3 changes: 3 additions & 0 deletions dephell/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class ReturnCodes(Enum):
DEFAULT_UPLOAD = 'https://upload.pypi.org/legacy/'
TEST_UPLOAD = 'https://test.pypi.org/legacy/'

HOMEPAGE_FIELD = 'homepage'
DOWNLOAD_FIELD = 'download'

FORMATS = (
'conda',
'egginfo',
Expand Down
12 changes: 2 additions & 10 deletions dephell/controllers/_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,9 @@ def _get_metadata(cls, root) -> dict:
if author.mail:
meta['maintainer_email'] = author.mail

fields = dict(
homepage='home_page',
home='home_page',
download='download_url',
)
for key, url in root.links.items():
if key in fields:
meta[fields[key]] = url
else:
key = key[0].upper() + key[1:]
meta['project_urls'].append('{}, {}'.format(key, url))
key = key[0].upper() + key[1:]
meta['project_urls'].append('{}, {}'.format(key, url))

if root.python:
meta['requires_python'] = str(root.python.peppify())
Expand Down
18 changes: 6 additions & 12 deletions dephell/converters/egginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from packaging.requirements import Requirement as PackagingRequirement

# app
from ..constants import DOWNLOAD_FIELD, HOMEPAGE_FIELD
from ..controllers import DependencyMaker, Readme
from ..models import Author, EntryPoint, RootDependency
from .base import BaseConverter
Expand Down Expand Up @@ -128,16 +129,16 @@ def parse_info(cls, content: str, root=None, urls: Dict[str, str] = None) -> Roo

# links
fields = (
('homepage', 'Home-Page'),
('download', 'Download-URL'),
(HOMEPAGE_FIELD, 'Home-Page'),
(DOWNLOAD_FIELD, 'Download-URL'),
)
for key, name in fields:
link = cls._get(info, name)
if link:
root.links[key] = link
for link in cls._get_list(info, 'Project-URL'):
key, url = link.split(', ')
root.links[key] = url
root.links[key.lower()] = url

# authors
for name in ('author', 'maintainer'):
Expand Down Expand Up @@ -268,16 +269,9 @@ def make_info(self, reqs, project: RootDependency, with_requires: bool) -> str:
content.append(('Summary', project.description))

# links
fields = dict(
homepage='Home-Page',
download='Download-URL',
)
for key, url in project.links.items():
if key in fields:
content.append((fields[key], url))
else:
key = key[0].upper() + key[1:]
content.append(('Project-URL', '{}, {}'.format(key, url)))
key = key[0].upper() + key[1:]
content.append(('Project-URL', '{}, {}'.format(key, url)))

# authors
if project.authors:
Expand Down
9 changes: 3 additions & 6 deletions dephell/converters/flit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from packaging.requirements import Requirement

# app
from ..constants import HOMEPAGE_FIELD
from ..controllers import DependencyMaker, Readme
from ..models import Author, EntryPoint, RootDependency
from .base import BaseConverter
Expand Down Expand Up @@ -81,7 +82,7 @@ def loads(self, content: str) -> RootDependency:

# links
if 'home-page' in section:
root.links['homepage'] = section['home-page']
root.links[HOMEPAGE_FIELD] = section['home-page']
if 'urls' in section:
root.links.update(section['urls'])

Expand Down Expand Up @@ -175,9 +176,7 @@ def dumps(self, reqs, project: RootDependency, content=None) -> str:
section[field] = value

# write links
if 'homepage' in project.links:
section['home-page'] = project.links['homepage']
if set(project.links) - {'homepage'}:
if project.links:
if 'urls' in section:
# remove old
for name in section['urls']:
Expand All @@ -187,8 +186,6 @@ def dumps(self, reqs, project: RootDependency, content=None) -> str:
section['urls'] = tomlkit.table()
# add and update
for name, url in project.links.items():
if name == 'homepage':
continue
section['urls'][name] = url
elif 'urls' in section:
del section['urls']
Expand Down
14 changes: 6 additions & 8 deletions dephell/converters/setuppy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from packaging.requirements import Requirement

# app
from ..constants import DOWNLOAD_FIELD, HOMEPAGE_FIELD
from ..controllers import DependencyMaker, Readme
from ..models import Author, EntryPoint, RootDependency
from .base import BaseConverter
Expand Down Expand Up @@ -94,7 +95,11 @@ def load(self, path) -> RootDependency:
)

# links
for key, name in (('home', 'url'), ('download', 'download_url')):
fields = (
(HOMEPAGE_FIELD, 'url'),
(DOWNLOAD_FIELD, 'download_url'),
)
for key, name in fields:
link = data.get(name)
if link:
root.links[key] = link
Expand Down Expand Up @@ -158,13 +163,6 @@ def dumps(self, reqs, project: RootDependency, content=None) -> str:
content.append(('python_requires', str(project.python.peppify())))

# links
fields = (
('home', 'url'),
('download', 'download_url'),
)
for key, name in fields:
if key in project.links:
content.append((name, project.links[key]))
if project.links:
content.append(('project_urls', project.links))

Expand Down
3 changes: 2 additions & 1 deletion dephell/repositories/_conda/_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ...cache import JSONCache
from ...cached_property import cached_property
from ...config import config
from ...constants import HOMEPAGE_FIELD
from ...models.release import Release
from ...models.simple_dependency import SimpleDependency
from ...networking import requests_session
Expand All @@ -34,7 +35,7 @@
# https://repo.anaconda.com/pkgs/r/noarch

URL_FIELDS = {
'home': 'homepage',
'home': HOMEPAGE_FIELD,
'dev_url': 'repository',
'doc_url': 'documentation',
'license_url': 'license',
Expand Down
3 changes: 2 additions & 1 deletion dephell/repositories/_conda/_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ...cache import JSONCache
from ...cached_property import cached_property
from ...config import config
from ...constants import HOMEPAGE_FIELD
from ...models.release import Release
from ...models.simple_dependency import SimpleDependency
from ...networking import aiohttp_session, requests_session
Expand All @@ -43,7 +44,7 @@
CONTENT_URL = 'https://raw.githubusercontent.com/{repo}/{rev}/{path}'

URL_FIELDS = {
'home': 'homepage',
'home': HOMEPAGE_FIELD,
'dev_url': 'repository',
'doc_url': 'documentation',
'license_url': 'license',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"full": [
"aiofiles", "appdirs", "autopep8", "bowler", "colorama", "docker",
"dockerpty", "fissix", "graphviz", "html5lib", "pygments",
"tabulate", "yapf"
"python-gnupg", "tabulate", "yapf"
],
"tests": ["aioresponses", "pytest", "requests-mock"]
},
Expand Down
4 changes: 2 additions & 2 deletions tests/requirements/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
description='Dependency resolution for Python',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://dephell.org/',
author='orsinium',

packages=[],
Expand All @@ -47,7 +46,8 @@
],
keywords='sample setuptools development',
project_urls={ # Optional
'Source': 'https://github.com/dephell/dephell/',
'homepage': 'https://dephell.org/',
'source': 'https://github.com/dephell/dephell/',
},
entry_points={
'console_scripts': ['dephell = dephell.cli:entrypoint'],
Expand Down
3 changes: 2 additions & 1 deletion tests/test_converters/test_egginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ def test_dumps_metainfo(requirements_path: Path):
parsed = Parser().parsestr(content)
assert parsed.get('Name') == 'dephell'
assert parsed.get('Version') == '0.2.0'
assert parsed.get('Home-Page') == 'https://github.com/orsinium/dephell'
exp = ['Homepage, https://github.com/orsinium/dephell']
assert parsed.get_all('Project-URL') == exp
2 changes: 1 addition & 1 deletion tests/test_repositories/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_root_dir(requirements_path: Path):
root = repo.get_root(name='dephell', version='0.2.0')
assert root.name == 'dephell'
assert root.version == '0.2.1'
assert root.links['home'] == 'https://github.com/orsinium/dephell'
assert root.links['homepage'] == 'https://github.com/orsinium/dephell'


def test_deps_file(requirements_path: Path):
Expand Down

0 comments on commit 58d022b

Please sign in to comment.