Skip to content
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

typechecking poetry.core.masonry #274

Merged
merged 5 commits into from
May 15, 2022

Conversation

dimbleby
Copy link
Contributor

@dimbleby dimbleby commented Jan 29, 2022

Resolves: python-poetry#

  • Added tests for changed code.
  • Updated documentation for changed code.

I've added mypy to the dev-dependencies and made the poetry.core.masonry code mypy-clean.

Slightly more invasive than some of the typechecking MRs we've seen:

  • making the various .build() methods have the same signature required changes (and I've removed an unused parameter too)
  • since mostly this code wants Path rather than str I've removed some odd-one-out Union[Path, str]
  • I've removed some cleverness where a BuildIncludeFile could be equal to a Path because it just seemed too much. I've caught one place where this trickery was being exploited, and re-implemented it in a less magical way, but it's possible that I've missed something.

@dimbleby dimbleby force-pushed the typechecking-masonry branch from 93f7187 to 955d823 Compare January 29, 2022 19:00
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.3% 0.3% Duplication

@@ -206,10 +203,6 @@ def find_files_to_add(self, exclude_build: bool = True) -> Set["BuildIncludeFile
if file.suffix == ".pyc":
continue

if file in to_add:
# Skip duplicates
Copy link
Contributor Author

Choose a reason for hiding this comment

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

to_add is a set, it couldn't contain duplicates if it tried. Just need to be happy with __hash__ and __eq__ on the BuildIncludeFile.

@dimbleby dimbleby force-pushed the typechecking-masonry branch from 955d823 to d3f48dd Compare January 29, 2022 19:28
pyproject.toml Outdated Show resolved Hide resolved
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 9, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.5% 0.5% Duplication

@dimbleby dimbleby mentioned this pull request Feb 9, 2022
pyproject.toml Outdated Show resolved Hide resolved
Copy link
Contributor

@danieleades danieleades left a comment

Choose a reason for hiding this comment

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

suggest moving the adding of mypy to a separate PR

@dimbleby dimbleby force-pushed the typechecking-masonry branch 4 times, most recently from 672e316 to a2e26b3 Compare April 3, 2022 10:12
@dimbleby
Copy link
Contributor Author

dimbleby commented Apr 3, 2022

Ugh, merge conflicts. So de-motivating. I don't think this is waiting on anything, can we get it merged please? @finswimmer?

(I have removed mypy from pyproject.toml in case that was controversial, though if that was a problem it's frustrating that no-one with the commit bit would say so)

@dimbleby dimbleby force-pushed the typechecking-masonry branch from 810b42b to 70b2a62 Compare April 30, 2022 10:43
target_dir: Path | None = None,
) -> None:
super().__init__(poetry, executable=executable)
self._target_dir = target_dir
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this is desired. Iirc build is intended to be called multiple times with different target directories. You can default to cwd if desired though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The builders were inconsistent about whether they took a target directory on their constructor or on their build() method. I have made them consistently put it on the constructor.

I think the suggestion is that we should jump the other way? ie remove the parameter from the constructors, put it on the build() method?

(There's a default value either way)

Copy link
Member

Choose a reason for hiding this comment

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

I suspect the inconsistency comes from the use of make_in in the wheel builder. Happy for it to be unified as consistency here is better, with the following funcitonality maintained.

  1. There is a default target directory (which as you said is present either way).
  2. the build() method can accept target directory.

This can also mean that make_in / make becomes redundant. Will need to check downstream see if they are being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed a commit that does what I think we're agreeing - say if I've misunderstood

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make() and make_in() do indeed look redundant, happy to remove them if you want

@dimbleby
Copy link
Contributor Author

dimbleby commented May 2, 2022

@abn are we good to go?

There was a question about potentially removing WheelBuilder.make() and WheelBuilder.make_in(), if you want that please say so - though even if so, perhaps it would better be done in a separate MR.

return self.path == other.path

return self.path == other
def __eq__(self, other: object) -> bool:
Copy link
Member

Choose a reason for hiding this comment

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

Why are we disallowing comparison with Path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not disallowing, but always returning False.

Because a BuildIncludeFile is not a Path!

src/poetry/core/masonry/builders/sdist.py Outdated Show resolved Hide resolved
src/poetry/core/masonry/builders/wheel.py Outdated Show resolved Hide resolved
@dimbleby dimbleby force-pushed the typechecking-masonry branch from b1acaf6 to cb3ed03 Compare May 12, 2022 18:44
@dimbleby dimbleby force-pushed the typechecking-masonry branch from cb3ed03 to 52597de Compare May 14, 2022 17:16
@dimbleby
Copy link
Contributor Author

@abn are we waiting on anything to get this merged?

@dimbleby dimbleby force-pushed the typechecking-masonry branch from 52597de to f6258d7 Compare May 15, 2022 09:34
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.3% 0.3% Duplication

Copy link
Member

@abn abn left a comment

Choose a reason for hiding this comment

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

Minor question otherwise good.

src/poetry/core/masonry/builders/builder.py Show resolved Hide resolved
@abn abn merged commit 7641b53 into python-poetry:master May 15, 2022
@dimbleby dimbleby deleted the typechecking-masonry branch May 15, 2022 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants