Browse Source

add Package.get_modulename() and refactor

master
Niklas Rosenstein 1 year ago
parent
commit
eda478dd9d
Signed by: NiklasRosenstein GPG Key ID: 06D269B33D25F6C6
3 changed files with 8 additions and 5 deletions
  1. + 6
    - 3
      src/shore/model.py
  2. + 1
    - 1
      src/shore/plugins/core.py
  3. + 1
    - 1
      src/shore/plugins/setuptools.py

+ 6
- 3
src/shore/model.py

@ -717,6 +717,9 @@ class Package(BaseObject):
def get_private(self) -> bool:
return self._get_inherited_field('private')
def get_modulename(self) -> str:
return self.modulename or self.name
def get_version(self) -> str:
version: str = self._get_inherited_field('version')
if version is None:
@ -772,7 +775,7 @@ class Package(BaseObject):
""" Returns the filename of the entry file that contains package metadata
such as `__version__` and `__author__`. """
name = (self.modulename or self.name).replace('-', '_')
name = self.get_modulename().replace('-', '_')
parts = name.split('.')
prefix = os.sep.join(parts[:-1])
for filename in [parts[-1] + '.py', os.path.join(parts[-1], '__init__.py')]:
@ -783,8 +786,8 @@ class Package(BaseObject):
.format(self.name))
def is_single_module(self) -> bool:
return ((
self.modulename or self.name).count('.') == 0 and
return (
self.get_modulename().count('.') == 0 and
os.path.basename(self.get_entry_file()) != '__init__.py')
def get_entry_file_abs(self) -> str:

+ 1
- 1
src/shore/plugins/core.py

@ -142,7 +142,7 @@ def get_monorepo_interdependency_version_refs(monorepo: Monorepo, new_version: V
regex = re.compile(r'^\s*- +([A-z0-9\.\-_]+) *([^\n:]+)?$', re.M)
packages = list(monorepo.get_packages())
package_names = set(p.modulename or p.name for p in packages)
package_names = set(p.get_modulename() for p in packages)
for package in packages:
with open(package.filename) as fp:

+ 1
- 1
src/shore/plugins/setuptools.py

@ -280,7 +280,7 @@ class SetuptoolsRenderer:
exclude_packages.append(pkg + '.*')
if package.is_single_module():
packages_args = ' py_modules = [{!r}],'.format(package.modulename or package.name)
packages_args = ' py_modules = [{!r}],'.format(package.get_modulename())
else:
packages_args = ' packages = setuptools.find_packages({src_directory!r}, {exclude_packages!r}),'.format(
src_directory=package.source_directory,

Loading…
Cancel
Save