Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit 96aa401

Browse files
committed
Solve merge conflict
2 parents cce0992 + 93e1db2 commit 96aa401

File tree

9 files changed

+148
-23
lines changed

9 files changed

+148
-23
lines changed

CONTRIBUTING.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Jupyter-PHP Contributing Guidelines
2+
====================================
3+
4+
Contributing with Code
5+
----------------------
6+
7+
In first place, if you want to contribute code to Jupyter-PHP, you must have installed PHP, preferably recent
8+
versions (PHP>=5.5, but recommended PHP>=7.0).
9+
10+
If you don't know where to start, you can try searching inside the
11+
[issues list](https://github.com/Litipk/Jupyter-PHP/issues). Specially the ones marked with the
12+
[help wanted](https://github.com/Litipk/Jupyter-PHP/labels/help%20wanted) tag.
13+
14+
Some extra advices related on good practices:
15+
* We try to follow the PSR standards, in special **PSR-1**, **PSR-2** and **PSR-4**.
16+
* Every new added feature should come with unit tests, stability and code correctness is an important priority of this project.
17+
18+
19+
Contributing with Documentation
20+
-------------------------------
21+
22+
If you want to contribute documentation, you're welcome! :) , BUT, actually the documentation is pretty bad, and it's perfectly
23+
undersandable that this task isn't very attractive.
24+
25+
Contributing with Bug Reports
26+
-----------------------------
27+
28+
A very important part of every software project is the bugs tracking and solving process. You can send us bug reports through
29+
the [tracker](https://github.com/Litipk/Jupyter-PHP/issues).
30+
31+
It's desirable that every bug report explains the bug in a way that the developers can easily reproduce it. The following points
32+
are very helpful in order to achieve reproducibility:
33+
* Example code.
34+
* Jupyter version
35+
* Jupyter-PHP version.
36+
* Python version
37+
* PHP version
38+
39+
Contributing with New Ideas
40+
---------------------------
41+
42+
You can use the github [tracker](https://github.com/Litipk/Jupyter-PHP/issues) to send us new ideas, even if those ideas aren't
43+
bug reports. In such case, adding something like "SUGGESTION: ...", "IMPROVEMENT: ..." to the report bug it's a good idea.
44+
45+
You can also discuss your ideas with us in our [Gitter chat room](https://gitter.im/Litipk/Jupyter-PHP).

LICENSE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015-2016 Litipk
3+
Copyright (c) 2015-2017 Litipk
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
22-

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"license": "MIT",
66
"require": {
77
"php": ">=7.0.0",
8-
"composer/composer": "^1.3.1",
98
"ext-zmq": "*",
9+
"composer/composer": "^1.3.1",
1010
"monolog/monolog": "^1.22",
11-
"psy/psysh": "0.8.*",
11+
"psy/psysh": "^0.8",
1212
"ramsey/uuid": "^3.5",
1313
"react/zmq": "^0.3.0",
1414
"symfony/polyfill-php70": "^1.3"

src/JupyterBroker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function send(
7777
);
7878

7979
if (null !== $this->logger) {
80-
$this->logger->debug('Sent message', ['processId' => posix_getpid(), 'message' => $finalMsg]);
80+
$this->logger->debug('Sent message', ['processId' => getmypid(), 'message' => $finalMsg]);
8181
}
8282

8383
$stream->send($finalMsg);

src/System/BsdSystem.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,4 @@ public function getOperativeSystem()
1111
{
1212
return self::OS_BSD;
1313
}
14-
15-
/** @return string */
16-
public function getAppDataDirectory()
17-
{
18-
return $this->getCurrentUserHome().'/.jupyter-php';
19-
}
2014
}

src/System/LinuxSystem.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,4 @@ public function getOperativeSystem()
1111
{
1212
return self::OS_LINUX;
1313
}
14-
15-
/** @return string */
16-
public function getAppDataDirectory()
17-
{
18-
return $this->getCurrentUserHome().'/.jupyter-php';
19-
}
2014
}

src/System/System.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ public abstract function getCurrentUser();
4040
/** @return string */
4141
public abstract function getCurrentUserHome();
4242

43-
/** @return string */
43+
/**
44+
* @param string $cmdName
45+
* @return boolean
46+
*/
47+
public abstract function checkIfCommandExists($cmdName);
48+
49+
/** @return string */
4450
public abstract function getAppDataDirectory();
4551

4652
/**

src/System/UnixSystem.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ public function getCurrentUserHome()
3232
}
3333
}
3434

35+
/**
36+
* @param string $cmdName
37+
* @return boolean
38+
*/
39+
public function checkIfCommandExists($cmdName)
40+
{
41+
if (!function_exists('exec')) {
42+
return false;
43+
}
44+
45+
$sysResponse = exec(
46+
'PATH='.getenv('PATH').'; '.
47+
"if command -v ".$cmdName." >/dev/null 2>&1; then echo \"true\"; else echo \"false\"; fi;"
48+
);
49+
50+
return filter_var($sysResponse, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
51+
}
52+
53+
/** @return string */
54+
public function getAppDataDirectory()
55+
{
56+
return $this->getCurrentUserHome().'/.jupyter-php';
57+
}
58+
3559
/**
3660
* Returns true if the path is a "valid" path and is writable (even if the complete path does not yet exist).
3761
* @param string $path
@@ -41,7 +65,7 @@ public function validatePath($path)
4165
{
4266
$absPath = $this->getAbsolutePath($path);
4367
$absPathParts = preg_split('/\//', preg_replace('/(^\/|\/$)/', '', $absPath));
44-
$nSteps = count($absPath);
68+
$nSteps = count($absPathParts);
4569

4670
$tmpPath = '';
4771
$prevReadable = false;

src/System/WindowsSystem.php

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,66 @@ public function getCurrentUserHome()
3333
}
3434
}
3535

36+
/**
37+
* @param string $cmdName
38+
* @return boolean
39+
*/
40+
public function checkIfCommandExists($cmdName)
41+
{
42+
if (!function_exists('exec')) {
43+
return false;
44+
}
45+
46+
$sysResponse = exec("where $cmdName > nul 2>&1 && echo true");
47+
48+
return filter_var($sysResponse, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
49+
}
50+
51+
/** @return string */
52+
public function getAppDataDirectory()
53+
{
54+
return $this->getCurrentUserHome() . '/.jupyter-php';
55+
}
56+
3657
/**
3758
* Returns true if the path is a "valid" path and is writable (event if the complete path does not yet exist).
3859
* @param string $path
3960
* @return boolean
4061
*/
4162
public function validatePath($path)
4263
{
43-
// TODO: Implement validatePath() method.
64+
$absPath = $this->getAbsolutePath($path);
65+
$absPathParts = explode(DIRECTORY_SEPARATOR, $absPath);
66+
$nSteps = count($absPathParts);
67+
68+
$tmpPath = $absPathParts[0];
69+
$prevReadable = false;
70+
$prevWritable = false;
71+
72+
for ($i = 1; $i < $nSteps; $i++) {
73+
$tmpPath .= DIRECTORY_SEPARATOR . $absPathParts[$i];
74+
75+
if (file_exists($tmpPath)) {
76+
if (!is_dir($tmpPath)) {
77+
if (is_link($tmpPath)) {
78+
$linkPath = readlink($tmpPath);
79+
if (false === $linkPath || !is_dir($linkPath)) {
80+
return false;
81+
}
82+
$tmpPath = $linkPath;
83+
} else {
84+
return false;
85+
}
86+
}
87+
88+
$prevReadable = is_readable($tmpPath);
89+
$prevWritable = is_writable($tmpPath);
90+
} else {
91+
return ($prevReadable && $prevWritable);
92+
}
93+
}
94+
95+
return true;
4496
}
4597

4698
/**
@@ -49,7 +101,13 @@ public function validatePath($path)
49101
*/
50102
public function ensurePath($path)
51103
{
52-
// TODO: Implement ensurePath() method.
104+
$absPath = $this->getAbsolutePath($path);
105+
106+
if (!file_exists($absPath) && false === mkdir($absPath, 0755, true)) {
107+
throw new \RuntimeException('Unable to create the specified directory (' . $absPath . ').');
108+
}
109+
110+
return $absPath;
53111
}
54112

55113
/**
@@ -58,7 +116,7 @@ public function ensurePath($path)
58116
*/
59117
protected function isAbsolutePath($path)
60118
{
61-
// TODO: Implement isAbsolutePath() method.
119+
return preg_match('/^[a-z]\:/i', $path) === 1;
62120
}
63121

64122
/**
@@ -67,6 +125,11 @@ protected function isAbsolutePath($path)
67125
*/
68126
protected function getAbsolutePath($path)
69127
{
70-
// TODO: Implement getAbsolutePath() method.
128+
$path = $this->isAbsolutePath($path) ? $path : (getcwd() . DIRECTORY_SEPARATOR . $path);
129+
130+
// Normalise directory separators
131+
$path = preg_replace('/[\/\\\\]/u', DIRECTORY_SEPARATOR, $path);
132+
133+
return $path;
71134
}
72135
}

0 commit comments

Comments
 (0)