Skip to content

Commit

Permalink
Integrate traits-stubs into the traits package (#1714)
Browse files Browse the repository at this point in the history
This PR (targeting Traits 7.0) integrates the separate traits-stubs package into the main traits package. This will remove the need to make a separate release of the traits-stubs package every time we release the traits package.

Notes:

* The stubs tests fail when run from an editable install, but are happy when run for a non-editable install
* This PR introduces a dependency on typing-extensions for Python 3.6 and Python 3.7

Closes #1254
  • Loading branch information
mdickinson committed Aug 18, 2022
1 parent aca38d0 commit 3e6ea50
Show file tree
Hide file tree
Showing 71 changed files with 28 additions and 217 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
- [ ] Tests
- [ ] Update API reference (`docs/source/traits_api_reference`)
- [ ] Update User manual (`docs/source/traits_user_manual`)
- [ ] Update type annotation hints in `traits-stubs`
- [ ] Update type annotation hints in stub files
6 changes: 0 additions & 6 deletions .github/workflows/run-traits-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install .[test]
python -m pip install traits-stubs/[test]
- name: Create clean test directory
run: |
mkdir testdir
Expand All @@ -44,8 +43,3 @@ jobs:
with:
working-directory: testdir
run: python -m unittest discover -v traits
- name: Test Traits typing stubs
uses: GabrielBB/xvfb-action@v1
with:
working-directory: testdir
run: python -m unittest discover -v traits_stubs_tests
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
*.egg-info/
/build/
/dist/
/traits-stubs/build/
/traits-stubs/dist/
/docs/build/

# Coverage artifacts
Expand Down
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ TBD Release summary
Detailed changes
~~~~~~~~~~~~~~~~

Features
~~~~~~~~
* The traits package now ships with stub files directly, instead of requiring
those files to be installed via the separate ``traits-stubs`` package.
(#1714)

Removals
~~~~~~~~
* Remove deprecated ``rich_compare`` Trait metadata. (#1698)
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ recursive-exclude docs *.pyc
graft examples
recursive-exclude examples *.pyc
include traits/ctraits.c
include traits/py.typed
recursive-include traits *.py
include traits/observation/_dsl_grammar.lark
8 changes: 0 additions & 8 deletions etstool.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,11 @@ def install(edm, runtime, environment, editable, source):
# of TraitsUI from EDM installs Traits as a dependency, so we need
# to explicitly uninstall it before re-installing from source.
install_traits = _get_install_command_string(".", editable=editable)
install_stubs = _get_install_command_string(
"./traits-stubs/", editable=editable
)
commands = [
"{edm} environments create {environment} --force --version={runtime}",
"{edm} --config edm.yaml install -y -e {environment} " + packages,
"{edm} plumbing remove-package -e {environment} traits",
install_traits,
install_stubs,
]

if pypi_dependencies:
Expand Down Expand Up @@ -285,10 +281,6 @@ def test(edm, runtime, verbose, environment):
"{edm} run -e {environment} -- coverage run -p -m "
"unittest discover " + options + "traits",
]
commands += [
"{edm} run -e {environment} -- coverage run -p -m "
"unittest discover " + options + "traits_stubs_tests",
]

# We run in a tempdir to avoid accidentally picking up wrong traits
# code from a local dir. We need to ensure a good .coveragerc is in
Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ target-version = ['py36']
profile = 'black'
line_length = 79
order_by_type = 'False'

[tool.pytest.ini_options]
addopts = '--ignore=traits-stubs'
15 changes: 14 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def get_long_description():
Topic :: Software Development
Topic :: Software Development :: Libraries
Topic :: Software Development :: User Interfaces
Typing :: Typed
""".splitlines()
if len(c.strip()) > 0
],
Expand All @@ -299,7 +300,11 @@ def get_long_description():
"Documentation": "https://docs.enthought.com/traits",
"Source Code": "https://github.com/enthought/traits",
},
install_requires=[],
install_requires=[
# We need typing-extensions for SupportsIndex; once we no longer
# support Python < 3.8, we can drop this requirement.
'typing-extensions; python_version<"3.8"',
],
extras_require={
"docs": [
"enthought-sphinx-theme",
Expand Down Expand Up @@ -327,6 +332,10 @@ def get_long_description():
},
ext_modules=[setuptools.Extension("traits.ctraits", ["traits/ctraits.c"])],
package_data={
"traits": [
"py.typed",
"*.pyi",
],
"traits.examples": [
"introduction/*",
"introduction/*/*",
Expand All @@ -336,6 +345,10 @@ def get_long_description():
"test-data/historical-pickles/*.pkl",
"test-data/historical-pickles/*.py",
],
"traits.stubs_tests": [
"examples/*.py",
"numpy_examples/*.py",
],
},
entry_points={
"etsdemo_data": [
Expand Down
28 changes: 0 additions & 28 deletions traits-stubs/LICENSE.txt

This file was deleted.

4 changes: 0 additions & 4 deletions traits-stubs/MANIFEST.in

This file was deleted.

80 changes: 0 additions & 80 deletions traits-stubs/README.rst

This file was deleted.

3 changes: 0 additions & 3 deletions traits-stubs/pyproject.toml

This file was deleted.

75 changes: 0 additions & 75 deletions traits-stubs/setup.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion traits/examples/introduction/1_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(self, filename, sample_id, date_acquired, operator,
may be aware of, and using these classes already.
As we will see, the capabilities of Traits are much greater than these type
checking systems, however if you have the traits-stubs package installed,
checking systems. However, Traits now ships with a selection of stub files, so
most of your trait type declarations will be recognised and can be used with
these new Python type systems.
Expand Down
File renamed without changes.
File renamed without changes.
Empty file added traits/stubs_tests/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
requires_numpy_typing,
requires_pkg_resources,
)
from traits_stubs_tests.util import MypyAssertions
from traits.stubs_tests.util import MypyAssertions


@requires_pkg_resources
@requires_mypy
class TestAnnotations(TestCase, MypyAssertions):
def test_all(self, filename_suffix=""):
""" Run mypy for all files contained in traits_stubs_tests/examples
""" Run mypy for all files contained in traits.stubs_tests/examples
directory.
Lines with expected errors are marked inside these files.
Expand All @@ -37,15 +37,15 @@ def test_all(self, filename_suffix=""):
Optional filename suffix filter.
"""
examples_dir = Path(pkg_resources.resource_filename(
'traits_stubs_tests', 'examples'))
'traits.stubs_tests', 'examples'))

for file_path in examples_dir.glob("*{}.py".format(filename_suffix)):
with self.subTest(file_path=file_path):
self.assertRaisesMypyError(file_path)

@requires_numpy_typing
def test_numpy_examples(self):
""" Run mypy for files contained in traits_stubs_tests/numpy_examples
""" Run mypy for files contained in traits.stubs_tests/numpy_examples
directory.
Lines with expected errors are marked inside these files.
Expand All @@ -57,7 +57,7 @@ def test_numpy_examples(self):
Optional filename suffix filter.
"""
examples_dir = Path(pkg_resources.resource_filename(
'traits_stubs_tests', 'numpy_examples'))
'traits.stubs_tests', 'numpy_examples'))

for file_path in examples_dir.glob("*.py"):
with self.subTest(file_path=file_path):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 3e6ea50

Please sign in to comment.