Skip to content

Commit

Permalink
Show required vs optional deps (#32)
Browse files Browse the repository at this point in the history
* Show required vs optional deps

`pip install x` does not install extras dependencies by default, so we'll show them in a separate list.

This is particularly useful for packages which have many optional integrations, or which track development dependencies using package extras.

* some cleanup

Co-authored-by: flynn <[email protected]>
  • Loading branch information
Zac-HD and crflynn authored Aug 16, 2020
1 parent a5bb518 commit 2db8a71
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
16 changes: 6 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
web:
build:
context: .
image: web
command: webdev
depends_on:
- postgresql
Expand All @@ -30,17 +31,15 @@ services:
volumes:
- "./pypistats/:/app/pypistats/"
beat:
build:
context: .
image: web
command: beat
depends_on:
- redis
<<: *envs
volumes:
- "./pypistats/:/app/pypistats/"
celery:
build:
context: .
image: web
command: celery
depends_on:
- redis
Expand All @@ -49,8 +48,7 @@ services:
volumes:
- "./pypistats/:/app/pypistats/"
flower:
build:
context: .
image: web
command: flower
depends_on:
- redis
Expand All @@ -60,8 +58,7 @@ services:
volumes:
- "./pypistats/:/app/pypistats/"
migrate:
build:
context: .
image: web
command: migrate
depends_on:
- postgresql
Expand All @@ -70,8 +67,7 @@ services:
- "./pypistats/:/app/pypistats/"
- "./migrations/:/app/migrations/"
seeds:
build:
context: .
image: web
command: seeds
depends_on:
- postgresql
Expand Down
4 changes: 4 additions & 0 deletions migrations/seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
for line in output.split("\n")[1:-1]:
packages.append(line.split(" ")[0])

# add some packages that have optional dependencies
packages.append("apache-airflow")
packages.append("databricks-dbapi")

logging.info(packages)

# take the last 120 days
Expand Down
10 changes: 9 additions & 1 deletion pypistats/templates/package.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,20 @@ <h1>{{ package }}</h1>
{{ metadata['info']['version'] }}
<br>
{% if metadata['requires'] %}
Requires:
Required dependencies:
{% for required in metadata['requires'] %}
<a href="{{ url_for('general.package_page', package=required.lower()) }}">{{ required.lower() }}</a>
{% if not loop.last %}|{% endif %}
{% endfor %}
{% endif %}
{% if metadata['optional'] %}
<br>
Optional dependencies:
{% for optional in metadata['optional'] %}
<a href="{{ url_for('general.package_page', package=optional.lower()) }}">{{ optional.lower() }}</a>
{% if not loop.last %}|{% endif %}
{% endfor %}
{% endif %}
{% else %}
No metadata found.
{% endif %}
Expand Down
13 changes: 9 additions & 4 deletions pypistats/views/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,15 @@ def package_page(package):
try:
metadata = requests.get(f"https://pypi.python.org/pypi/{package}/json", timeout=5).json()
if metadata["info"].get("requires_dist", None):
requires = set()
for required in metadata["info"]["requires_dist"]:
requires.add(re.split(r"[^0-9a-zA-Z_.-]+", required)[0])
metadata["requires"] = sorted(list(requires))
requires, optional = set(), set()
for dependency in metadata["info"]["requires_dist"]:
package_name = re.split(r"[^0-9a-zA-Z_.-]+", dependency.lower())[0]
if "; extra ==" in dependency:
optional.add(package_name)
else:
requires.add(package_name)
metadata["requires"] = sorted(requires)
metadata["optional"] = sorted(optional)
except Exception:
pass

Expand Down

0 comments on commit 2db8a71

Please sign in to comment.