Skip to content

Feature/refactor package name class#6

Draft
DavidWLoupe wants to merge 7 commits into
mainfrom
feature/refactor-package-name-class
Draft

Feature/refactor package name class#6
DavidWLoupe wants to merge 7 commits into
mainfrom
feature/refactor-package-name-class

Conversation

@DavidWLoupe

Copy link
Copy Markdown
Contributor

What

Adds a class for collecting a package name and providing an interface for getting it in different formats. The three class properties that are supported are:

  • fullName (e.g. @loupeteam/atn)
  • baseName (e.g. atn)
  • version (e.g. 3.1.0)

Why

Previously there were a variety of methods strewn about for adding or splitting up names and versions. This seeks to unify the issue by channeling it through an object interface

@kirillmorozov kirillmorozov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @DavidWLoupe,

I've emailed @AndrewMusser regarding contribution to LPM and one of the things he told me I can help with is the review of this PR.

Beside all my comments I'll also suggest having all new code conform to PEP 8 and have type hints.

Comment thread src/Package.py
Comment on lines +21 to +24
if self._versionText != '':
return self._versionText
else:
return '' No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't it the same?

Suggested change
if self._versionText != '':
return self._versionText
else:
return ''
return self._versionText

What was your intention behind this check?

Comment thread src/Package.py
import re

class PackageNameVersion:
def __init__(self, input: str):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since you've already started typing your code:

Suggested change
def __init__(self, input: str):
def __init__(self, input: str) -> None:

Comment thread src/Package.py
self._versionText = match.group(4) if match.group(4) is not None else ''

@property
def baseName(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
def baseName(self):
def baseName(self) -> str:

Comment thread src/Package.py
return f"{self._baseName}"

@property
def fullName(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
def fullName(self):
def fullName(self) -> str:

Comment thread src/Package.py
return f"@loupeteam/{self._baseName}"

@property
def version(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
def version(self):
def version(self) -> str:

@@ -0,0 +1,69 @@
import pytest
import sys
sys.path.append('./src/')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Manipulation of path smells bad.

What you can do instead is restructure your code to the following:

.
├── docs
├── lpm
│   ├── __init__.py
│   ├── lpm.py
│   └── package.py
├── tests
│   └── test_package.py
├── README.md
└── requirments.txt

This way you could write in your test file

from lpm import package

And run tests from the root of the repo.

Extracting tests from src will also make distribution easier because you'll only need to copy src dir and your that will leave alongside won't be distributed.

from Package import PackageNameVersion

class Test_PackageNameVersion:
def test_validInputsNoVersion(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like that you use table driven tests but I have a question: why haven't you used pytest parametrisation feature?

Comment thread src/LPM.py
print(colored(f'Could not interpret \"{item}\" as a valid package', 'red'))

# Return if no valid packages
if len(packageNameObjectList) == 0:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if len(packageNameObjectList) == 0:
if not packageNameObjectList:

is more pythonic.

Comment thread src/LPM.py
Comment on lines +80 to +82
packagesFullNames = [p.fullName for p in packageNameObjectList]
packagesBaseNames = [p.baseName for p in packageNameObjectList]
packagesVersions = [p.version for p in packageNameObjectList]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't get why have you implemented PackageNameVersion class to have all info regarding a package in one place but then decided to split a list of package into three different lists?

Comment thread src/LPM.py
else:
packageName = package
installSource(packageName, '', loupePkg)
for (packageFullName, packageBaseName, version) in zip(packagesFullNames, packagesBaseNames, packagesVersions):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here you zip them together to iterate over three lists but if you would have kept it in a single list it would be as easy as:

for package in packages:
    installSource(package.fullName, package.version, loupePkg)

or with further refactoring to installSource function even simpler

for package in packages:
    installSource(package)

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.

2 participants