Skip to content

Commit

Permalink
Fix incremental synchronization
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 Dec 2, 2022
1 parent 1ca091d commit c665a52
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Binary file modified pigar/.db.sqlite3
Binary file not shown.
38 changes: 20 additions & 18 deletions pigar/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,11 @@ async def _sync_project(self, project_url):
dist = db.query_distribution_with_top_level_modules(project_name)

try:
with tempfile.TemporaryDirectory() as tmp_download_dir:
# FIXME(damnever): create temporary directory on demand.
version, top_levels = await self._parse_top_levels(
project_name,
project_url,
tmp_download_dir,
)
version, project_download_url = await self._pypi_distributions.get_latest_distribution_info(
project_name,
project_url,
include_prereleases=False,
)
if version is None:
logger.warn(
'distribution "%s" has no valid versions', project_name
Expand All @@ -553,6 +551,15 @@ async def _sync_project(self, project_url):
project_name, dist.version
)
return
with tempfile.TemporaryDirectory() as tmp_download_dir:
# FIXME(damnever): create temporary directory on demand.
top_levels = await self._parse_top_levels(
project_name,
project_download_url,
tmp_download_dir,
)
if top_levels is None:
return

modules_to_add = set(top_levels or [])
modules_to_delete = None
Expand Down Expand Up @@ -581,17 +588,12 @@ async def _sync_project(self, project_url):
raise e

async def _parse_top_levels(
self, project_name, project_url, tmp_download_dir
self, project_name, project_download_url, tmp_download_dir
):
version, url, dist_file = await self._pypi_distributions.get_latest_distribution(
project_name,
project_url,
include_prereleases=False,
tmp_download_dir=tmp_download_dir,
dist_file = await self._pypi_distributions._download_raw(
project_download_url, tmp_download_dir=tmp_download_dir
)
if version is None:
return None, None
filename = urlparse(url).path
filename = urlparse(project_download_url).path

event_loop = asyncio.get_event_loop()
try:
Expand All @@ -605,7 +607,7 @@ async def _parse_top_levels(
filename,
exc_info=True,
)
return None, None
return None
top_levels = _maybe_include_project_name_as_import_name(
top_levels, project_name
)
Expand All @@ -616,4 +618,4 @@ async def _parse_top_levels(
logger.debug(
'distribution %s parsed top levels: %r', project_name, top_levels
)
return version, top_levels
return top_levels

0 comments on commit c665a52

Please sign in to comment.