Skip to content

Commit

Permalink
Fix requirements & update database
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaochao Dong (@damnever) <the.xcdong@gmail.com>
  • Loading branch information
damnever committed Nov 13, 2022
1 parent 7c0db48 commit a6aed4b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
Binary file modified pigar/.db.sqlite3
Binary file not shown.
17 changes: 7 additions & 10 deletions pigar/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@
Color, lines_diff, print_table, parse_requirements, PraseRequirementError,
trim_prefix, trim_suffix
)
from .parser import parse_imports, parse_installed_packages
from .parser import parse_imports, parse_installed_packages, _special_package_import_names
from .pypi import PKGS_URL, Downloader, Updater

from requests.exceptions import HTTPError

# FIXME: dirty workaround..
_special_packages = {
"dogpile.cache": "dogpile.cache",
"dogpile.core": "dogpile.core",
"ruamel.yaml": "ruamel.yaml",
"ruamel.ordereddict": "ruamel.ordereddict",
}
_special_import_names = {}
for pkg_name, import_names in _special_package_import_names.items():
for import_name in import_names:
_special_import_names[import_name] = pkg_name


class RequirementsGenerator(object):
Expand Down Expand Up @@ -342,8 +339,8 @@ def parse_packages(package_root, ignores=None, installed_pkgs=None):
names.append('flask')
names.append('flask_' + name.split('.')[2])
# Special cases..
elif special_name in _special_packages:
names.append(_special_packages[special_name])
elif special_name in _special_import_names:
names.append(special_name)
# Other.
elif '.' in name:
names.append(name.split('.')[0])
Expand Down
9 changes: 1 addition & 8 deletions pigar/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import print_function, division, absolute_import

import os
import re
import sqlite3
import contextlib
try: # py2
Expand All @@ -12,14 +13,6 @@

from .helpers import Dict, retry

# TODO(damnever): insert into db by default.
# (import_name, package_name)
_F_PACKAGES = {
'yaml': 'PyYAML',
'dogpile.cache': 'dogpile.cache',
'dogpile.core': 'dogpile.core',
}


class Database(object):
"""Database store (top_level_name, package_name) piars.
Expand Down
13 changes: 13 additions & 0 deletions pigar/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,15 @@ def parse_installed_packages():
return mapping


# FIXME: dirty workaround..
# Special distributions top level import name: Distribution name -> import name.
_special_package_import_names = {
"dogpile.cache": ("dogpile.cache", ),
"dogpile.core": ("dogpile.core", ),
"ruamel.yaml": ("ruamel.yaml", ),
}


def _search_path(path):
mapping = dict()

Expand All @@ -304,6 +313,10 @@ def _search_path(path):
with open(top_level, 'r') as f:
for line in f:
mapping[line.strip()] = (pkg_name, version)
for import_name in _special_package_import_names.get(
pkg_name, set()
):
mapping[import_name] = (pkg_name, version)

# Install from local and available in GitHub.
elif fnmatch.fnmatch(file, '*-link'):
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
change_logs = f.read()

install_requires = [
'colorama>=0.3.9', 'requests>=2.20.0', 'nbformat>=4.4.0',
'colorama>=0.3.9', 'requests>=2.20.0', 'nbformat>=4.4.0', 'packaging>=20.9'
'futures;python_version<"3.2"'
]

Expand Down Expand Up @@ -70,7 +70,8 @@
],
keywords='requirements.txt,automation,tool,module-search',
packages=find_packages(
exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
exclude=["*.tests", "*.tests.*", "tests.*", "tests"]
),
install_requires=install_requires,
include_package_data=True,
entry_points={'console_scripts': [
Expand Down

0 comments on commit a6aed4b

Please sign in to comment.