Browse Source

treat PEP-561 stub packages more gently

shut-new-model
Niklas Rosenstein 9 months ago
parent
commit
208636246f
No known key found for this signature in database GPG Key ID: 6D269B33D25F6C6
2 changed files with 12 additions and 4 deletions
  1. + 3
    - 3
      src/shut/commands/pkg/new.py
  2. + 9
    - 1
      src/shut/model/package.py

+ 3
- 3
src/shut/commands/pkg/new.py

@ -112,8 +112,6 @@ def new(
if not target_directory:
target_directory = project_name
if not module_name:
module_name = project_name.replace('-', '_')
if not author:
author = load_author_from_git() or Author('Unknown', '<unknown@example.org>')
if not version:
@ -122,7 +120,7 @@ def new(
package_manifest = PackageModel(
data=PackageData(
name=project_name,
modulename=None if module_name == project_name.replace('-', '_') else module_name,
modulename=module_name,
version=version,
author=author,
license=license,
@ -133,6 +131,8 @@ def new(
),
)
module_name = package_manifest.data.get_modulename()
template_vars = {
'project_name': project_name,
'version': version,

+ 9
- 1
src/shut/model/package.py

@ -80,7 +80,15 @@ class PackageData:
# TODO: Data files
def get_modulename(self) -> str:
return self.modulename or self.name.replace('-', '_')
if self.modulename:
return self.modulename
# Check for PEP-561 stub packages.
# See also https://mypy.readthedocs.io/en/latest/installed_packages.html#making-pep-561-compatible-packages
if self.name.endswith('-stubs'):
return self.name[:-6].replace('-', '_') + '-stubs'
return self.name.replace('-', '_')
def get_python_requirement(self) -> Optional[Requirement]:
return next(filter(lambda x: x.package == 'python', self.requirements), None)

Loading…
Cancel
Save