Skip to content

Commit

Permalink
Modify PackageManifest class names and attributes
Browse files Browse the repository at this point in the history
Modifies PackageManifest class names to be camelcase and deletes
attribute `manifest_type` from individual classes.

Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
  • Loading branch information
AyanSinhaMahapatra committed Nov 30, 2021
1 parent b8968e2 commit d2b37a1
Show file tree
Hide file tree
Showing 37 changed files with 407 additions and 427 deletions.
54 changes: 27 additions & 27 deletions src/packagedcode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# Note: the order matters: from the most to the least specific
# Package classes MUST be added to this list to be active
PACKAGE_MANIFEST_TYPES = [
rpm.RPMManifest,
rpm.RpmManifest,
debian.DebianPackage,

models.JavaJar,
Expand All @@ -51,38 +51,38 @@
models.Axis2Mar,

about.Aboutfile,
npm.NPMPackageJSON,
npm.NPMPackageLockJSON,
npm.NPMYarnLockJSON,
phpcomposer.PHPComposerJSON,
phpcomposer.PHPComposerLock,
haxe.HaxelibJSON,
cargo.RustCargoToml,
cargo.RustCargoLock,
cocoapods.CocoapodsPodspec,
cocoapods.CocoapodsPodfileLock,
cocoapods.CocoapodsPodspecJSON,
npm.PackageJson,
npm.PackageLockJson,
npm.YarnLockJson,
phpcomposer.ComposerJson,
phpcomposer.ComposerLock,
haxe.HaxelibJson,
cargo.CargoToml,
cargo.CargoLock,
cocoapods.Podspec,
cocoapods.PodfileLock,
cocoapods.PodspecJson,
opam.OpamFile,
models.MeteorPackage,
bower.BowerJSON,
freebsd.FreeBSDCompactManifest,
bower.BowerJson,
freebsd.CompactManifest,
models.CpanModule,
rubygems.RubyGemArchive,
rubygems.RubyGemArchiveExtracted,
rubygems.RubyGemSpec,
rubygems.RubyGemfileLock,
rubygems.GemArchive,
rubygems.GemArchiveExtracted,
rubygems.GemSpec,
rubygems.GemfileLock,
models.AndroidApp,
models.AndroidLibrary,
models.MozillaExtension,
models.ChromeExtension,
models.IOSApp,
pypi.PythonMetadataFile,
pypi.PythonBinaryDist,
pypi.PythonSourceDist,
pypi.PythonSetupPy,
pypi.PythonDependencyFile,
pypi.PythonPipfileLock,
pypi.PythonRequirementsFile,
pypi.MetadataFile,
pypi.BinaryDistArchive,
pypi.SourceDistArchive,
pypi.SetupPy,
pypi.DependencyFile,
pypi.PipfileLock,
pypi.RequirementsFile,
golang.GoMod,
golang.GoSum,
models.CabPackage,
Expand All @@ -93,7 +93,7 @@
models.AppleDmgPackage,
models.IsoImagePackage,
models.SquashfsPackage,
chef.MetadataJSON,
chef.MetadataJson,
chef.Metadatarb,
build.BazelPackage,
build.BuckPackage,
Expand All @@ -104,7 +104,7 @@
build.MetadataBzl,
msi.MsiInstallerPackage,
windows.MicrosoftUpdateManifest,
pubspec.PubspecYAML,
pubspec.PubspecYaml,
pubspec.PubspecLock
]

Expand Down
3 changes: 1 addition & 2 deletions src/packagedcode/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ class Aboutfile(AboutPackage, models.PackageManifest):

file_patterns = ('*.ABOUT',)
extensions = ('.ABOUT',)
manifest_type = 'aboutfile'

@classmethod
def is_manifest(cls, location):
"""
Return True if the file at ``location`` is likely a manifest of this type.
"""
return (filetype.is_file(location) and location.lower().endswith(('.about',)))
return filetype.is_file(location) and location.lower().endswith(('.about',))

@classmethod
def recognize(cls, location):
Expand Down
3 changes: 1 addition & 2 deletions src/packagedcode/bower.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ def compute_normalized_license(self):


@attr.s()
class BowerJSON(BowerPackage, models.PackageManifest):
class BowerJson(BowerPackage, models.PackageManifest):

file_patterns = ('bower.json', '.bower.json')
extensions = ('.json',)
manifest_type = 'bowerjson'

@classmethod
def is_manifest(cls, location):
Expand Down
12 changes: 4 additions & 8 deletions src/packagedcode/cargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

@attr.s()
class RustCargoCrate(models.Package):
file_patterns = ('Cargo.toml', 'Cargo.lock')
default_type = 'cargo'
default_primary_language = 'Rust'
default_web_baseurl = 'https://crates.io'
Expand All @@ -60,19 +59,17 @@ def api_data_url(self, baseurl=default_api_baseurl):


@attr.s()
class RustCargoToml(RustCargoCrate, models.PackageManifest):
class CargoToml(RustCargoCrate, models.PackageManifest):

file_patterns = ('Cargo.toml',)
extensions = ('.json',)
manifest_type = 'cargotoml'
extensions = ('.toml',)

@classmethod
def is_manifest(cls, location):
"""
Return True if the file at ``location`` is likely a manifest of this type.
"""
return (filetype.is_file(location)
and fileutils.file_name(location).lower() == 'cargo.toml')
return filetype.is_file(location) and fileutils.file_name(location).lower() == 'cargo.toml'

@classmethod
def recognize(cls, location):
Expand Down Expand Up @@ -106,11 +103,10 @@ def recognize(cls, location):


@attr.s()
class RustCargoLock(RustCargoCrate, models.PackageManifest):
class CargoLock(RustCargoCrate, models.PackageManifest):

file_patterns = ('Cargo.lock',)
extensions = ('.lock',)
manifest_type = 'cargolock'

@classmethod
def is_manifest(cls, location):
Expand Down
4 changes: 1 addition & 3 deletions src/packagedcode/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,10 @@ def format(self, tokens, outfile):


@attr.s()
class MetadataJSON(ChefPackage, models.PackageManifest):
class MetadataJson(ChefPackage, models.PackageManifest):

file_patterns = ('metadata.json',)
extensions = ('.json',)
manifest_type = 'metadatajson'

@classmethod
def is_manifest(cls, location):
Expand Down Expand Up @@ -192,7 +191,6 @@ class Metadatarb(ChefPackage, models.PackageManifest):

file_patterns = ('metadata.rb',)
extensions = ('.rb',)
manifest_type = 'metadatarb'

@classmethod
def is_manifest(cls, location):
Expand Down
15 changes: 6 additions & 9 deletions src/packagedcode/cocoapods.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@


@attr.s()
class BaseCocoapodsPackage(models.Package):
class CocoapodsPackage(models.Package):
default_type = 'pods'
default_primary_language = 'Objective-C'
default_web_baseurl = 'https://cocoapods.org'
Expand Down Expand Up @@ -117,18 +117,17 @@ def get_podname_proper(podname):


@attr.s()
class CocoapodsPodspec(BaseCocoapodsPackage, models.PackageManifest):
class Podspec(CocoapodsPackage, models.PackageManifest):

file_patterns = ('*.podspec',)
extensions = ('.podspec',)
manifest_type = 'podspec'

@classmethod
def is_manifest(cls, location):
"""
Return True if the file at ``location`` is likely a manifest of this type.
"""
return (filetype.is_file(location) and location.endswith('.podspec'))
return filetype.is_file(location) and location.endswith('.podspec')

@classmethod
def recognize(cls, location):
Expand Down Expand Up @@ -177,11 +176,10 @@ def recognize(cls, location):


@attr.s()
class CocoapodsPodfileLock(BaseCocoapodsPackage, models.PackageManifest):
class PodfileLock(CocoapodsPackage, models.PackageManifest):

file_patterns = ('*podfile.lock',)
extensions = ('.lock',)
manifest_type = 'podfilelock'

@classmethod
def is_manifest(cls, location):
Expand Down Expand Up @@ -264,18 +262,17 @@ def read_podfile_lock(location):


@attr.s()
class CocoapodsPodspecJSON(BaseCocoapodsPackage, models.PackageManifest):
class PodspecJson(CocoapodsPackage, models.PackageManifest):

file_patterns = ('*.podspec.json',)
extensions = ('.json',)
manifest_type = 'podspecjson'

@classmethod
def is_manifest(cls, location):
"""
Return True if the file at ``location`` is likely a manifest of this type.
"""
return (filetype.is_file(location) and location.endswith('.podspec.json'))
return filetype.is_file(location) and location.endswith('.podspec.json')

@classmethod
def recognize(cls, location):
Expand Down
1 change: 0 additions & 1 deletion src/packagedcode/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class Condayml(CondaPackage, models.PackageManifest):

file_patterns = ('meta.yaml', 'META.yml',)
extensions = ('.yml', '.yaml',)
manifest_type = 'condayml'

@classmethod
def is_manifest(cls, location):
Expand Down
3 changes: 1 addition & 2 deletions src/packagedcode/freebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ def compute_normalized_license(self):


@attr.s()
class FreeBSDCompactManifest(FreeBSDPackage, models.PackageManifest):
class CompactManifest(FreeBSDPackage, models.PackageManifest):

file_patterns = ('+COMPACT_MANIFEST',)
manifest_type = 'compactmanifest'

@classmethod
def is_manifest(cls, location):
Expand Down
6 changes: 2 additions & 4 deletions src/packagedcode/golang.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ class GoMod(GolangPackage, models.PackageManifest):

file_patterns = ('go.mod',)
extensions = ('.mod',)
manifest_type = 'gomod'

@classmethod
def is_manifest(cls, location):
"""
Return True if the file at ``location`` is likely a manifest of this type.
"""
filename = fileutils.file_name(location).lower()
return (filetype.is_file(location) and filename == 'go.mod')
return filetype.is_file(location) and filename == 'go.mod'

@classmethod
def recognize(cls, location):
Expand Down Expand Up @@ -120,15 +119,14 @@ class GoSum(GolangPackage, models.PackageManifest):

file_patterns = ('go.sum',)
extensions = ('.sum',)
manifest_type = 'gosum'

@classmethod
def is_manifest(cls, location):
"""
Return True if the file at ``location`` is likely a manifest of this type.
"""
filename = fileutils.file_name(location).lower()
return (filetype.is_file(location) and filename == 'go.sum')
return filetype.is_file(location) and filename == 'go.sum'

@classmethod
def recognize(cls, location):
Expand Down
6 changes: 2 additions & 4 deletions src/packagedcode/haxe.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,17 @@ def repository_download_url(self, baseurl=default_download_baseurl):


@attr.s()
class HaxelibJSON(HaxePackage, models.PackageManifest):
class HaxelibJson(HaxePackage, models.PackageManifest):

file_patterns = ('haxelib.json',)
extensions = ('.json',)
manifest_type = 'haxlibjson'

@classmethod
def is_manifest(cls, location):
"""
Return True if the file at ``location`` is likely a manifest of this type.
"""
return (filetype.is_file(location)
and fileutils.file_name(location).lower() == 'haxelib.json')
return filetype.is_file(location) and fileutils.file_name(location).lower() == 'haxelib.json'

@classmethod
def recognize(cls, location):
Expand Down
9 changes: 5 additions & 4 deletions src/packagedcode/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,16 +696,17 @@ class PackageManifest:
# list of known file_patterns for a package manifest type
file_patterns = tuple()

# Package manifest type within a package ecosystem
manifest_type = None

@property
def package_manifest_type(self):
"""
A tuple unique across package manifests, created from the default package type
and the manifest type.
"""
return self.default_type, self.manifest_type
return self.default_type, self.manifest_type()

@classmethod
def manifest_type(cls):
return cls.__module__+"."+cls.__qualname__

@classmethod
def is_manifest(cls, location):
Expand Down
12 changes: 4 additions & 8 deletions src/packagedcode/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,17 @@ def compute_normalized_license(self):


@attr.s()
class NPMPackageJSON(NpmPackage, models.PackageManifest):
class PackageJson(NpmPackage, models.PackageManifest):

file_patterns = ('package.json',)
extensions = ('.tgz',)
manifest_type = 'packagejson'

@classmethod
def is_manifest(cls, location):
"""
Return True if the file at ``location`` is likely a manifest of this type.
"""
return (filetype.is_file(location)
and fileutils.file_name(location).lower() == 'package.json')
return filetype.is_file(location) and fileutils.file_name(location).lower() == 'package.json'

@classmethod
def recognize(cls, location):
Expand Down Expand Up @@ -179,14 +177,13 @@ def recognize(cls, location):


@attr.s()
class NPMPackageLockJSON(NpmPackage, models.PackageManifest):
class PackageLockJson(NpmPackage, models.PackageManifest):

file_patterns = (
'npm-shrinkwrap.json',
'package-lock.json',
)
extensions = ('.tgz',)
manifest_type = 'packagelockjson'

@staticmethod
def is_package_lock(location):
Expand Down Expand Up @@ -321,11 +318,10 @@ def recognize(cls, location):


@attr.s()
class NPMYarnLockJSON(NpmPackage, models.PackageManifest):
class YarnLockJson(NpmPackage, models.PackageManifest):

file_patterns = ('yarn.lock',)
extensions = ('.tgz',)
manifest_type = 'yarnlock'

@classmethod
def is_manifest(cls, location):
Expand Down
Loading

0 comments on commit d2b37a1

Please sign in to comment.