Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
d3969808
Commit
d3969808
authored
Mar 22, 2014
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pulled find_package functionality into a PackageFinder class
parent
77b7c39d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
55 deletions
+64
-55
setuptools/__init__.py
setuptools/__init__.py
+64
-55
No files found.
setuptools/__init__.py
View file @
d3969808
...
...
@@ -29,7 +29,10 @@ run_2to3_on_doctests = True
# Standard package names for fixer packages
lib2to3_fixer_packages
=
[
'lib2to3.fixes'
]
def
find_packages
(
where
=
'.'
,
exclude
=
(),
include
=
(
'*'
,)):
class
PackageFinder
(
object
):
@
classmethod
def
find
(
cls
,
where
=
'.'
,
exclude
=
(),
include
=
(
'*'
,)):
"""Return a list all Python packages found within directory 'where'
'where' should be supplied as a "cross-platform" (i.e. URL-style) path; it
...
...
@@ -46,14 +49,15 @@ def find_packages(where='.', exclude=(), include=('*',)):
The list of included packages is built up first and then any explicitly
excluded packages are removed from it.
"""
out
=
_find_packages_iter
(
convert_path
(
where
))
includes
=
_build_filter
(
*
include
)
excludes
=
_build_filter
(
'ez_setup'
,
'*__pycache__'
,
*
exclude
)
out
=
cls
.
_find_packages_iter
(
convert_path
(
where
))
includes
=
cls
.
_build_filter
(
*
include
)
excludes
=
cls
.
_build_filter
(
'ez_setup'
,
'*__pycache__'
,
*
exclude
)
out
=
filter
(
includes
,
out
)
out
=
filterfalse
(
excludes
,
out
)
return
list
(
out
)
def
_all_dirs
(
base_path
):
@
staticmethod
def
_all_dirs
(
base_path
):
"""
Return all dirs in base_path, relative to base_path
"""
...
...
@@ -61,30 +65,35 @@ def _all_dirs(base_path):
for
dir
in
dirs
:
yield
os
.
path
.
relpath
(
os
.
path
.
join
(
root
,
dir
),
base_path
)
def
_find_packages_iter
(
base_path
):
dirs
=
_all_dirs
(
base_path
)
@
classmethod
def
_find_packages_iter
(
cls
,
base_path
):
dirs
=
cls
.
_all_dirs
(
base_path
)
suitable
=
filterfalse
(
lambda
n
:
'.'
in
n
,
dirs
)
packages
=
(
path
for
path
in
suitable
if
_looks_like_package
(
os
.
path
.
join
(
base_path
,
path
))
if
cls
.
_looks_like_package
(
os
.
path
.
join
(
base_path
,
path
))
)
for
pkg_path
in
packages
:
yield
pkg_path
.
replace
(
os
.
path
.
sep
,
'.'
)
def
_looks_like_package
(
path
):
@
staticmethod
def
_looks_like_package
(
path
):
return
(
os
.
path
.
isfile
(
os
.
path
.
join
(
path
,
'__init__.py'
))
or
sys
.
version_info
[:
2
]
>=
(
3
,
3
)
# PEP 420
)
def
_build_filter
(
*
patterns
):
@
staticmethod
def
_build_filter
(
*
patterns
):
"""
Given a list of patterns, return a callable that will be true only if
the input matches one of the patterns.
"""
return
lambda
name
:
any
(
fnmatchcase
(
name
,
pat
=
pat
)
for
pat
in
patterns
)
find_packages
=
PackageFinder
.
find
setup
=
distutils
.
core
.
setup
_Command
=
_get_unpatched
(
_Command
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment