Skip to content

Commit 15728ee

Browse files
trim21sdispater
andauthored
Fix vendor package as installed package (#1883) (#1981)
* Fix vendor package as installed package (#1883) * import from Co-Authored-By: Sébastien Eustace <[email protected]> * test vendor package as installed * refactor * remove blank line Co-authored-by: Sébastien Eustace <[email protected]>
1 parent 085d5a6 commit 15728ee

File tree

3 files changed

+246
-1
lines changed

3 files changed

+246
-1
lines changed

poetry/repositories/installed_repository.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from poetry import _CURRENT_VENDOR
12
from poetry.packages import Package
23
from poetry.utils._compat import Path
34
from poetry.utils._compat import metadata
@@ -22,18 +23,25 @@ def load(cls, env): # type: (Env) -> InstalledRepository
2223
metadata.distributions(path=[entry]), key=lambda d: str(d._path),
2324
):
2425
name = distribution.metadata["name"]
26+
path = Path(str(distribution._path))
2527
version = distribution.metadata["version"]
2628
package = Package(name, version, version)
2729
package.description = distribution.metadata.get("summary", "")
2830

2931
if package.name in seen:
3032
continue
3133

34+
try:
35+
path.relative_to(_CURRENT_VENDOR)
36+
except ValueError:
37+
pass
38+
else:
39+
continue
40+
3241
seen.add(package.name)
3342

3443
repo.add_package(package)
3544

36-
path = Path(str(distribution._path))
3745
is_standard_package = True
3846
try:
3947
path.relative_to(env.site_packages)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
Metadata-Version: 2.1
2+
Name: attrs
3+
Version: 19.3.0
4+
Summary: Classes Without Boilerplate
5+
Home-page: https://www.attrs.org/
6+
Author: Hynek Schlawack
7+
Author-email: [email protected]
8+
Maintainer: Hynek Schlawack
9+
Maintainer-email: [email protected]
10+
License: MIT
11+
Project-URL: Documentation, https://www.attrs.org/
12+
Project-URL: Bug Tracker, https://github.com/python-attrs/attrs/issues
13+
Project-URL: Source Code, https://github.com/python-attrs/attrs
14+
Keywords: class,attribute,boilerplate
15+
Platform: UNKNOWN
16+
Classifier: Development Status :: 5 - Production/Stable
17+
Classifier: Intended Audience :: Developers
18+
Classifier: Natural Language :: English
19+
Classifier: License :: OSI Approved :: MIT License
20+
Classifier: Operating System :: OS Independent
21+
Classifier: Programming Language :: Python
22+
Classifier: Programming Language :: Python :: 2
23+
Classifier: Programming Language :: Python :: 2.7
24+
Classifier: Programming Language :: Python :: 3
25+
Classifier: Programming Language :: Python :: 3.4
26+
Classifier: Programming Language :: Python :: 3.5
27+
Classifier: Programming Language :: Python :: 3.6
28+
Classifier: Programming Language :: Python :: 3.7
29+
Classifier: Programming Language :: Python :: 3.8
30+
Classifier: Programming Language :: Python :: Implementation :: CPython
31+
Classifier: Programming Language :: Python :: Implementation :: PyPy
32+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
33+
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
34+
Description-Content-Type: text/x-rst
35+
Provides-Extra: azure-pipelines
36+
Requires-Dist: coverage ; extra == 'azure-pipelines'
37+
Requires-Dist: hypothesis ; extra == 'azure-pipelines'
38+
Requires-Dist: pympler ; extra == 'azure-pipelines'
39+
Requires-Dist: pytest (>=4.3.0) ; extra == 'azure-pipelines'
40+
Requires-Dist: six ; extra == 'azure-pipelines'
41+
Requires-Dist: zope.interface ; extra == 'azure-pipelines'
42+
Requires-Dist: pytest-azurepipelines ; extra == 'azure-pipelines'
43+
Provides-Extra: dev
44+
Requires-Dist: coverage ; extra == 'dev'
45+
Requires-Dist: hypothesis ; extra == 'dev'
46+
Requires-Dist: pympler ; extra == 'dev'
47+
Requires-Dist: pytest (>=4.3.0) ; extra == 'dev'
48+
Requires-Dist: six ; extra == 'dev'
49+
Requires-Dist: zope.interface ; extra == 'dev'
50+
Requires-Dist: sphinx ; extra == 'dev'
51+
Requires-Dist: pre-commit ; extra == 'dev'
52+
Provides-Extra: docs
53+
Requires-Dist: sphinx ; extra == 'docs'
54+
Requires-Dist: zope.interface ; extra == 'docs'
55+
Provides-Extra: tests
56+
Requires-Dist: coverage ; extra == 'tests'
57+
Requires-Dist: hypothesis ; extra == 'tests'
58+
Requires-Dist: pympler ; extra == 'tests'
59+
Requires-Dist: pytest (>=4.3.0) ; extra == 'tests'
60+
Requires-Dist: six ; extra == 'tests'
61+
Requires-Dist: zope.interface ; extra == 'tests'
62+
63+
.. image:: https://www.attrs.org/en/latest/_static/attrs_logo.png
64+
:alt: attrs Logo
65+
66+
======================================
67+
``attrs``: Classes Without Boilerplate
68+
======================================
69+
70+
.. image:: https://readthedocs.org/projects/attrs/badge/?version=stable
71+
:target: https://www.attrs.org/en/stable/?badge=stable
72+
:alt: Documentation Status
73+
74+
.. image:: https://attrs.visualstudio.com/attrs/_apis/build/status/python-attrs.attrs?branchName=master
75+
:target: https://attrs.visualstudio.com/attrs/_build/latest?definitionId=1&branchName=master
76+
:alt: CI Status
77+
78+
.. image:: https://codecov.io/github/python-attrs/attrs/branch/master/graph/badge.svg
79+
:target: https://codecov.io/github/python-attrs/attrs
80+
:alt: Test Coverage
81+
82+
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
83+
:target: https://github.com/psf/black
84+
:alt: Code style: black
85+
86+
.. teaser-begin
87+
88+
``attrs`` is the Python package that will bring back the **joy** of **writing classes** by relieving you from the drudgery of implementing object protocols (aka `dunder <https://nedbatchelder.com/blog/200605/dunder.html>`_ methods).
89+
90+
Its main goal is to help you to write **concise** and **correct** software without slowing down your code.
91+
92+
.. -spiel-end-
93+
94+
For that, it gives you a class decorator and a way to declaratively define the attributes on that class:
95+
96+
.. -code-begin-
97+
98+
.. code-block:: pycon
99+
100+
>>> import attr
101+
102+
>>> @attr.s
103+
... class SomeClass(object):
104+
... a_number = attr.ib(default=42)
105+
... list_of_numbers = attr.ib(factory=list)
106+
...
107+
... def hard_math(self, another_number):
108+
... return self.a_number + sum(self.list_of_numbers) * another_number
109+
110+
111+
>>> sc = SomeClass(1, [1, 2, 3])
112+
>>> sc
113+
SomeClass(a_number=1, list_of_numbers=[1, 2, 3])
114+
115+
>>> sc.hard_math(3)
116+
19
117+
>>> sc == SomeClass(1, [1, 2, 3])
118+
True
119+
>>> sc != SomeClass(2, [3, 2, 1])
120+
True
121+
122+
>>> attr.asdict(sc)
123+
{'a_number': 1, 'list_of_numbers': [1, 2, 3]}
124+
125+
>>> SomeClass()
126+
SomeClass(a_number=42, list_of_numbers=[])
127+
128+
>>> C = attr.make_class("C", ["a", "b"])
129+
>>> C("foo", "bar")
130+
C(a='foo', b='bar')
131+
132+
133+
After *declaring* your attributes ``attrs`` gives you:
134+
135+
- a concise and explicit overview of the class's attributes,
136+
- a nice human-readable ``__repr__``,
137+
- a complete set of comparison methods (equality and ordering),
138+
- an initializer,
139+
- and much more,
140+
141+
*without* writing dull boilerplate code again and again and *without* runtime performance penalties.
142+
143+
On Python 3.6 and later, you can often even drop the calls to ``attr.ib()`` by using `type annotations <https://www.attrs.org/en/latest/types.html>`_.
144+
145+
This gives you the power to use actual classes with actual types in your code instead of confusing ``tuple``\ s or `confusingly behaving <https://www.attrs.org/en/stable/why.html#namedtuples>`_ ``namedtuple``\ s.
146+
Which in turn encourages you to write *small classes* that do `one thing well <https://www.destroyallsoftware.com/talks/boundaries>`_.
147+
Never again violate the `single responsibility principle <https://en.wikipedia.org/wiki/Single_responsibility_principle>`_ just because implementing ``__init__`` et al is a painful drag.
148+
149+
150+
.. -testimonials-
151+
152+
Testimonials
153+
============
154+
155+
**Amber Hawkie Brown**, Twisted Release Manager and Computer Owl:
156+
157+
Writing a fully-functional class using attrs takes me less time than writing this testimonial.
158+
159+
160+
**Glyph Lefkowitz**, creator of `Twisted <https://twistedmatrix.com/>`_, `Automat <https://pypi.org/project/Automat/>`_, and other open source software, in `The One Python Library Everyone Needs <https://glyph.twistedmatrix.com/2016/08/attrs.html>`_:
161+
162+
I’m looking forward to is being able to program in Python-with-attrs everywhere.
163+
It exerts a subtle, but positive, design influence in all the codebases I’ve see it used in.
164+
165+
166+
**Kenneth Reitz**, creator of `Requests <https://github.com/psf/requests>`_ (`on paper no less <https://twitter.com/hynek/status/866817877650751488>`_!):
167+
168+
attrs—classes for humans. I like it.
169+
170+
171+
**Łukasz Langa**, creator of `Black <https://github.com/psf/black>`_, prolific Python core developer, and release manager for Python 3.8 and 3.9:
172+
173+
I'm increasingly digging your attr.ocity. Good job!
174+
175+
176+
.. -end-
177+
178+
.. -project-information-
179+
180+
Getting Help
181+
============
182+
183+
Please use the ``python-attrs`` tag on `StackOverflow <https://stackoverflow.com/questions/tagged/python-attrs>`_ to get help.
184+
185+
Answering questions of your fellow developers is also great way to help the project!
186+
187+
188+
Project Information
189+
===================
190+
191+
``attrs`` is released under the `MIT <https://choosealicense.com/licenses/mit/>`_ license,
192+
its documentation lives at `Read the Docs <https://www.attrs.org/>`_,
193+
the code on `GitHub <https://github.com/python-attrs/attrs>`_,
194+
and the latest release on `PyPI <https://pypi.org/project/attrs/>`_.
195+
It’s rigorously tested on Python 2.7, 3.4+, and PyPy.
196+
197+
We collect information on **third-party extensions** in our `wiki <https://github.com/python-attrs/attrs/wiki/Extensions-to-attrs>`_.
198+
Feel free to browse and add your own!
199+
200+
If you'd like to contribute to ``attrs`` you're most welcome and we've written `a little guide <https://www.attrs.org/en/latest/contributing.html>`_ to get you started!
201+
202+
203+
Release Information
204+
===================
205+
206+
19.3.0 (2019-10-15)
207+
-------------------
208+
209+
Changes
210+
^^^^^^^
211+
212+
- Fixed ``auto_attribs`` usage when default values cannot be compared directly with ``==``, such as ``numpy`` arrays.
213+
`#585 <https://github.com/python-attrs/attrs/issues/585>`_
214+
215+
`Full changelog <https://www.attrs.org/en/stable/changelog.html>`_.
216+
217+
Credits
218+
=======
219+
220+
``attrs`` is written and maintained by `Hynek Schlawack <https://hynek.me/>`_.
221+
222+
The development is kindly supported by `Variomedia AG <https://www.variomedia.de/>`_.
223+
224+
A full list of contributors can be found in `GitHub's overview <https://github.com/python-attrs/attrs/graphs/contributors>`_.
225+
226+
It’s the spiritual successor of `characteristic <https://characteristic.readthedocs.io/>`_ and aspires to fix some of it clunkiness and unfortunate decisions.
227+
Both were inspired by Twisted’s `FancyEqMixin <https://twistedmatrix.com/documents/current/api/twisted.python.util.FancyEqMixin.html>`_ but both are implemented using class decorators because `subclassing is bad for you <https://www.youtube.com/watch?v=3MNVP9-hglc>`_, m’kay?
228+
229+

tests/repositories/test_installed_repository.py

+8
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
ENV_DIR = (FIXTURES_DIR / "installed").resolve()
1010
SITE_PACKAGES = ENV_DIR / "lib" / "python3.7" / "site-packages"
1111
SRC = ENV_DIR / "src"
12+
VENDOR_DIR = ENV_DIR / "vendor" / "py3.7"
1213
INSTALLED_RESULTS = [
1314
metadata.PathDistribution(SITE_PACKAGES / "cleo-0.7.6.dist-info"),
1415
metadata.PathDistribution(SRC / "pendulum" / "pendulum.egg-info"),
1516
metadata.PathDistribution(
1617
zipp.Path(str(SITE_PACKAGES / "foo-0.1.0-py3.8.egg"), "EGG-INFO")
1718
),
19+
metadata.PathDistribution(VENDOR_DIR / "attrs-19.3.0.dist-info"),
1820
]
1921

2022

@@ -40,6 +42,9 @@ def test_load(mocker):
4042
{"remote.origin.url": "[email protected]:sdispater/pendulum.git"},
4143
],
4244
)
45+
mocker.patch(
46+
"poetry.repositories.installed_repository._CURRENT_VENDOR", str(VENDOR_DIR)
47+
)
4348
repository = InstalledRepository.load(MockEnv(path=ENV_DIR))
4449

4550
assert len(repository.packages) == 3
@@ -63,3 +68,6 @@ def test_load(mocker):
6368
assert pendulum.source_type == "git"
6469
assert pendulum.source_url == "https://github.com/sdispater/pendulum.git"
6570
assert pendulum.source_reference == "bb058f6b78b2d28ef5d9a5e759cfa179a1a713d6"
71+
72+
for pkg in repository.packages:
73+
assert pkg.name != "attrs"

0 commit comments

Comments
 (0)