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

Commit

Permalink
34185: correction according to review
Browse files Browse the repository at this point in the history
  • Loading branch information
soehms committed Jul 18, 2022
1 parent f51f29a commit 3071dbc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
12 changes: 2 additions & 10 deletions src/sage/features/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,9 @@ def _spkg_type(self):
The type as a string in ``('base', 'standard', 'optional', 'experimental')``.
If no SPKG corresponds to this feature ``None`` is returned.
"""
from sage.misc.package import _spkg_type
return _spkg_type(self.name)
spkg_type = None
from sage.env import SAGE_PKGS
try:
f = open(os.path.join(SAGE_PKGS, self.name, "type"))
except IOError:
# Probably an empty directory => ignore
return None

with f:
spkg_type = f.read().strip()
return spkg_type

def resolution(self):
r"""
Expand Down
41 changes: 34 additions & 7 deletions src/sage/misc/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,38 @@ def pip_remote_version(pkg, pypi_url=DEFAULT_PYPI, ignore_URLError=False):
stable_releases = [v for v in info['releases'] if 'a' not in v and 'b' not in v]
return max(stable_releases)

def _spkg_type(name):
r"""
Return the type of the Sage package with the given name.
INPUT:
- ``name`` -- string giving the subdirectory name of the package under
``SAGE_PKGS``
EXAMPLES::
sage: from sage.misc.package import _spkg_type
sage: _spkg_type('pip')
'standard'
OUTPUT:
The type as a string in ``('base', 'standard', 'optional', 'experimental')``.
If no ``SPKG`` exists with the given name ``None`` is returned.
"""
spkg_type = None
from sage.env import SAGE_PKGS
try:
f = open(os.path.join(SAGE_PKGS, name, "type"))
except IOError:
# Probably an empty directory => ignore
return None

with f:
spkg_type = f.read().strip()
return spkg_type


def pip_installed_packages(normalization=None):
r"""
Expand Down Expand Up @@ -311,15 +343,10 @@ def list_packages(*pkg_types: str, pkg_sources: List[str] = ['normal', 'pip', 's

for p in lp:

try:
f = open(os.path.join(SAGE_PKGS, p, "type"))
except IOError:
# Probably an empty directory => ignore
typ = _spkg_type(p)
if not typ:
continue

with f:
typ = f.read().strip()

if os.path.isfile(os.path.join(SAGE_PKGS, p, "requirements.txt")):
src = 'pip'
elif os.path.isfile(os.path.join(SAGE_PKGS, p, "checksums.ini")):
Expand Down

0 comments on commit 3071dbc

Please sign in to comment.