Skip to content

Replace __file__ with pkgutil.get_data #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ python:
- 3.7
- 3.8

before_install:
- pip install -r requirements-dev.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this for other stuff that will be added later. Can you revert this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm, iirc if they are installed the list at https://github.com/jackmaney/python-stdlib-list/pull/30/files#diff-9e9ddedef65dec3da86063a067839e65R36 becomes quite large.

I suggest when they are needed on Travis, they are installed inside a tox testenv. I didnt delete the file - it is still available to be used for other Travis jobs, e.g. a docs or publish job, and can be used by devs locally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Let's keep them away for now and I'll send another PR later for this.

Let's keep this in! Thanks for the tests and improvements. I'll see if I can get a new release out after this.


install:
- python setup.py sdist && version=$(python setup.py --version) && pushd dist && pip install stdlib-list-${version}.tar.gz && popd

script:
# FIXME: add some real test.
- python -c "import stdlib_list; print(stdlib_list.stdlib_list('$TRAVIS_PYTHON_VERSION'))"
- python -m tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\o/


deploy:
skip_cleanup: true
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ include README.rst
include LICENSE
include versioneer.py
include stdlib_list/_version.py
recursive-include tests *.py
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def read(*parts):
long_description="{}".format(read("README.md")),
long_description_content_type="text/markdown",
include_package_data=True,
packages=find_packages(),
packages=find_packages(exclude=["tests", "tests.*"]),
cmdclass=versioneer.get_cmdclass(),
)
9 changes: 8 additions & 1 deletion stdlib_list/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from ._version import get_versions

__version__ = get_versions()['version']
del get_versions

# Import all the things that used to be in here for backwards-compatibility reasons
from .base import stdlib_list, in_stdlib, get_canonical_version, short_versions, long_versions, base_dir, list_dir
from .base import (
stdlib_list,
in_stdlib,
get_canonical_version,
short_versions,
long_versions,
)
12 changes: 5 additions & 7 deletions stdlib_list/base.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
from __future__ import print_function, absolute_import

import os
import pkgutil
import sys

try:
from functools import lru_cache
except ImportError:
from functools32 import lru_cache

base_dir = os.path.dirname(os.path.realpath(__file__))

list_dir = os.path.join(base_dir, "lists")

long_versions = ["2.6.9", "2.7.9", "3.2.6", "3.3.6", "3.4.3", "3.5", "3.6",
"3.7", "3.8"]

Expand Down Expand Up @@ -45,10 +42,11 @@ def stdlib_list(version=None):
version = get_canonical_version(version) if version is not None else '.'.join(
str(x) for x in sys.version_info[:2])

module_list_file = os.path.join(list_dir, "{}.txt".format(version))
module_list_file = os.path.join("lists", "{}.txt".format(version))

data = pkgutil.get_data("stdlib_list", module_list_file).decode()

with open(module_list_file) as f:
result = [y for y in [x.strip() for x in f.readlines()] if y]
result = [y for y in [x.strip() for x in data.splitlines()] if y]

return result

Expand Down
Loading