Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c734f2f0
Commit
c734f2f0
authored
May 16, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Autolink package names in requirements.txt
parent
640440c9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
113 additions
and
0 deletions
+113
-0
lib/gitlab/dependency_linker.rb
lib/gitlab/dependency_linker.rb
+1
-0
lib/gitlab/dependency_linker/requirements_txt_linker.rb
lib/gitlab/dependency_linker/requirements_txt_linker.rb
+17
-0
spec/lib/gitlab/dependency_linker/requirements_txt_linker_spec.rb
.../gitlab/dependency_linker/requirements_txt_linker_spec.rb
+87
-0
spec/lib/gitlab/dependency_linker_spec.rb
spec/lib/gitlab/dependency_linker_spec.rb
+8
-0
No files found.
lib/gitlab/dependency_linker.rb
View file @
c734f2f0
...
@@ -10,6 +10,7 @@ module Gitlab
...
@@ -10,6 +10,7 @@ module Gitlab
PodspecJsonLinker
,
PodspecJsonLinker
,
CartfileLinker
,
CartfileLinker
,
GodepsJsonLinker
,
GodepsJsonLinker
,
RequirementsTxtLinker
].
freeze
].
freeze
def
self
.
linker
(
blob_name
)
def
self
.
linker
(
blob_name
)
...
...
lib/gitlab/dependency_linker/requirements_txt_linker.rb
0 → 100644
View file @
c734f2f0
module
Gitlab
module
DependencyLinker
class
RequirementsTxtLinker
<
BaseLinker
self
.
file_type
=
:requirements_txt
private
def
link_dependencies
link_regex
(
/^(?<name>(?![a-z+]+:)[^#.-][^ ><=;\[]+)/
)
do
|
name
|
"https://pypi.python.org/pypi/
#{
name
}
"
end
link_regex
(
%r{^(?<name>https?://[^ ]+)}
,
&
:itself
)
end
end
end
end
spec/lib/gitlab/dependency_linker/requirements_txt_linker_spec.rb
0 → 100644
View file @
c734f2f0
require
'rails_helper'
describe
Gitlab
::
DependencyLinker
::
RequirementsTxtLinker
,
lib:
true
do
describe
'.support?'
do
it
'supports requirements.txt'
do
expect
(
described_class
.
support?
(
'requirements.txt'
)).
to
be_truthy
end
it
'supports doc-requirements.txt'
do
expect
(
described_class
.
support?
(
'doc-requirements.txt'
)).
to
be_truthy
end
it
'does not support other files'
do
expect
(
described_class
.
support?
(
'requirements'
)).
to
be_falsey
end
end
describe
'#link'
do
let
(
:file_name
)
{
"requirements.txt"
}
let
(
:file_content
)
do
<<-
CONTENT
.
strip_heredoc
#
####### example-requirements.txt #######
#
###### Requirements without Version Specifiers ######
nose
nose-cov
beautifulsoup4
#
###### Requirements with Version Specifiers ######
# See https://www.python.org/dev/peps/pep-0440/#version-specifiers
docopt == 0.6.1 # Version Matching. Must be version 0.6.1
keyring >= 4.1.1 # Minimum version 4.1.1
coverage != 3.5 # Version Exclusion. Anything except version 3.5
Mopidy-Dirble ~= 1.1 # Compatible release. Same as >= 1.1, == 1.*
#
###### Refer to other requirements files ######
-r other-requirements.txt
#
#
###### A particular file ######
./downloads/numpy-1.9.2-cp34-none-win32.whl
http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev1820+49a8884-cp34-none-win_amd64.whl
#
###### Additional Requirements without Version Specifiers ######
# Same as 1st section, just here to show that you can put things in any order.
rejected
green
#
Jinja2>=2.3
Pygments>=1.2
Sphinx>=1.3
docutils>=0.7
markupsafe
CONTENT
end
subject
{
Gitlab
::
Highlight
.
highlight
(
file_name
,
file_content
)
}
def
link
(
name
,
url
)
%{<a href="#{url}" rel="nofollow noreferrer noopener" target="_blank">#{name}</a>}
end
it
'links dependencies'
do
expect
(
subject
).
to
include
(
link
(
'nose'
,
'https://pypi.python.org/pypi/nose'
))
expect
(
subject
).
to
include
(
link
(
'nose-cov'
,
'https://pypi.python.org/pypi/nose-cov'
))
expect
(
subject
).
to
include
(
link
(
'beautifulsoup4'
,
'https://pypi.python.org/pypi/beautifulsoup4'
))
expect
(
subject
).
to
include
(
link
(
'docopt'
,
'https://pypi.python.org/pypi/docopt'
))
expect
(
subject
).
to
include
(
link
(
'keyring'
,
'https://pypi.python.org/pypi/keyring'
))
expect
(
subject
).
to
include
(
link
(
'coverage'
,
'https://pypi.python.org/pypi/coverage'
))
expect
(
subject
).
to
include
(
link
(
'Mopidy-Dirble'
,
'https://pypi.python.org/pypi/Mopidy-Dirble'
))
expect
(
subject
).
to
include
(
link
(
'rejected'
,
'https://pypi.python.org/pypi/rejected'
))
expect
(
subject
).
to
include
(
link
(
'green'
,
'https://pypi.python.org/pypi/green'
))
expect
(
subject
).
to
include
(
link
(
'Jinja2'
,
'https://pypi.python.org/pypi/Jinja2'
))
expect
(
subject
).
to
include
(
link
(
'Pygments'
,
'https://pypi.python.org/pypi/Pygments'
))
expect
(
subject
).
to
include
(
link
(
'Sphinx'
,
'https://pypi.python.org/pypi/Sphinx'
))
expect
(
subject
).
to
include
(
link
(
'docutils'
,
'https://pypi.python.org/pypi/docutils'
))
expect
(
subject
).
to
include
(
link
(
'markupsafe'
,
'https://pypi.python.org/pypi/markupsafe'
))
end
it
'links URLs'
do
expect
(
subject
).
to
include
(
link
(
'http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev1820+49a8884-cp34-none-win_amd64.whl'
,
'http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev1820+49a8884-cp34-none-win_amd64.whl'
))
end
end
end
spec/lib/gitlab/dependency_linker_spec.rb
View file @
c734f2f0
...
@@ -73,5 +73,13 @@ describe Gitlab::DependencyLinker, lib: true do
...
@@ -73,5 +73,13 @@ describe Gitlab::DependencyLinker, lib: true do
described_class
.
link
(
blob_name
,
nil
,
nil
)
described_class
.
link
(
blob_name
,
nil
,
nil
)
end
end
it
'links using RequirementsTxtLinker'
do
blob_name
=
'requirements.txt'
expect
(
described_class
::
RequirementsTxtLinker
).
to
receive
(
:link
)
described_class
.
link
(
blob_name
,
nil
,
nil
)
end
end
end
end
end
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